65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import React from 'react'
|
|
import { View } from 'react-native'
|
|
import MaterialIcons from '@expo/vector-icons/MaterialIcons'
|
|
import { usePathname, useRouter } from 'expo-router'
|
|
import { tw, MyText, MyTouchableOpacity, StorageServiceCasual } from 'common-ui'
|
|
import constants from '@/src/constants'
|
|
|
|
interface LoginWallProps {
|
|
/** Headline shown above the message. */
|
|
title?: string
|
|
/** Supporting copy. */
|
|
message?: string
|
|
/** When provided, a "Go Back" action is rendered under the Log In button. */
|
|
onBack?: () => void
|
|
}
|
|
|
|
/**
|
|
* Inline login gate. Renders a "please log in" prompt instead of redirecting, so
|
|
* the screen the user came from stays in the navigation stack and Back works
|
|
* normally (a push-based redirect would bounce them back into the wall).
|
|
*/
|
|
const LoginWall: React.FC<LoginWallProps> = ({
|
|
title = 'Please log in',
|
|
message = 'Log in to continue.',
|
|
onBack,
|
|
}) => {
|
|
const router = useRouter()
|
|
const pathname = usePathname()
|
|
|
|
const handleLogIn = async () => {
|
|
try {
|
|
// Remember where the user was, so login returns them to this page.
|
|
await StorageServiceCasual.setItem(
|
|
constants.AUTH_REDIRECT_KEY,
|
|
JSON.stringify({ targetUrl: pathname, queryParams: {}, timestamp: Date.now() })
|
|
)
|
|
} catch {
|
|
// ignore storage failure — still navigate to login
|
|
}
|
|
router.push('/(auth)/login')
|
|
}
|
|
|
|
return (
|
|
<View style={tw`flex-1 bg-gray-50 justify-center items-center px-6`}>
|
|
<View style={tw`w-20 h-20 bg-blue-50 rounded-full items-center justify-center mb-4`}>
|
|
<MaterialIcons name="lock-outline" size={36} color="#2563EB" />
|
|
</View>
|
|
<MyText style={tw`text-lg font-bold text-gray-900`}>{title}</MyText>
|
|
<MyText style={tw`text-gray-500 text-center mt-2 mb-6`}>{message}</MyText>
|
|
<MyTouchableOpacity
|
|
style={tw`bg-brand500 px-6 py-3 rounded-xl`}
|
|
onPress={handleLogIn}
|
|
>
|
|
<MyText style={tw`text-white font-bold`}>Log In</MyText>
|
|
</MyTouchableOpacity>
|
|
{onBack && (
|
|
<MyTouchableOpacity style={tw`mt-4`} onPress={onBack}>
|
|
<MyText style={tw`text-gray-500 font-medium`}>Go Back</MyText>
|
|
</MyTouchableOpacity>
|
|
)}
|
|
</View>
|
|
)
|
|
}
|
|
|
|
export default LoginWall
|