123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <script setup>
  2. import { Inertia } from '@inertiajs/inertia'
  3. import { useForm, Head } from '@inertiajs/inertia-vue3'
  4. import { useFormErrorReset } from '@/components/useFormErrorReset'
  5. import { useConfirm } from 'primevue/useconfirm'
  6. import AppInputText from '@/components/AppInputText.vue'
  7. import DashboardLayout from '@/layouts/DashboardLayout.vue'
  8. const props = defineProps({
  9. customer: Object,
  10. })
  11. const form = useForm({
  12. name: props.customer.name,
  13. address: props.customer.address,
  14. phone: props.customer.phone,
  15. npwp: props.customer.npwp,
  16. })
  17. useFormErrorReset(form)
  18. const deleteConfirm = useConfirm()
  19. const onDelete = () => {
  20. deleteConfirm.require({
  21. message: `Yakin akan menghapus (${props.customer.name}) ?`,
  22. header: 'Hapus Pelanggan',
  23. acceptLabel: 'Hapus',
  24. rejectLabel: 'Batalkan',
  25. accept: () => {
  26. Inertia.delete(route('customers.destroy', props.customer.id))
  27. },
  28. reject: () => {
  29. deleteConfirm.close()
  30. },
  31. })
  32. }
  33. const onSubmit = () => {
  34. form.put(route('customers.update', props.customer.id))
  35. }
  36. </script>
  37. <template>
  38. <Head title="Ubah Pelanggan" />
  39. <DashboardLayout>
  40. <ConfirmDialog></ConfirmDialog>
  41. <div class="grid">
  42. <div class="col-12 lg:col-8">
  43. <Card>
  44. <template #title> Ubah Pelanggan </template>
  45. <template #content>
  46. <div class="grid">
  47. <div class="col-12 md:col-6">
  48. <AppInputText
  49. label="Nama"
  50. placeholder="nama"
  51. :error="form.errors.name"
  52. v-model="form.name"
  53. />
  54. </div>
  55. <div class="col-12 md:col-6">
  56. <AppInputText
  57. label="Alamat"
  58. placeholder="alamat"
  59. :error="form.errors.address"
  60. v-model="form.address"
  61. />
  62. </div>
  63. <div class="col-12 md:col-6">
  64. <AppInputText
  65. label="No HP"
  66. placeholder="no hp"
  67. type="number"
  68. :error="form.errors.phone"
  69. v-model="form.phone"
  70. />
  71. </div>
  72. <div class="col-12 md:col-6">
  73. <AppInputText
  74. label="NPWP"
  75. placeholder="npwp"
  76. type="number"
  77. :error="form.errors.npwp"
  78. v-model="form.npwp"
  79. />
  80. </div>
  81. </div>
  82. </template>
  83. <template #footer>
  84. <div class="grid">
  85. <div
  86. class="col-12 md:col-6 flex flex-column md:flex-row justify-content-center md:justify-content-start"
  87. >
  88. <Button
  89. label="Hapus"
  90. icon="pi pi-trash"
  91. class="p-button-outlined p-button-danger"
  92. @click="onDelete"
  93. />
  94. </div>
  95. <div
  96. class="col-12 md:col-6 flex flex-column md:flex-row justify-content-center md:justify-content-end"
  97. >
  98. <Button
  99. label="Simpan"
  100. icon="pi pi-check"
  101. class="p-button-outlined"
  102. :disabled="form.processing"
  103. @click="onSubmit"
  104. />
  105. </div>
  106. </div>
  107. </template>
  108. </Card>
  109. </div>
  110. </div>
  111. </DashboardLayout>
  112. </template>