From 54e621d12e92d6e5c17165d8f18a7b9ef12c727a Mon Sep 17 00:00:00 2001 From: wayangalihpratama Date: Fri, 5 Jan 2024 14:49:14 +0800 Subject: [PATCH] [#192] Implement updated by in CaseProfile FE --- .../src/pages/cases/components/CaseProfile.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/frontend/src/pages/cases/components/CaseProfile.js b/frontend/src/pages/cases/components/CaseProfile.js index f422a7e4..54b6146c 100644 --- a/frontend/src/pages/cases/components/CaseProfile.js +++ b/frontend/src/pages/cases/components/CaseProfile.js @@ -299,9 +299,12 @@ const CaseProfile = ({ useState(true); const [isNextButton, setIsNextButton] = useState(false); const [privateCase, setPrivateCase] = useState(false); + const [currentCaseProfile, setCurrentCaseProfile] = useState({}); - const currentCaseProfile = useMemo( - () => formData, + useEffect( + () => { + setCurrentCaseProfile(formData); + }, // eslint-disable-next-line react-hooks/exhaustive-deps [] ); @@ -461,17 +464,22 @@ const CaseProfile = ({ // detect is payload updated const filteredCurrentCaseProfile = removeUndefinedObjectValue(currentCaseProfile); - const filteredValues = removeUndefinedObjectValue(values); + const filteredValues = { + ...filteredCurrentCaseProfile, + ...removeUndefinedObjectValue(values), + private: privateCase, + reporting_period: "per-year", + }; const isUpdated = !isEqual(filteredCurrentCaseProfile, filteredValues); - console.info(isUpdated, "UPDATED"); const paramCaseId = caseId ? caseId : currentCaseId; const apiCall = currentCaseId || caseId - ? api.put(`case/${paramCaseId}`, payload) + ? api.put(`case/${paramCaseId}?updated=${isUpdated}`, payload) : api.post("case", payload); apiCall .then((res) => { + setCurrentCaseProfile(filteredValues); const { data } = res; setCurrentCaseId(data?.id); setCurrentCase(data);