Show.vue 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <script setup>
  2. import { computed, watch } from 'vue'
  3. import { Head, useForm, usePage } from '@inertiajs/inertia-vue3'
  4. import AppLayout from '@/layouts/AppLayout.vue'
  5. import AppInputText from '@/components/AppInputText.vue'
  6. import AppDropdown from '@/components/AppDropdown.vue'
  7. import AppPassword from '@/components/AppPassword.vue'
  8. const props = defineProps({
  9. user: Object,
  10. roles: Array,
  11. outlets: Array,
  12. genders: Array,
  13. })
  14. const errors = computed(() => usePage().props.value.errors)
  15. watch(errors, () => {
  16. form.clearErrors()
  17. formChangePassword.clearErrors()
  18. })
  19. const form = useForm({
  20. name: props.user.name,
  21. phone: props.user.phone,
  22. email: props.user.email,
  23. gender_id: props.user.gender_id,
  24. outlet_id: props.user.outlet_id,
  25. role_id: props.user.role_id,
  26. })
  27. const submit = () => {
  28. form.put(route('users.update', props.user.id))
  29. }
  30. const formChangePassword = useForm({
  31. old_password: '',
  32. new_password: '',
  33. new_password_confirmation: '',
  34. })
  35. const changePassword = () => {
  36. formChangePassword.post(route('users.change-password', props.user.id), {
  37. onSuccess: () => formChangePassword.reset(),
  38. })
  39. }
  40. </script>
  41. <template>
  42. <Head title="Profil Saya" />
  43. <AppLayout>
  44. <div class="grid">
  45. <div class="col-12 md:col-8">
  46. <Card>
  47. <template #title>Profil Saya</template>
  48. <template #content>
  49. <TabView lazy>
  50. <TabPanel header="Ubah Profil">
  51. <div class="grid">
  52. <div class="col-12 md:col-6">
  53. <AppInputText label="Nama" placeholder="nama" :error="form.errors.name" v-model="form.name" />
  54. </div>
  55. <div class="col-12 md:col-6">
  56. <AppInputText
  57. label="Nomor HP"
  58. placeholder="nomor hp"
  59. :error="form.errors.phone"
  60. v-model="form.phone"
  61. />
  62. </div>
  63. <div class="col-12 md:col-6">
  64. <AppInputText label="Email" placeholder="email" :error="form.errors.email" v-model="form.email" />
  65. </div>
  66. <div class="col-12 md:col-6">
  67. <AppDropdown
  68. label="Jenis Kelamin"
  69. placeholder="pilih satu"
  70. v-model="form.gender_id"
  71. :options="genders"
  72. :error="form.errors.gender_id"
  73. />
  74. </div>
  75. <div class="col-12 flex justify-content-end">
  76. <Button
  77. label="Simpan"
  78. icon="pi pi-check"
  79. class="p-button-outlined"
  80. :disabled="form.processing"
  81. @click="submit"
  82. />
  83. </div>
  84. </div>
  85. </TabPanel>
  86. <TabPanel header="Ubah Password">
  87. <div class="grid">
  88. <div class="col-12">
  89. <AppPassword
  90. label="Password Lama"
  91. placeholder="password lama"
  92. :error="formChangePassword.errors.old_password"
  93. v-model="formChangePassword.old_password"
  94. />
  95. </div>
  96. <div class="col-12">
  97. <AppPassword
  98. label="Password Baru"
  99. placeholder="password baru"
  100. :error="formChangePassword.errors.new_password"
  101. v-model="formChangePassword.new_password"
  102. />
  103. </div>
  104. <div class="col-12">
  105. <AppPassword
  106. label="Konfirmasi Password"
  107. placeholder="konfirmasi password"
  108. v-model="formChangePassword.new_password_confirmation"
  109. />
  110. </div>
  111. <div class="col-12 flex justify-content-end">
  112. <Button
  113. label="Simpan"
  114. icon="pi pi-check"
  115. class="p-button-outlined"
  116. :disabled="formChangePassword.processing"
  117. @click="changePassword"
  118. />
  119. </div>
  120. </div>
  121. </TabPanel>
  122. </TabView>
  123. </template>
  124. </Card>
  125. </div>
  126. </div>
  127. </AppLayout>
  128. </template>