Skip to content

Commit

Permalink
[#192] Implement updated by in CaseProfile FE
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Jan 5, 2024
1 parent 652e071 commit 54e621d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions frontend/src/pages/cases/components/CaseProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
[]
);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 54e621d

Please # to comment.