Show.vue 3.8KB

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