Skip to content

Commit

Permalink
Reset predecessor on mandate change (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschumpr authored Sep 16, 2024
2 parents 6423cf8 + 437e197 commit 52e2f39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/Geopilot.Frontend/cypress/e2e/delivery.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ describe("Delivery tests", () => {
isDisabled("predecessor", false);
cy.get('[data-cy="createDelivery-button"]').should("be.enabled");
setSelect("predecessor", 1);
setSelect("mandate", 2);
cy.wait("@predecessors");
evaluateSelect("predecessor", "");
setSelect("predecessor", 2);
setSelect("mandate", 0);
isDisabled("predecessor", true);
cy.get('[data-cy="createDelivery-button"]').should("be.disabled");
Expand Down
23 changes: 11 additions & 12 deletions src/Geopilot.Frontend/src/pages/delivery/deliverySubmit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,22 @@ export const DeliverySubmit = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [validationResponse, user]);

useEffect(() => {
const mandateId = formMethods.getValues()["mandate"];
const submitForm = (data: FieldValues) => {
if (data["predecessor"] === "") {
data["predecessor"] = null;
}
submitDelivery(data as DeliverySubmitData);
};

const handleMandateChange = (mandateId: number) => {
formMethods.setValue("predecessor", undefined);
if (mandateId) {
fetchApi<Delivery[]>("/api/v1/delivery?" + new URLSearchParams({ mandateId: mandateId })).then(
fetchApi<Delivery[]>("/api/v1/delivery?" + new URLSearchParams({ mandateId: mandateId.toString() })).then(
setPreviousDeliveries,
);
} else {
setPreviousDeliveries([]);
formMethods.setValue("predecessor", undefined);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [formMethods.getValues()["mandate"]]);

const submitForm = (data: FieldValues) => {
if (data["predecessor"] === "") {
data["predecessor"] = null;
}
submitDelivery(data as DeliverySubmitData);
};

return authEnabled && user ? (
Expand All @@ -68,6 +66,7 @@ export const DeliverySubmit = () => {
values={mandates
?.sort((a, b) => a.name.localeCompare(b.name))
.map(mandate => ({ key: mandate.id, name: mandate.name }))}
onUpdate={handleMandateChange}
/>
<FormSelect
fieldName="predecessor"
Expand Down

0 comments on commit 52e2f39

Please sign in to comment.