diff --git a/mobile/app/signup.tsx b/mobile/app/signup.tsx new file mode 100644 index 0000000..eda2367 --- /dev/null +++ b/mobile/app/signup.tsx @@ -0,0 +1,140 @@ +import React from 'react'; +import { StyleSheet, View, Button, Text, TextInput, ActivityIndicator, Alert } from 'react-native'; +import { Formik } from 'formik'; +import * as Yup from 'yup'; +import { useRouter } from 'expo-router'; + +import authApi from '../services/authApi'; +import { useApi } from '@/services/useAPI'; + + +const SignUpSchema = Yup.object().shape({ + name: Yup.string() + .min(2, 'Too Short!') + .required('Name is required'), + email: Yup.string() + .email('Invalid email') + .required('Email is required'), + password: Yup.string() + .min(8, 'Password must be at least 8 characters') + .required('Password is required'), + confirmPassword: Yup.string() + .oneOf([Yup.ref('password')], 'Passwords must match') + .required('Confirm Password is required'), +}); + +export default function SignUpScreen() { + const router = useRouter(); + const { request: performSignUp, loading, error } = useApi(authApi.signUp); + + + const handleSubmit = async (values: any) => { + const { name, email, password } = values; + const result = await performSignUp({ name, email, password }); + + if (result.success) { + Alert.alert( + 'Success!', + result.data?.message || 'You have been registered successfully.', + [{ text: 'OK', onPress: () => router.replace('/login') }] + ); + } + + }; + + return ( + + Create Account + + + + {({ handleChange, handleBlur, handleSubmit, values, errors, touched }) => ( + + + {errors.name && touched.name ? {errors.name} : null} + + + {errors.email && touched.email ? {errors.email} : null} + + + {errors.password && touched.password ? {errors.password} : null} + + + {errors.confirmPassword && touched.confirmPassword ? {errors.confirmPassword} : null} + + + {error && {error}} + + {loading ? ( + + ) : ( +