194 lines
6.3 KiB
Vue
194 lines
6.3 KiB
Vue
<script setup lang="ts">
|
|
import { useForm } from '@inertiajs/vue3';
|
|
import { route } from 'ziggy-js';
|
|
|
|
const props = defineProps<{
|
|
dynamicId: number;
|
|
ledgerId: number;
|
|
}>();
|
|
|
|
const form = useForm({
|
|
amount: 0,
|
|
description: '',
|
|
media: [] as File[],
|
|
});
|
|
|
|
function handleMutationFileChange(event: Event) {
|
|
const files = (event.target as HTMLInputElement).files;
|
|
|
|
if (files) {
|
|
for (let i = 0; i < files.length; i++) {
|
|
form.media.push(files[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
function removeMutationFile(index: number) {
|
|
form.media.splice(index, 1);
|
|
}
|
|
|
|
function submit() {
|
|
form.post(
|
|
route('dynamics.ledgers.mutations.store', {
|
|
dynamic: props.dynamicId,
|
|
ledger: props.ledgerId,
|
|
}),
|
|
{
|
|
onSuccess: () => form.reset(),
|
|
},
|
|
);
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="c-add-mutation-form">
|
|
<h4 class="c-add-mutation-form__title">Add Mutation</h4>
|
|
<form @submit.prevent="submit" class="c-add-mutation-form__form">
|
|
<div class="c-add-mutation-form__field">
|
|
<label for="amount" class="c-add-mutation-form__label"
|
|
>Amount</label
|
|
>
|
|
<input
|
|
v-model="form.amount"
|
|
id="amount"
|
|
type="number"
|
|
class="c-add-mutation-form__input"
|
|
/>
|
|
<div
|
|
v-if="form.errors.amount"
|
|
class="c-add-mutation-form__error"
|
|
>
|
|
{{ form.errors.amount }}
|
|
</div>
|
|
</div>
|
|
|
|
<div class="c-add-mutation-form__field">
|
|
<label for="description" class="c-add-mutation-form__label"
|
|
>Description</label
|
|
>
|
|
<textarea
|
|
v-model="form.description"
|
|
id="description"
|
|
rows="4"
|
|
class="c-add-mutation-form__textarea"
|
|
></textarea>
|
|
<div
|
|
v-if="form.errors.description"
|
|
class="c-add-mutation-form__error"
|
|
>
|
|
{{ form.errors.description }}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Media Uploads for Mutations -->
|
|
<div class="c-add-mutation-form__field">
|
|
<label class="c-add-mutation-form__label"
|
|
>Attach Proof Media (Photos/Videos)</label
|
|
>
|
|
<input
|
|
type="file"
|
|
multiple
|
|
accept="image/*,video/*"
|
|
@change="handleMutationFileChange"
|
|
class="c-add-mutation-form__file-input"
|
|
/>
|
|
<div
|
|
v-if="form.media.length > 0"
|
|
class="c-add-mutation-form__media-preview-list"
|
|
>
|
|
<div
|
|
v-for="(file, index) in form.media"
|
|
:key="index"
|
|
class="c-add-mutation-form__media-preview-item"
|
|
>
|
|
<span class="c-add-mutation-form__media-preview-name">{{
|
|
file.name
|
|
}}</span>
|
|
<button
|
|
type="button"
|
|
@click="removeMutationFile(index)"
|
|
class="c-add-mutation-form__media-preview-remove"
|
|
>
|
|
✕
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="c-add-mutation-form__actions">
|
|
<button
|
|
type="submit"
|
|
:disabled="form.processing"
|
|
class="c-add-mutation-form__submit-btn"
|
|
>
|
|
Add Mutation
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
@reference "../../css/app.css";
|
|
|
|
.c-add-mutation-form {
|
|
@apply mt-8;
|
|
}
|
|
|
|
.c-add-mutation-form__title {
|
|
@apply text-lg font-medium text-gray-900 dark:text-gray-100;
|
|
}
|
|
|
|
.c-add-mutation-form__form {
|
|
@apply mt-6 space-y-6 overflow-hidden bg-white p-6 shadow-sm sm:rounded-lg dark:bg-gray-800;
|
|
}
|
|
|
|
.c-add-mutation-form__field {
|
|
@apply block;
|
|
}
|
|
|
|
.c-add-mutation-form__label {
|
|
@apply block text-sm font-medium text-gray-700 dark:text-gray-300;
|
|
}
|
|
|
|
.c-add-mutation-form__input {
|
|
@apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
|
}
|
|
|
|
.c-add-mutation-form__textarea {
|
|
@apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
|
|
}
|
|
|
|
.c-add-mutation-form__file-input {
|
|
@apply mt-1 block w-full text-sm text-neutral-500 file:mr-4 file:rounded-md file:border-0 file:bg-indigo-50 file:px-4 file:py-2 file:text-xs file:font-semibold file:text-indigo-700 hover:file:bg-indigo-100;
|
|
}
|
|
|
|
.c-add-mutation-form__media-preview-list {
|
|
@apply mt-2 flex flex-wrap gap-2;
|
|
}
|
|
|
|
.c-add-mutation-form__media-preview-item {
|
|
@apply relative inline-flex items-center gap-2 rounded border border-neutral-200 bg-neutral-100 p-1.5 pr-8 text-xs dark:border-neutral-700 dark:bg-neutral-800;
|
|
}
|
|
|
|
.c-add-mutation-form__media-preview-name {
|
|
@apply max-w-[150px] truncate;
|
|
}
|
|
|
|
.c-add-mutation-form__media-preview-remove {
|
|
@apply absolute top-1.5 right-1.5 cursor-pointer text-[10px] text-neutral-400 hover:text-red-500;
|
|
}
|
|
|
|
.c-add-mutation-form__error {
|
|
@apply text-sm text-red-600;
|
|
}
|
|
|
|
.c-add-mutation-form__actions {
|
|
@apply flex items-center gap-4;
|
|
}
|
|
|
|
.c-add-mutation-form__submit-btn {
|
|
@apply inline-flex items-center rounded-md border border-transparent bg-gray-800 px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase transition duration-150 ease-in-out hover:bg-gray-700 focus:bg-gray-700 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none active:bg-gray-900 dark:bg-gray-200 dark:text-gray-800 dark:hover:bg-white dark:focus:bg-white dark:focus:ring-offset-gray-800 dark:active:bg-gray-300;
|
|
}
|
|
</style>
|