Edit.vue 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 AppDropdown from '@/components/AppDropdown.vue'
  7. import AppInputText from '@/components/AppInputText.vue'
  8. import AppDialog from '@/components/AppDialog.vue'
  9. import AppLayout from '@/layouts/AppLayout.vue'
  10. const props = defineProps({
  11. customer: Object,
  12. genders: Array,
  13. })
  14. const form = useForm({
  15. customer_number: props.customer.customer_number,
  16. name: props.customer.name,
  17. phone: props.customer.phone,
  18. gender_id: props.customer.gender_id,
  19. })
  20. const submit = () => {
  21. form.put(route('customers.update', props.customer.id))
  22. }
  23. const errors = computed(() => usePage().props.value.errors)
  24. watch(errors, () => {
  25. form.clearErrors()
  26. })
  27. const visibleDialog = ref(false)
  28. const confirmDialog = () => {
  29. visibleDialog.value = true
  30. }
  31. const onAgree = (id) => Inertia.delete(route('customers.destroy', id))
  32. const onCancel = () => (visibleDialog.value = false)
  33. </script>
  34. <template>
  35. <Head title="Ubah Customer" />
  36. <AppLayout>
  37. <div class="grid">
  38. <div class="col-12 lg:col-8">
  39. <Card>
  40. <template #content>
  41. <div class="grid">
  42. <div class="col-12 md:col-6">
  43. <AppInputText
  44. :disabled="true"
  45. label="Id Customer"
  46. v-model="form.customer_number"
  47. placeholder="id customer"
  48. />
  49. </div>
  50. <div class="col-12 md:col-6">
  51. <AppInputText label="Nama" placeholder="nama" :error="form.errors.name" v-model="form.name" />
  52. </div>
  53. <div class="col-12 md:col-6">
  54. <AppInputText label="Nomor HP" placeholder="nomor hp" :error="form.errors.phone" v-model="form.phone" />
  55. </div>
  56. <div class="col-12 md:col-6">
  57. <AppDropdown
  58. label="Jenis Kelamin"
  59. placeholder="Pilih satu"
  60. v-model="form.gender_id"
  61. :options="genders"
  62. :error="form.errors.gender_id"
  63. />
  64. </div>
  65. </div>
  66. </template>
  67. <template #footer>
  68. <div
  69. class="flex flex-column sm:flex-row align-items-center sm:justify-content-center sm:justify-content-between"
  70. >
  71. <AppDialog
  72. message="Yakin akan menghapus data ini?"
  73. v-model:visible="visibleDialog"
  74. @agree="onAgree(customer.id)"
  75. @cancel="onCancel"
  76. />
  77. <Button label="Hapus" icon="pi pi-trash" class="p-button-text p-button-danger" @click="confirmDialog" />
  78. <AppButton @click="submit" label="Simpan" icon="pi pi-check" class="p-button-text" />
  79. </div>
  80. </template>
  81. </Card>
  82. </div>
  83. </div>
  84. </AppLayout>
  85. </template>