diff --git a/src/components/default/auth/cards/client/profile.tsx b/src/components/default/auth/cards/client/profile.tsx index c9495b3..11a0291 100644 --- a/src/components/default/auth/cards/client/profile.tsx +++ b/src/components/default/auth/cards/client/profile.tsx @@ -2,3 +2,9 @@ import { useAuth } from '@/lib/hooks/context'; import { useEffect } from 'react'; import { useRouter } from 'next/navigation'; +import { + AvatarUpload, + ProfileForm, + ResetPasswordForm, + SignOut, +} from '@/components/default/auth/forms/client/profile'; diff --git a/src/components/default/auth/forms/client/profile/index.tsx b/src/components/default/auth/forms/client/profile/index.tsx new file mode 100644 index 0000000..6d630d5 --- /dev/null +++ b/src/components/default/auth/forms/client/profile/index.tsx @@ -0,0 +1,4 @@ +export { AvatarUpload } from './avatar-upload'; +export { ProfileForm } from './profile-form'; +export { ResetPasswordForm } from './reset-password-form'; +export { SignOut } from './sign-out'; diff --git a/src/components/default/auth/forms/client/profile/profile-form.tsx b/src/components/default/auth/forms/client/profile/profile-form.tsx index e69de29..14d0cdc 100644 --- a/src/components/default/auth/forms/client/profile/profile-form.tsx +++ b/src/components/default/auth/forms/client/profile/profile-form.tsx @@ -0,0 +1,100 @@ +'use client'; +import { z } from 'zod'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useAuth } from '@/lib/hooks/context'; +import { useEffect } from 'react'; +import { useForm } from 'react-hook-form'; +import { SubmitButton } from '@/components/default/forms'; +import { + CardContent, + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, + Input, +} from '@/components/ui'; + +const formSchema = z.object({ + full_name: z.string().min(5, { + message: 'Full name is required & must be at least 5 characters.', + }), + email: z.string().email(), +}); + +type ProfileFormProps = { + onSubmit: (values: z.infer) => Promise; +}; + +export const ProfileForm = ({ + onSubmit, +}: ProfileFormProps) => { + const { profile, loading } = useAuth(); + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + full_name: profile?.full_name ?? '', + email: profile?.email ?? '', + }, + }); + + useEffect(() => { + if (profile) + form.reset({ + full_name: profile.full_name ?? '', + email: profile.email ?? '', + }); + }, [profile, form]); + + const handleSubmit = async (values: z.infer) => { + await onSubmit(values); + }; + + return ( + +
+ + ( + + Full Name + + + + Your public display name. + + + )} + /> + + ( + + Email + + + + + Your email address associated with your account. + + + + )} + /> + +
+ + Save Changes + +
+ + +
+ ); +}; diff --git a/src/components/default/auth/forms/client/profile/reset-password-form.tsx b/src/components/default/auth/forms/client/profile/reset-password-form.tsx index e69de29..28f843d 100644 --- a/src/components/default/auth/forms/client/profile/reset-password-form.tsx +++ b/src/components/default/auth/forms/client/profile/reset-password-form.tsx @@ -0,0 +1,54 @@ +'use client'; +import { z } from 'zod'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { useAuth } from '@/lib/hooks/context'; +import { useForm } from 'react-hook-form'; +import { useState } from 'react'; +import { StatusMessage, SubmitButton } from '@/components/default/forms'; +import { type Result } from '@/utils/supabase/types' + +const formSchema = z + .object({ + password: z.string().min(8, { + message: 'Password must be at least 8 characters.', + }), + confirmPassword: z.string(), + }) + .refine((data) => data.password === data.confirmPassword, { + message: 'Passwords do not match.', + path: ['confirmPassword'], + }); + +type ResetPasswordFormProps = { + onSubmit: (formData: FormData) => Promise>; + message?: string; +}; + +export const ResetPasswordForm = ({ + onSubmit, + message, +}: ResetPasswordFormProps) => { + const { loading } = useAuth(); + const [statusMessage, setStatusMessage] = useState(message ?? ''); + + const form = useForm>({ + resolver: zodResolver(formSchema), + defaultValues: { + password: '', + confirmPassword: '', + }, + }); + + const handleSubmit = async (values: z.infer) => { + try { + const formData = new FormData(); + formData.append('password', values.password); + formData.append('confirmPassword', values.confirmPassword); + await onSubmit(formData); + + } catch (error) { + + } + } + +};