Edit.vue 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <script setup>
  2. import { ref, watch, computed } from 'vue'
  3. import { Inertia } from '@inertiajs/inertia'
  4. import { Head, useForm, usePage } from '@inertiajs/inertia-vue3'
  5. import AppButton from '@/components/AppButton.vue'
  6. import AppInputText from '@/components/AppInputText.vue'
  7. import AppInputNumber from '@/components/AppInputNumber.vue'
  8. import AppDialog from '@/components/AppDialog.vue'
  9. import AppLayout from '@/layouts/AppLayout.vue'
  10. const props = defineProps({
  11. laundry: Object,
  12. })
  13. const form = useForm({
  14. name: props.laundry.name,
  15. price: props.laundry.price,
  16. unit: props.laundry.unit,
  17. })
  18. const submit = () => {
  19. form.put(route('laundries.update', props.laundry.id))
  20. }
  21. const errors = computed(() => usePage().props.value.errors)
  22. watch(errors, () => {
  23. form.clearErrors()
  24. })
  25. const visibleDialog = ref(false)
  26. const confirmDialog = () => {
  27. visibleDialog.value = true
  28. }
  29. const onAgree = (id) => Inertia.delete(route('laundries.destroy', id))
  30. const onCancel = () => (visibleDialog.value = false)
  31. </script>
  32. <template>
  33. <Head title="Ubah tipe Laundry" />
  34. <AppLayout>
  35. <div class="grid">
  36. <div class="col-12 lg:col-8">
  37. <Card>
  38. <template #content>
  39. <div class="grid">
  40. <div class="col-12 md:col-6">
  41. <AppInputText label="Nama" placeholder="nama" :error="form.errors.name" v-model="form.name" />
  42. </div>
  43. <div class="col-12 md:col-6">
  44. <AppInputNumber label="Harga" placeholder="harga" :error="form.errors.price" v-model="form.price" />
  45. </div>
  46. <div class="col-12 md:col-6">
  47. <AppInputText label="Satuan" placeholder="satuan" :error="form.errors.unit" v-model="form.unit" />
  48. </div>
  49. </div>
  50. </template>
  51. <template #footer>
  52. <div
  53. class="flex flex-column sm:flex-row align-items-center sm:justify-content-center sm:justify-content-between"
  54. >
  55. <AppDialog
  56. message="Yakin akan menghapus data ini?"
  57. v-model:visible="visibleDialog"
  58. @agree="onAgree(laundry.id)"
  59. @cancel="onCancel"
  60. />
  61. <Button label="Hapus" icon="pi pi-trash" class="p-button-text p-button-danger" @click="confirmDialog" />
  62. <AppButton @click="submit" label="Simpan" icon="pi pi-check" class="p-button-text" />
  63. </div>
  64. </template>
  65. </Card>
  66. </div>
  67. </div>
  68. </AppLayout>
  69. </template>