|
| 1 | +<script lang="ts"> |
| 2 | + import { modalStore } from '@skeletonlabs/skeleton' |
| 3 | + import { useForm } from '@inertiajs/svelte' |
| 4 | + import type { SystemConfiguration } from '@/types' |
| 5 | + import { snakeCaseToSentenceCaseCapitalizeWords } from '@/helpers' |
| 6 | + import {} from 'os' |
| 7 | + import Button from '@/Components/Button.svelte' |
| 8 | +
|
| 9 | + // Base Classes |
| 10 | + const cBase = 'card p-4 w-modal shadow-xl space-y-4' |
| 11 | + const cHeader = 'text-2xl font-bold' |
| 12 | + const cForm = 'border border-surface-500 p-4 space-y-4 rounded-container-token' |
| 13 | +
|
| 14 | + // Props |
| 15 | + /** Exposes parent props to this component. */ |
| 16 | + export let parent: any |
| 17 | + export let configuration: SystemConfiguration |
| 18 | + export let title: string |
| 19 | +
|
| 20 | + // Form Data |
| 21 | + let form = useForm({ |
| 22 | + name: configuration.name, |
| 23 | + id: configuration.id, |
| 24 | + value: configuration.value, |
| 25 | + }) |
| 26 | +
|
| 27 | + function handleSubmit(): void { |
| 28 | + $form.post(route('admin.settings.configurations'), { |
| 29 | + onSuccess: () => { |
| 30 | + modalStore.close() |
| 31 | + }, |
| 32 | + }) |
| 33 | + } |
| 34 | +</script> |
| 35 | + |
| 36 | +<div class={cBase}> |
| 37 | + <header class={cHeader}>{title}</header> |
| 38 | + |
| 39 | + <form on:submit|preventDefault={handleSubmit}> |
| 40 | + <div class="modal-form {cForm}" on:submit|preventDefault={handleSubmit}> |
| 41 | + <label class="label"> |
| 42 | + <span>Name</span> |
| 43 | + <input |
| 44 | + class="input" |
| 45 | + type="text" |
| 46 | + required |
| 47 | + value={snakeCaseToSentenceCaseCapitalizeWords(configuration.name)} |
| 48 | + disabled |
| 49 | + placeholder="Name" |
| 50 | + /> |
| 51 | + </label> |
| 52 | + {#if configuration.type == 'bool'} |
| 53 | + <label class="flex items-center space-x-2"> |
| 54 | + <p>Value</p> |
| 55 | + <input class="checkbox" type="checkbox" bind:checked={$form.value} /> |
| 56 | + </label> |
| 57 | + {:else if configuration.type == 'number'} |
| 58 | + <label class="label"> |
| 59 | + <span>Value</span> |
| 60 | + <input class="input" type="number" required bind:value={$form.value} placeholder="Value" /> |
| 61 | + </label> |
| 62 | + {:else} |
| 63 | + <label class="label"> |
| 64 | + <span>Value</span> |
| 65 | + <input class="input" type="text" required bind:value={$form.value} placeholder="Value" /> |
| 66 | + </label> |
| 67 | + {/if} |
| 68 | + </div> |
| 69 | + |
| 70 | + <footer class="modal-footer {parent.regionFooter}"> |
| 71 | + <Button color="ghost" type="button" on:click={parent.onClose}>{parent.buttonTextCancel}</Button> |
| 72 | + <Button type="submit" loading={$form.processing}>Submit</Button> |
| 73 | + </footer> |
| 74 | + </form> |
| 75 | +</div> |
0 commit comments