Skip to content

Commit

Permalink
OM-277: reset forms when eu changed
Browse files Browse the repository at this point in the history
  • Loading branch information
olewandowski1 committed Aug 30, 2024
1 parent 3a08753 commit 84abf2e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/components/VoucherAcquirementGenericVoucher.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function VoucherAcquirementGenericVoucher() {
const [acquirementSummaryLoading, setAcquirementSummaryLoading] = useState(false);
const [isPaymentModalOpen, setIsPaymentModalOpen] = useState(false);
const { mutation, submittingMutation } = useSelector((state) => state.workerVoucher);
const { economicUnit } = useSelector((state) => state.policyHolder);

const acquirementBlocked = (voucherAcquirement) => !voucherAcquirement?.quantity
|| voucherAcquirement?.quantity > VOUCHER_QUANTITY_THRESHOLD;
Expand Down Expand Up @@ -106,9 +107,9 @@ function VoucherAcquirementGenericVoucher() {
if (storedUserEconomicUnit) {
const userEconomicUnit = JSON.parse(storedUserEconomicUnit);

setVoucherAcquirement((prevState) => ({ ...prevState, employer: userEconomicUnit }));
setVoucherAcquirement((prevState) => ({ ...prevState, employer: userEconomicUnit, quantity: 0 }));
}
}, [setVoucherAcquirement]);
}, [setVoucherAcquirement, economicUnit]);

return (
<>
Expand Down
7 changes: 5 additions & 2 deletions src/components/VoucherAcquirementSpecificWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function VoucherAcquirementSpecificWorker() {
const [acquirementSummaryLoading, setAcquirementSummaryLoading] = useState(false);
const [isPaymentModalOpen, setIsPaymentModalOpen] = useState(false);
const { mutation, submittingMutation } = useSelector((state) => state.workerVoucher);
const { economicUnit } = useSelector((state) => state.policyHolder);

const acquirementBlocked = (voucherAcquirement) => !voucherAcquirement?.workers?.length
|| !voucherAcquirement?.dateRanges?.length;
Expand Down Expand Up @@ -113,9 +114,11 @@ function VoucherAcquirementSpecificWorker() {
if (storedUserEconomicUnit) {
const userEconomicUnit = JSON.parse(storedUserEconomicUnit);

setVoucherAcquirement((prevState) => ({ ...prevState, employer: userEconomicUnit }));
setVoucherAcquirement((prevState) => ({
...prevState, employer: userEconomicUnit, workers: [], dateRanges: [],
}));
}
}, [setVoucherAcquirement]);
}, [setVoucherAcquirement, economicUnit]);

return (
<>
Expand Down
7 changes: 5 additions & 2 deletions src/components/VoucherAssignmentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function VoucherAssignmentForm() {
const [assignmentSummaryLoading, setAssignmentSummaryLoading] = useState(false);
const [isConfirmationModalOpen, setIsConfirmationModalOpen] = useState(false);
const { mutation, submittingMutation } = useSelector((state) => state.workerVoucher);
const { economicUnit } = useSelector((state) => state.policyHolder);

const assignmentBlocked = (voucherAssignment) => !voucherAssignment?.workers?.length
|| !voucherAssignment?.dateRanges?.length;
Expand Down Expand Up @@ -91,9 +92,11 @@ function VoucherAssignmentForm() {
if (storedUserEconomicUnit) {
const userEconomicUnit = JSON.parse(storedUserEconomicUnit);

setVoucherAssignment((prevState) => ({ ...prevState, employer: userEconomicUnit }));
setVoucherAssignment((prevState) => ({
...prevState, employer: userEconomicUnit, workers: [], dateRanges: [],
}));
}
}, [setVoucherAssignment]);
}, [setVoucherAssignment, economicUnit]);

return (
<Grid container>
Expand Down

0 comments on commit 84abf2e

Please sign in to comment.