From 003020c95266eda16e228481369c88c70b28c943 Mon Sep 17 00:00:00 2001 From: sina_sajjadi Date: Mon, 27 Jan 2025 17:36:10 +0330 Subject: [PATCH] feat: update site name and logo, modify profile validation schema, and adjust API endpoints for user updates --- src/components/auth/change-password-from.tsx | 25 +- src/components/auth/email-update-form.tsx | 5 +- src/components/auth/profile-update-form.tsx | 77 ++--- .../auth/profile-validation-schema.tsx | 6 +- src/components/chat/chat-input.tsx | 286 ++++++++---------- src/components/chat/message.tsx | 6 +- src/components/chat/messages-list.tsx | 6 +- src/components/dashboard/admin.tsx | 2 +- src/components/layouts/topbar/message-bar.tsx | 2 +- src/components/product/product-form.tsx | 20 +- src/data/client/api-endpoints.ts | 6 +- src/data/client/http-client.ts | 15 +- src/data/client/user.ts | 6 +- src/data/user.ts | 66 ++-- src/pages/settings/index.tsx | 6 +- src/settings/site.settings.ts | 4 +- src/utils/auth-utils.ts | 82 ++--- 17 files changed, 297 insertions(+), 323 deletions(-) diff --git a/src/components/auth/change-password-from.tsx b/src/components/auth/change-password-from.tsx index ab23d98..f2ff64f 100644 --- a/src/components/auth/change-password-from.tsx +++ b/src/components/auth/change-password-from.tsx @@ -16,11 +16,10 @@ interface FormValues { } const changePasswordSchema = yup.object().shape({ - oldPassword: yup.string().required('form:error-old-password-required'), - newPassword: yup.string().required('form:error-password-required'), - passwordConfirmation: yup + password: yup.string().required('form:error-password-required'), + password_confirmation: yup .string() - .oneOf([yup.ref('newPassword')], 'form:error-match-passwords') + .oneOf([yup.ref('password')], 'form:error-match-passwords') .required('form:error-confirm-password'), }); @@ -42,8 +41,8 @@ const ChangePasswordForm = () => { async function onSubmit(values: FormValues) { changePassword( { - oldPassword: values.oldPassword, - newPassword: values.newPassword, + password: values.password, + password_confirmation: values.password_confirmation, }, { onError: (error: any) => { @@ -79,30 +78,30 @@ const ChangePasswordForm = () => { /> - + /> */}
-
diff --git a/src/components/auth/email-update-form.tsx b/src/components/auth/email-update-form.tsx index acda683..daa216b 100644 --- a/src/components/auth/email-update-form.tsx +++ b/src/components/auth/email-update-form.tsx @@ -25,11 +25,14 @@ export default function EmailUpdateForm({ me }: any) { }); async function onSubmit(values: FormValues) { + console.log("hi"); + const {email } = values; updateEmail({ email: email, }); } +console.log(errors); return (
@@ -52,7 +55,7 @@ export default function EmailUpdateForm({ me }: any) {
-
diff --git a/src/components/auth/profile-update-form.tsx b/src/components/auth/profile-update-form.tsx index 1fd55b8..bef50a6 100644 --- a/src/components/auth/profile-update-form.tsx +++ b/src/components/auth/profile-update-form.tsx @@ -37,14 +37,14 @@ export default function ProfileUpdate({ me }: any) { const { t } = useTranslation(); const { mutate: updateUser, isLoading: loading } = useUpdateUserMutation(); const { permissions } = getAuthCredentials(); - let permission = hasAccess(adminOnly, permissions); + const permission = hasAccess(adminOnly, permissions); + const { register, handleSubmit, control, - formState: { errors }, + formState: { errors, dirtyFields }, } = useForm({ - //@ts-ignore resolver: yupResolver(profileValidationSchema), defaultValues: { ...(me && @@ -60,28 +60,31 @@ export default function ProfileUpdate({ me }: any) { }); async function onSubmit(values: FormValues) { - const { name, profile } = values; - const { notifications } = profile; - const input = { + console.log(values); + + // If nothing is dirty, no need to call the update + if (Object.keys(dirtyFields).length === 0) { + return; + } + + // Construct your payload conditionally + // Always include the user id for the update + const inputPayload: any = { id: me?.id, - input: { - name: name, - profile: { - id: me?.profile?.id, - bio: profile?.bio, - contact: profile?.contact, - avatar: { - thumbnail: profile?.avatar?.thumbnail, - original: profile?.avatar?.original, - id: profile?.avatar?.id, - }, - notifications: { - ...notifications, - }, - }, - }, + input: {}, }; - updateUser({ ...input }); + + // Check top-level fields first + if (dirtyFields.fullname) { + inputPayload.input.fullname = values.fullname; + } + + if (dirtyFields.avatar) { + inputPayload.input.avatar = values.avatar; + } + + // Finally call the mutation with the built payload + updateUser(inputPayload); } return ( @@ -94,17 +97,17 @@ export default function ProfileUpdate({ me }: any) { /> - + - {permission ? ( + + {/* {permission && (
-
- ) : ( - '' - )} + )} */} +
- -