|
| 1 | +import { Button } from '@/components/reusables/ui/button'; |
| 2 | +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/reusables/ui/card'; |
| 3 | +import { Input } from '@/components/reusables/ui/input'; |
| 4 | +import { Label } from '@/components/reusables/ui/label'; |
| 5 | +import GoldGradient from '@/components/ui/gold-gradient'; |
| 6 | +import { useForgotPassword } from '@/features/auth/hook'; |
| 7 | +import { forgotPasswordSchema, type ForgotPasswordSchema } from '@/features/auth/schema'; |
| 8 | +import useForm from '@/hooks/use-app-form'; |
| 9 | +import { useLocalSearchParams } from 'expo-router'; |
| 10 | +import React from 'react'; |
| 11 | +import { |
| 12 | + ActivityIndicator, |
| 13 | + KeyboardAvoidingView, |
| 14 | + Platform, |
| 15 | + ScrollView, |
| 16 | + Text, |
| 17 | + useColorScheme, |
| 18 | + View, |
| 19 | +} from 'react-native'; |
| 20 | + |
| 21 | +const ForgotPassword = () => { |
| 22 | + const colorScheme = useColorScheme(); |
| 23 | + const { email } = useLocalSearchParams<{ email?: string }>(); |
| 24 | + const { mutate: forgotPassword, isPending } = useForgotPassword(); |
| 25 | + const { form, errors, handleChange, handleSubmit } = useForm<ForgotPasswordSchema>({ |
| 26 | + data: { |
| 27 | + email: email ?? '', |
| 28 | + }, |
| 29 | + schema: forgotPasswordSchema, |
| 30 | + onSubmit: (data) => forgotPassword(data), |
| 31 | + }); |
| 32 | + |
| 33 | + return ( |
| 34 | + <KeyboardAvoidingView |
| 35 | + className="flex-1" |
| 36 | + behavior={Platform.OS === 'ios' ? 'padding' : 'height'} |
| 37 | + keyboardVerticalOffset={Platform.OS === 'ios' ? 80 : 0} |
| 38 | + > |
| 39 | + <ScrollView |
| 40 | + keyboardShouldPersistTaps="handled" |
| 41 | + contentContainerClassName="sm:flex-1 items-center justify-center p-4 py-8 sm:py-4 sm:p-6 mt-safe" |
| 42 | + keyboardDismissMode="interactive" |
| 43 | + > |
| 44 | + <View className="w-full max-w-sm"> |
| 45 | + <View className="gap-6"> |
| 46 | + <Card className="bg-transparent border-0"> |
| 47 | + <CardHeader> |
| 48 | + <CardTitle className="text-center text-gold-text text-xl sm:text-left">Forgot Password</CardTitle> |
| 49 | + <CardDescription className="text-center sm:text-left"> |
| 50 | + Yeah! It happens. We've got your back. Simply supply your registered email below and you'll |
| 51 | + be set to go. |
| 52 | + </CardDescription> |
| 53 | + </CardHeader> |
| 54 | + <CardContent className="gap-6"> |
| 55 | + <View className="gap-6"> |
| 56 | + <View className="gap-1.5"> |
| 57 | + <Label htmlFor="email">Email</Label> |
| 58 | + <Input |
| 59 | + id="email" |
| 60 | + placeholder="m@example.com" |
| 61 | + keyboardType="email-address" |
| 62 | + autoComplete="email" |
| 63 | + autoCapitalize="none" |
| 64 | + editable={!isPending} |
| 65 | + value={form.email} |
| 66 | + onChangeText={(text) => handleChange('email', text)} |
| 67 | + returnKeyType="next" |
| 68 | + submitBehavior="submit" |
| 69 | + /> |
| 70 | + {errors?.email && <Text className="text-sm text-destructive">{errors?.email}</Text>} |
| 71 | + </View> |
| 72 | + <GoldGradient> |
| 73 | + <Button className="bg-transparent w-full" onPress={handleSubmit} disabled={isPending}> |
| 74 | + {isPending ? ( |
| 75 | + <ActivityIndicator color={colorScheme === 'dark' ? '#000000' : '#ffffff'} /> |
| 76 | + ) : ( |
| 77 | + <Text>Continue</Text> |
| 78 | + )} |
| 79 | + </Button> |
| 80 | + </GoldGradient> |
| 81 | + </View> |
| 82 | + </CardContent> |
| 83 | + </Card> |
| 84 | + </View> |
| 85 | + </View> |
| 86 | + </ScrollView> |
| 87 | + </KeyboardAvoidingView> |
| 88 | + ); |
| 89 | +}; |
| 90 | + |
| 91 | +export default ForgotPassword; |
0 commit comments