Edit.vue 4.1KB

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