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'} - send('NEXT')}> - Next - - {:else if $state.value === 'name'} - - - {#if $errors.name} - {$errors.name} - {:else} - {$state.value in stateMachine.states - ? stateMachine.states[$state.value].meta.fieldLabel - : ''} - {/if} - - - - send('NEXT')} - > - Next - - - {:else if $state.value === 'email'} - - - {#if $errors.email} - {$errors.email} - {:else} - {$state.value in stateMachine.states - ? stateMachine.states[$state.value].meta.fieldLabel - : ''} - {/if} - - - - send('NEXT')} - > - Next - - - {:else if $state.value === 'summary'} - Name: {$form.name} - Email: {$form.email} - { - console.log('Submit button clicked'); - send('SUBMIT'); - }} - > - Submit - - {:else if $state.value === 'submitting'} - - {:else if $state.value === 'success'} - Thank you for your submission! - send('RESTART')}> - Start Again - - {:else if $state.value === 'failure'} - - Error: {$state.context.error?.message || 'An unknown error occurred.'} - - send('RESTART')}> - Try Again - - {/if} - - - -
- {$state.value in stateMachine.states ? stateMachine.states[$state.value].meta.description : ''} -
Name: {$form.name}
Email: {$form.email}
Thank you for your submission!
- Error: {$state.context.error?.message || 'An unknown error occurred.'} -
{$state.value in stateMachine.states - ? stateMachine.states[$state.value].meta.buttonLabel + ? stateMachine.states[$state.value].meta.description : ''} - - {/if} -
+ Error: {$state.context.error?.message || 'An unknown error occurred.'} +