Edit.vue 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { Inertia } from '@inertiajs/inertia'
  4. import { useForm, Head } from '@inertiajs/inertia-vue3'
  5. import AppInputText from '@/components/AppInputText.vue'
  6. import AppDropdown from '@/components/AppDropdown.vue'
  7. import AppButton from '@/components/AppButton.vue'
  8. import AppDialog from '@/components/AppDialog.vue'
  9. import AppLayout from '@/layouts/AppLayout.vue'
  10. const props = defineProps({
  11. user: Object,
  12. genders: Array,
  13. outlets: Array,
  14. roles: Array,
  15. })
  16. const form = useForm({
  17. name: props.user.name,
  18. phone: props.user.phone,
  19. email: props.user.email,
  20. address: props.user.address,
  21. gender_id: props.user.gender_id,
  22. outlet_id: props.user.outlet_id,
  23. role_id: props.user.role_id,
  24. })
  25. const submit = () => {
  26. form.put(route('users.update', props.user.id))
  27. }
  28. const visibleDialog = ref(false)
  29. const confirmDialog = () => {
  30. visibleDialog.value = true
  31. }
  32. const onAgree = (id) => Inertia.delete(route('users.destroy', id))
  33. const onCancel = () => (visibleDialog.value = false)
  34. </script>
  35. <template>
  36. <Head title="Ubah User" />
  37. <AppLayout>
  38. <div class="grid">
  39. <div class="col-12 lg:col-8">
  40. <Card>
  41. <template #content>
  42. <div class="grid">
  43. <div class="col-12 md:col-6">
  44. <AppInputText label="Nama" placeholder="nama" :error="form.errors.name" v-model="form.name" />
  45. </div>
  46. <div class="col-12 md:col-6">
  47. <AppInputText label="Nomor HP" placeholder="nomor hp" :error="form.errors.phone" v-model="form.phone" />
  48. </div>
  49. <div class="col-12 md:col-6">
  50. <AppInputText label="Email" placeholder="email" :error="form.errors.email" v-model="form.email" />
  51. </div>
  52. <div class="col-12 md:col-6">
  53. <AppInputText label="Alamat" placeholder="alamat" :error="form.errors.address" v-model="form.address" />
  54. </div>
  55. <div class="col-12 md:col-6">
  56. <AppDropdown
  57. label="Jenis Kelamin"
  58. placeholder="Pilih satu"
  59. v-model="form.gender_id"
  60. :options="genders"
  61. :error="form.errors.gender_id"
  62. />
  63. </div>
  64. <div class="col-12 md:col-6">
  65. <AppDropdown
  66. label="Hak Akses"
  67. placeholder="Pilih satu"
  68. v-model="form.role_id"
  69. :options="roles"
  70. :error="form.errors.role_id"
  71. />
  72. </div>
  73. <div class="col-12 md:col-6">
  74. <AppDropdown
  75. label="Outlet"
  76. placeholder="Pilih satu"
  77. v-model="form.outlet_id"
  78. :options="outlets"
  79. :error="form.errors.outlet_id"
  80. />
  81. </div>
  82. </div>
  83. </template>
  84. <template #footer>
  85. <div
  86. class="flex flex-column sm:flex-row align-items-center sm:justify-content-center sm:justify-content-between"
  87. >
  88. <AppDialog
  89. message="Yakin akan menghapus data ini?"
  90. v-model:visible="visibleDialog"
  91. @agree="onAgree(user.id)"
  92. @cancel="onCancel"
  93. />
  94. <Button label="Hapus" icon="pi pi-trash" class="p-button-text p-button-danger" @click="confirmDialog" />
  95. <div class="flex flex-column sm:flex-row align-items-center sm:justify-content-center">
  96. <AppButton
  97. label="Blokir"
  98. icon="pi pi-ban"
  99. :href="route('users.block', user.id)"
  100. method="delete"
  101. class="p-button-text p-button-danger md:mr-3"
  102. />
  103. <AppButton @click="submit" label="Simpan" icon="pi pi-check" />
  104. </div>
  105. </div>
  106. </template>
  107. </Card>
  108. </div>
  109. </div>
  110. </AppLayout>
  111. </template>