Skip to content

Commit

Permalink
Fixed draft (#1775)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhaib-aot authored Nov 23, 2023
1 parent 655da84 commit 98d1735
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion forms-flow-web/src/components/Draft/DraftTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const DraftTable = () => {
return (
<button
className="btn btn-link mt-2"
onClick={() => window.open(url, "_blank")}
onClick={() => dispatch(push(url))}
>
<Translation>{(t) => t("Edit Draft")}</Translation>{" "}
</button>
Expand Down
23 changes: 12 additions & 11 deletions forms-flow-web/src/components/Draft/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,16 @@ const View = React.memo((props) => {
} = props;
const dispatch = useDispatch();

const saveDraft = (payload, exitType = exitType) => {
const formStatusLoading = useSelector(
(state) => state.process?.formStatusLoading
);

const processData = useSelector(
(state) => state.process?.formProcessList
);


const saveDraft = (payload, exitType = exitType?.current) => {
if (exitType === "SUBMIT" || processData?.status !== "active") return;
let dataChanged = !isEqual(payload.data, lastUpdatedDraft.data);
if (draftSubmission?.id) {
Expand All @@ -117,14 +126,6 @@ const View = React.memo((props) => {
}
}
};
const formStatusLoading = useSelector(
(state) => state.process?.formStatusLoading
);

const processData = useSelector(
(state) => state.process?.formProcessList
);

/**
* We will repeatedly update the current state to draft table
* on purticular interval
Expand All @@ -150,13 +151,13 @@ const View = React.memo((props) => {

useEffect(() => {
return () => {
if(draftRef.current)
if(draftRef.current)
{
let payload = getDraftReqFormat(formId, draftRef.current);
if (poll) saveDraft(payload, exitType.current);
}
};
}, [poll, exitType.current, draftSubmission?.id]);
}, [poll, exitType.current, draftSubmission?.id, processData?.status]);

if (isActive || isPublicStatusLoading || formStatusLoading) {
return (
Expand Down

0 comments on commit 98d1735

Please sign in to comment.