From bb50f7cadc8d47c1bf66fea308660bd52929860d Mon Sep 17 00:00:00 2001 From: wayangalihpratama Date: Thu, 4 Jan 2024 16:51:25 +0800 Subject: [PATCH] [#192] Check update status for case profile payload --- .../src/pages/cases/components/CaseProfile.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/frontend/src/pages/cases/components/CaseProfile.js b/frontend/src/pages/cases/components/CaseProfile.js index 5bb7bba4..f57e9e5e 100644 --- a/frontend/src/pages/cases/components/CaseProfile.js +++ b/frontend/src/pages/cases/components/CaseProfile.js @@ -35,6 +35,7 @@ import { api } from "../../../lib"; import { UIState, UserState } from "../../../store"; import isEmpty from "lodash/isEmpty"; import uniqBy from "lodash/uniqBy"; +import isEqual from "lodash/isEqual"; import { useParams, useNavigate } from "react-router-dom"; import dayjs from "dayjs"; import { casePermission } from "../../../store/static"; @@ -298,6 +299,12 @@ const CaseProfile = ({ const [isNextButton, setIsNextButton] = useState(false); const [privateCase, setPrivateCase] = useState(false); + const currentCaseProfile = useMemo( + () => formData, + // eslint-disable-next-line react-hooks/exhaustive-deps + [] + ); + { /* Support add User Access */ } @@ -450,6 +457,29 @@ const CaseProfile = ({ tags: values.tags || null, }; + // check current value with update value + const filteredCurrentCaseProfile = Object.entries( + currentCaseProfile + ).reduce((acc, [key, value]) => { + if (typeof value !== "undefined") { + acc[key] = value; + } + return acc; + }, {}); + const filteredValues = Object.entries(values).reduce( + (acc, [key, value]) => { + if (typeof value !== "undefined") { + acc[key] = value; + } + return acc; + }, + {} + ); + const isUpdated = !isEqual(filteredCurrentCaseProfile, filteredValues); + // console.log(filteredCurrentCaseProfile, "FormData"); + // console.log(filteredValues, "payload"); + console.info(isUpdated, "UPDATED"); + const paramCaseId = caseId ? caseId : currentCaseId; const apiCall = currentCaseId || caseId