Skip to content

Commit

Permalink
[#192] Check update status for case profile payload
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Jan 4, 2024
1 parent 63e4d25 commit bb50f7c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions frontend/src/pages/cases/components/CaseProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 */
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bb50f7c

Please # to comment.