diff --git a/src/OAP/Oap.Theme.Svelte/src/ApplicationForm.svelte b/src/OAP/Oap.Theme.Svelte/src/ApplicationForm.svelte index cc71e3c..a5f9745 100644 --- a/src/OAP/Oap.Theme.Svelte/src/ApplicationForm.svelte +++ b/src/OAP/Oap.Theme.Svelte/src/ApplicationForm.svelte @@ -1,12 +1,15 @@ @@ -101,7 +129,7 @@

No content data??

{:else if $content.data?.oapApplicationForm}
- {#each $content.data?.oapApplicationForm as oapApplicationForm} + {#each $content.data.oapApplicationForm as oapApplicationForm} {#if oapApplicationForm}

{/if} {#each oapApplicationForm?.list?.contentItems ?? [] as contentItem, index} - {#if contentItem?.__typename === "OapApplicationFormStep" && $step === index} + {#if contentItem?.__typename === "OapApplicationFormStep" && $applicationFormState.currentStep === index} diff --git a/src/OAP/Oap.Theme.Svelte/src/components/ApplicationFormStep.svelte b/src/OAP/Oap.Theme.Svelte/src/components/ApplicationFormStep.svelte index 6e8246d..eec3e7a 100644 --- a/src/OAP/Oap.Theme.Svelte/src/components/ApplicationFormStep.svelte +++ b/src/OAP/Oap.Theme.Svelte/src/components/ApplicationFormStep.svelte @@ -24,10 +24,6 @@ import Form from "./Form.svelte"; import type { EventHandler } from "svelte/elements"; - export let onSubmit: - | EventHandler - | undefined - | null; export let antiForgeryToken: string | null; export let fragment: FragmentType; @@ -44,6 +40,6 @@ {#each content.flow?.widgets ?? [] as widget} {#if widget?.__typename === "Form"} -
+ {/if} {/each} diff --git a/src/OAP/Oap.Theme.Svelte/src/components/Fields/Button.svelte b/src/OAP/Oap.Theme.Svelte/src/components/Fields/Button.svelte index 5a699fb..4e45bec 100644 --- a/src/OAP/Oap.Theme.Svelte/src/components/Fields/Button.svelte +++ b/src/OAP/Oap.Theme.Svelte/src/components/Fields/Button.svelte @@ -7,10 +7,14 @@ - diff --git a/src/OAP/Oap.Theme.Svelte/src/components/Form.svelte b/src/OAP/Oap.Theme.Svelte/src/components/Form.svelte index d4631ce..388e0c2 100644 --- a/src/OAP/Oap.Theme.Svelte/src/components/Form.svelte +++ b/src/OAP/Oap.Theme.Svelte/src/components/Form.svelte @@ -26,7 +26,6 @@ @@ -49,7 +48,7 @@ id={content.formElement?.id} action={content.form?.action} method={content.form?.method} - on:submit|preventDefault={onSubmit} + on:submit|preventDefault={formContext.handleSubmit} > ; @@ -33,6 +35,8 @@ OapApplicationFormButtonsWidgetFragment, fragment, ); + + const formContext = getContext("formContext"); @@ -45,6 +49,7 @@ type={isButtonType(content.back?.type) ? content.back?.type : "button"} + onClick={formContext.handleBack} /> {:else}   diff --git a/src/OAP/Oap.Theme.Svelte/src/lib/contextModels.ts b/src/OAP/Oap.Theme.Svelte/src/lib/contextModels.ts new file mode 100644 index 0000000..2cf2cd7 --- /dev/null +++ b/src/OAP/Oap.Theme.Svelte/src/lib/contextModels.ts @@ -0,0 +1,6 @@ +import type { EventHandler } from "svelte/elements"; + +export interface FormContext { + handleSubmit: EventHandler; + handleBack: EventHandler; +} diff --git a/src/OAP/Oap.Theme.Svelte/src/lib/stores.ts b/src/OAP/Oap.Theme.Svelte/src/lib/stores.ts index 5e78bcf..6686a35 100644 --- a/src/OAP/Oap.Theme.Svelte/src/lib/stores.ts +++ b/src/OAP/Oap.Theme.Svelte/src/lib/stores.ts @@ -1,5 +1,3 @@ -import applicationId from "./stores/applicationId"; -import step from "./stores/step"; -import application from './stores/application'; +import applicationFormState from "./stores/applicationFormState"; -export { step, applicationId, application }; +export { applicationFormState }; diff --git a/src/OAP/Oap.Theme.Svelte/src/lib/stores/application.ts b/src/OAP/Oap.Theme.Svelte/src/lib/stores/application.ts deleted file mode 100644 index cf427c0..0000000 --- a/src/OAP/Oap.Theme.Svelte/src/lib/stores/application.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { writable } from "svelte/store"; -import { type IApplication } from "../oap/oapApiV1ClientTypes"; - -const application = writable(null); - -export default application; diff --git a/src/OAP/Oap.Theme.Svelte/src/lib/stores/applicationFormState.ts b/src/OAP/Oap.Theme.Svelte/src/lib/stores/applicationFormState.ts new file mode 100644 index 0000000..d118618 --- /dev/null +++ b/src/OAP/Oap.Theme.Svelte/src/lib/stores/applicationFormState.ts @@ -0,0 +1,9 @@ +import { writable } from "svelte/store"; +import type { ApplicationFormState } from "../viewModels"; + +const applicationFormState = writable({ + application: null, + currentStep: 0, +}); + +export default applicationFormState; diff --git a/src/OAP/Oap.Theme.Svelte/src/lib/stores/applicationId.ts b/src/OAP/Oap.Theme.Svelte/src/lib/stores/applicationId.ts deleted file mode 100644 index 90b191f..0000000 --- a/src/OAP/Oap.Theme.Svelte/src/lib/stores/applicationId.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { writable } from 'svelte/store'; -const applicationId = writable(null); - -export default applicationId; \ No newline at end of file diff --git a/src/OAP/Oap.Theme.Svelte/src/lib/stores/step.ts b/src/OAP/Oap.Theme.Svelte/src/lib/stores/step.ts deleted file mode 100644 index 90663d1..0000000 --- a/src/OAP/Oap.Theme.Svelte/src/lib/stores/step.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { writable } from 'svelte/store'; -const step = writable(0); - -export default step; \ No newline at end of file diff --git a/src/OAP/Oap.Theme.Svelte/src/lib/viewModels.ts b/src/OAP/Oap.Theme.Svelte/src/lib/viewModels.ts new file mode 100644 index 0000000..a4d6494 --- /dev/null +++ b/src/OAP/Oap.Theme.Svelte/src/lib/viewModels.ts @@ -0,0 +1,6 @@ +import type { IApplication } from "./oap/oapApiV1ClientTypes"; + +export interface ApplicationFormState { + application: IApplication | null; + currentStep: number; +}