Edit.vue 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <script setup>
  2. import { computed, watch, ref } from 'vue'
  3. import { Inertia } from '@inertiajs/inertia'
  4. import { Head, useForm, usePage } from '@inertiajs/inertia-vue3'
  5. import AppLayout from '@/layouts/AppLayout.vue'
  6. import AppDialog from '@/components/AppDialog.vue'
  7. import AppInputText from '@/components/AppInputText.vue'
  8. const props = defineProps({
  9. member: Object,
  10. })
  11. const errors = computed(() => usePage().props.value.errors)
  12. watch(errors, () => {
  13. form.clearErrors()
  14. })
  15. const visibleDialog = ref(false)
  16. const confirmDialog = () => {
  17. visibleDialog.value = true
  18. }
  19. const onAgree = () => Inertia.delete(route('members.destroy', props.member.id))
  20. const onCancel = () => (visibleDialog.value = false)
  21. const form = useForm({
  22. name: props.member.name,
  23. phone: props.member.phone,
  24. })
  25. const submit = () => {
  26. form.put(route('members.update', props.member.id))
  27. }
  28. </script>
  29. <template>
  30. <Head title="Ubah Member" />
  31. <AppLayout>
  32. <div class="grid">
  33. <div class="col-12 md:col-8">
  34. <Card>
  35. <template #title> Ubah Member </template>
  36. <template #content>
  37. <div class="grid">
  38. <div class="col-12 md:col-6">
  39. <AppInputText v-model="form.name" label="Nama" placeholder="nama" :error="form.errors.name" />
  40. </div>
  41. <div class="col-12 md:col-6">
  42. <AppInputText v-model="form.phone" label="Nomor HP" placeholder="nomor hp" :error="form.errors.phone" />
  43. </div>
  44. </div>
  45. </template>
  46. <template #footer>
  47. <div class="grid">
  48. <div class="col-12 md:col-6 flex flex-column md:flex-row justify-content-center md:justify-content-start">
  49. <AppDialog
  50. message="Yakin akan menghapus data ini?"
  51. v-model:visible="visibleDialog"
  52. @agree="onAgree"
  53. @cancel="onCancel"
  54. />
  55. <Button
  56. label="Hapus"
  57. icon="pi pi-trash"
  58. class="p-button-outlined p-button-danger"
  59. @click="confirmDialog"
  60. />
  61. </div>
  62. <div class="col-12 md:col-6 flex flex-column md:flex-row justify-content-center md:justify-content-end">
  63. <Button
  64. label="Simpan"
  65. icon="pi pi-check"
  66. class="p-button-outlined"
  67. :disabled="form.processing"
  68. @click="submit"
  69. />
  70. </div>
  71. </div>
  72. </template>
  73. </Card>
  74. </div>
  75. </div>
  76. </AppLayout>
  77. </template>