Skip to content

Commit

Permalink
Move update logic to separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
tschumpr committed Sep 16, 2024
1 parent db0fc93 commit 437e197
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Geopilot.Frontend/src/pages/delivery/deliverySubmit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ export const DeliverySubmit = () => {
submitDelivery(data as DeliverySubmitData);
};

const handleMandateChange = (mandateId: number) => {
formMethods.setValue("predecessor", undefined);
if (mandateId) {
fetchApi<Delivery[]>("/api/v1/delivery?" + new URLSearchParams({ mandateId: mandateId.toString() })).then(
setPreviousDeliveries,
);
} else {
setPreviousDeliveries([]);
}
};

return authEnabled && user ? (
<FormProvider {...formMethods}>
<form onSubmit={formMethods.handleSubmit(submitForm)}>
Expand All @@ -55,16 +66,7 @@ export const DeliverySubmit = () => {
values={mandates
?.sort((a, b) => a.name.localeCompare(b.name))
.map(mandate => ({ key: mandate.id, name: mandate.name }))}
onUpdate={mandateId => {
formMethods.setValue("predecessor", undefined);
if (mandateId) {
fetchApi<Delivery[]>(
"/api/v1/delivery?" + new URLSearchParams({ mandateId: mandateId.toString() }),
).then(setPreviousDeliveries);
} else {
setPreviousDeliveries([]);
}
}}
onUpdate={handleMandateChange}
/>
<FormSelect
fieldName="predecessor"
Expand Down

0 comments on commit 437e197

Please sign in to comment.