diff --git a/src/lib/components/examples/Recipies.svelte b/src/lib/components/examples/Recipies.svelte index 0f49c14..b5f6df2 100644 --- a/src/lib/components/examples/Recipies.svelte +++ b/src/lib/components/examples/Recipies.svelte @@ -5,6 +5,7 @@ import { TreeSchema } from '$lib/types/TreeSchema'; import { writable, get } from 'svelte/store'; import { createUser } from './userService'; + import { derived } from 'svelte/store'; const initialFormData = { name: '', age: '' }; @@ -150,127 +151,123 @@ const { state, send } = useMachine(stateMachine); $: { - // Reactively update the form validation status based on the errors isFormValid.set(Object.keys(get(errors)).length === 0); } + + const possibleActions = derived(state, ($state) => + Object.keys(stateMachine.states[$state.value]?.on || {}) + ); -
-

- {$state.value in stateMachine.states && stateMachine.states[$state.value].meta - ? stateMachine.states[$state.value].meta.title - : 'Unknown state'} -

-

- {$state.value in stateMachine.states ? stateMachine.states[$state.value].meta.description : ''} -

- - {#if $state.value === 'start'} - - {:else if $state.value === 'name'} -
-
- {#if $errors.name} - {$errors.name} - {:else} - - {/if} - - -
- -
- {:else if $state.value === 'email'} -
-
- {#if $errors.email} - {$errors.email} - {:else} - - {/if} - - -
- -
- {:else if $state.value === 'summary'} -

Name: {$form.name}

-

Email: {$form.email}

- - {:else if $state.value === 'submitting'} - - {:else if $state.value === 'success'} -

Thank you for your submission!

- - {:else if $state.value === 'failure'} -

- Error: {$state.context.error?.message || 'An unknown error occurred.'} -

- - {/if} -
- - -
- {#if $state.value in stateMachine.states && stateMachine.states[$state.value].on.NEXT} - - {/if} -
+

+ + {#if $state.value === 'start'}Welcome{:else if $state.value === 'name'} +
+
+ {#if $errors.name} + {$errors.name} + {:else} + + {/if} + + +
+
+ {:else if $state.value === 'email'} +
+
+ {#if $errors.email} + {$errors.email} + {:else} + + {/if} + + +
+
+ {:else if $state.value === 'summary'} +

Name: {$form.name}

+

Email: {$form.email}

+ {:else if $state.value === 'submitting'} + Add spinner here + {:else if $state.value === 'success'} +

Thank you for your submission!

+ {:else if $state.value === 'failure'} +

+ Error: {$state.context.error?.message || 'An unknown error occurred.'} +

+ {/if} + {#if possibleActions} +
+ {#each $possibleActions as action (action)} + {#if action === 'BACK'} + + {/if} + {/each} + + {#each $possibleActions as action (action)} + {#if action !== 'NEXT' && action !== 'BACK'} + + {/if} + {/each} + + {#each $possibleActions as action (action)} + {#if action === 'NEXT'} + + {/if} + {/each} +
+ {/if} + +