Index.vue 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <script setup>
  2. import { Inertia } from '@inertiajs/inertia'
  3. import { useConfirm } from 'primevue/useconfirm'
  4. import { indexTable } from './config'
  5. import AppSearch from '@/components/AppSearch.vue'
  6. import AppButtonLink from '@/components/AppButtonLink.vue'
  7. import AppPagination from '@/components/AppPagination.vue'
  8. import DashboardLayout from '@/layouts/Dashboard/DashboardLayout.vue'
  9. defineProps({
  10. users: Object,
  11. initialSearch: String,
  12. })
  13. const resetConfirm = useConfirm()
  14. const onResetPassword = (data) => {
  15. resetConfirm.require({
  16. message: `Yakin mereset kata sandi (${data.name}) ?`,
  17. header: 'Reset Kata Sandi',
  18. acceptLabel: 'Iya',
  19. rejectLabel: 'Tidak',
  20. accept: () => {
  21. Inertia.put(route('users.reset-password', data.id))
  22. },
  23. reject: () => {
  24. resetConfirm.close()
  25. },
  26. })
  27. }
  28. const deleteConfirm = useConfirm()
  29. const onDelete = (data) => {
  30. deleteConfirm.require({
  31. message: `Yakin akan menghapus data (${data.name}) ?`,
  32. header: 'Hapus User',
  33. acceptLabel: 'Iya',
  34. rejectLabel: 'Tidak',
  35. accept: () => {
  36. Inertia.delete(route('users.destroy', data.id))
  37. },
  38. reject: () => {
  39. deleteConfirm.close()
  40. },
  41. })
  42. }
  43. </script>
  44. <template>
  45. <DashboardLayout title="Daftar User">
  46. <ConfirmDialog />
  47. <DataTable
  48. responsiveLayout="scroll"
  49. columnResizeMode="expand"
  50. :value="users.data"
  51. :rowHover="true"
  52. :stripedRows="true"
  53. >
  54. <template #header>
  55. <h1>User</h1>
  56. <div class="grid">
  57. <div class="col-12 md:col-8">
  58. <div class="flex align-items-center">
  59. <AppSearch
  60. class="w-full md:w-27rem"
  61. placeholder="nama, nama pengguna"
  62. url="/users"
  63. :initialSearch="initialSearch"
  64. />
  65. </div>
  66. </div>
  67. <div
  68. class="col-12 md:col-4 flex flex-column md:flex-row justify-content-end"
  69. >
  70. <AppButtonLink
  71. label="Tambah User"
  72. icon="pi pi-pencil"
  73. class="p-button-outlined"
  74. :href="route('users.create')"
  75. />
  76. </div>
  77. </div>
  78. </template>
  79. <Column
  80. v-for="value in indexTable"
  81. :field="value.field"
  82. :header="value.header"
  83. :key="value.field"
  84. />
  85. <Column>
  86. <template #body="{ data }">
  87. <AppButtonLink
  88. icon="pi pi-pencil"
  89. class="p-button-icon-only p-button-rounded p-button-text"
  90. v-tooltip.bottom="'Ubah User'"
  91. :href="route('users.edit', data.id)"
  92. />
  93. <Button
  94. v-if="data.role_id !== 1"
  95. icon="pi pi-key"
  96. class="p-button-icon-only p-button-rounded p-button-text"
  97. v-tooltip.bottom="'Reset Kata Sandi'"
  98. @click="onResetPassword(data)"
  99. />
  100. <Button
  101. v-if="data.role_id !== 1"
  102. icon="pi pi-trash"
  103. class="p-button-icon-only p-button-rounded p-button-text"
  104. v-tooltip.bottom="'Hapus User'"
  105. @click="onDelete(data)"
  106. />
  107. </template>
  108. </Column>
  109. </DataTable>
  110. <AppPagination :links="users.links" />
  111. </DashboardLayout>
  112. </template>