From 546d3d2659f32a2d76d353d7bd8094dff3951fde Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Mon, 18 Mar 2024 14:55:07 +0300 Subject: [PATCH] Fix userpic upload mutation --- .../ProfileSettings/ProfileSettings.tsx | 2 +- src/context/profile.tsx | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/components/ProfileSettings/ProfileSettings.tsx b/src/components/ProfileSettings/ProfileSettings.tsx index 1c2afd98..70389ccb 100644 --- a/src/components/ProfileSettings/ProfileSettings.tsx +++ b/src/components/ProfileSettings/ProfileSettings.tsx @@ -123,7 +123,7 @@ export const ProfileSettings = () => { setIsUserpicUpdating(true) const result = await handleImageUpload(uploadFile) - updateFormField('userpic', result.url) + updateFormField('pic', result.url) setUserpicFile(null) setIsUserpicUpdating(false) diff --git a/src/context/profile.tsx b/src/context/profile.tsx index 1b88f149..48262694 100644 --- a/src/context/profile.tsx +++ b/src/context/profile.tsx @@ -54,18 +54,12 @@ export const ProfileFormProvider = (props: { children: JSX.Element }) => { const updateFormField = (fieldName: string, value: string, remove?: boolean) => { if (fieldName === 'links') { - if (remove) { - setForm( - 'links', - form.links.filter((item) => item !== value), - ) - } else { - setForm((prev) => ({ ...prev, links: [...prev.links, value] })) - } + setForm((prev) => { + const updatedLinks = remove ? prev.links.filter((item) => item !== value) : [...prev.links, value]; + return { ...prev, links: updatedLinks }; + }); } else { - setForm({ - [fieldName]: value, - }) + setForm((prev) => ({ ...prev, [fieldName]: value })); } }