From 35456073e6007f0b1ff3ac7a027fe78f84c39eaf Mon Sep 17 00:00:00 2001 From: Lennart Bank Date: Thu, 20 Apr 2023 13:54:20 +0200 Subject: [PATCH] FINALIZE --- pages/extra/index.tsx | 31 ++++++++++++++++++++------ pages/persoonsgegevens/[person].tsx | 3 ++- src/context/MarriageOptionsContext.tsx | 1 - 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/pages/extra/index.tsx b/pages/extra/index.tsx index f54640c7..51f10b02 100644 --- a/pages/extra/index.tsx +++ b/pages/extra/index.tsx @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import { FormField, FormLabel } from "@utrecht/component-library-react"; import Head from "next/head"; import Image from "next/image"; @@ -28,7 +27,7 @@ import { PageFooterTemplate } from "../../src/components/huwelijksplanner/PageFo import { PageHeaderTemplate } from "../../src/components/huwelijksplanner/PageHeaderTemplate"; import { ReservationCard } from "../../src/components/huwelijksplanner/ReservationCard"; import { MarriageOptionsContext } from "../../src/context/MarriageOptionsContext"; -import { SdgproductService } from "../../src/generated"; +import { HuwelijkService, SdgproductService } from "../../src/generated"; export const getServerSideProps = async ({ locale }: { locale: string }) => ({ props: { @@ -39,7 +38,9 @@ export const getServerSideProps = async ({ locale }: { locale: string }) => ({ export default function MultistepForm1() { const { t } = useTranslation(["common", "huwelijksplanner-step-5", "form"]); const { locale, push } = useRouter(); + const [isLoading, setIsLoading] = useState(false); + const [isSavingProduct, setIsSavingProduct] = useState(false); const [trouwboekje, setTrouwboekje] = useState(); const [selectedExtra, setSelectedExtra] = useState(); @@ -49,9 +50,21 @@ export default function MultistepForm1() { const onMarriageCertificateKindSubmit = (event: FormEvent) => { event.preventDefault(); - setMarriageOptions({...marriageOptions, extras: [selectedExtra]}); + setIsSavingProduct(true); + + HuwelijkService.huwelijkPatchItem(marriageOptions.huwelijk.id, { producten: [selectedExtra] }) + .then((res) => { + setMarriageOptions({ + ...marriageOptions, + huwelijk: { + ...marriageOptions.huwelijk, + "ceremony-price-amount": res.kosten ? res.kosten.replace("EUR ", "") : "-", + }, + }); - push("/voorgenomen-huwelijk/checken"); + push("/voorgenomen-huwelijk/checken"); + }) + .finally(() => setIsSavingProduct(false)); }; useEffect(() => { @@ -113,15 +126,19 @@ export default function MultistepForm1() { {trouwboekje.embedded.vertalingen.map((vertaling: any) => ( - setSelectedExtra(vertaling.id)} id={vertaling.id} name="marriage-certificate-kind" /> + setSelectedExtra(vertaling.id)} + id={vertaling.id} + name="marriage-certificate-kind" + /> {vertaling.specifiekeTekst} ({vertaling.kosten}) ))} - )} diff --git a/pages/persoonsgegevens/[person].tsx b/pages/persoonsgegevens/[person].tsx index 08c63a1d..428fd363 100644 --- a/pages/persoonsgegevens/[person].tsx +++ b/pages/persoonsgegevens/[person].tsx @@ -359,7 +359,8 @@ export default function MultistepForm1() { setIsLoading(true); if (!huwelijkId) { - AssentService.assentPatchItem(huwelijk?.partners[0]._self.id, { + // @ts-ignore + AssentService.assentPatchItem(huwelijk?.embedded?.partners[0]._self.id, { requester: getBsnFromJWT(), contact: { subjectIdentificatie: { diff --git a/src/context/MarriageOptionsContext.tsx b/src/context/MarriageOptionsContext.tsx index 0e25ac4b..15ccb54e 100644 --- a/src/context/MarriageOptionsContext.tsx +++ b/src/context/MarriageOptionsContext.tsx @@ -18,7 +18,6 @@ export interface MarriageOptionsProps { huwelijk: Huwelijk; ambtenaar?: string; ceremonyId?: string; - extras?: string[]; } const myWindow = typeof window !== "undefined" ? window : undefined;