diff --git a/src/Geopilot.Frontend/cypress/e2e/delivery.cy.js b/src/Geopilot.Frontend/cypress/e2e/delivery.cy.js index 319293ec..05187454 100644 --- a/src/Geopilot.Frontend/cypress/e2e/delivery.cy.js +++ b/src/Geopilot.Frontend/cypress/e2e/delivery.cy.js @@ -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"); diff --git a/src/Geopilot.Frontend/src/pages/delivery/deliverySubmit.tsx b/src/Geopilot.Frontend/src/pages/delivery/deliverySubmit.tsx index a792006c..0e3e5f30 100644 --- a/src/Geopilot.Frontend/src/pages/delivery/deliverySubmit.tsx +++ b/src/Geopilot.Frontend/src/pages/delivery/deliverySubmit.tsx @@ -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("/api/v1/delivery?" + new URLSearchParams({ mandateId: mandateId })).then( + fetchApi("/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 ? ( @@ -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} />