Edit.vue 3.3KB

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