diff --git a/src/components/EditProfileModal.tsx b/src/components/EditProfileModal.tsx index bc2818a..ca71679 100644 --- a/src/components/EditProfileModal.tsx +++ b/src/components/EditProfileModal.tsx @@ -6,6 +6,7 @@ import { useUpdateUser } from '@/hooks/user' import Avatar from '@/components/Avatar' import TextInput from '@/components/TextInput' import Modal from '@/components/Modal' +import Form from '@/components/Form' import FileUploadWrapper from './FileUploadWrapper' type FormType = 'profile' | 'password' @@ -58,30 +59,16 @@ const EditProfileForm: React.FC = ({ user, setOpen, setActiveForm }) -
+ setOpen && setOpen(false)} + isSubmitting={isLoading} + > -
-
- - -
-
- + ) } @@ -105,30 +92,17 @@ const EditPasswordForm: React.FC = ({ user, setActiveForm }) => { if (!user) return <> return (
-
+ setActiveForm('profile')} + isSubmitting={isLoading} + allowDirtySubmit + > true} /> -
-
- - -
-
- +
) } diff --git a/src/components/Form.tsx b/src/components/Form.tsx new file mode 100644 index 0000000..60dc0c5 --- /dev/null +++ b/src/components/Form.tsx @@ -0,0 +1,66 @@ +// Form.tsx +import React from 'react' +import { SubmitHandler } from 'react-hook-form' + +type FormProps = { + form: any; // Update this type based on your actual form state type + onSubmit: SubmitHandler; // Update the type based on your form data type + onClose?: () => void; + onCancel?: () => void; + isSubmitting?: boolean; + allowDirtySubmit?: boolean; + children: React.ReactNode; +} + +const Form: React.FC = ({ + form, + onSubmit, + onClose = null, + onCancel = null, + isSubmitting = false, + allowDirtySubmit = false, + children +}) => ( +
+
+ {children} +
+
+ + {onClose && ( + + )} + {onCancel && ( + + )} +
+
+
+
+) + +export default Form