Index.vue 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <script setup>
  2. import { Inertia } from '@inertiajs/inertia'
  3. import { useConfirm } from 'primevue/useconfirm'
  4. import { indexTable } from './config'
  5. import AppSearchFilter from '@/components/AppSearchFilter.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. initialFilters: Object,
  11. users: Object,
  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. <DataTable
  47. responsiveLayout="scroll"
  48. :value="users.data"
  49. :rowHover="true"
  50. :stripedRows="true"
  51. >
  52. <template #header>
  53. <h1>User</h1>
  54. <div class="grid">
  55. <div class="col-12 md:col-8">
  56. <AppSearchFilter
  57. placeholder="nama, nama pengguna"
  58. name-param="search"
  59. :initialSearch="initialFilters"
  60. />
  61. </div>
  62. <div
  63. class="col-12 md:col-4 flex flex-column md:flex-row justify-content-end"
  64. >
  65. <AppButtonLink
  66. label="Tambah User"
  67. icon="pi pi-pencil"
  68. class="p-button-outlined"
  69. :href="route('users.create')"
  70. />
  71. </div>
  72. </div>
  73. </template>
  74. <Column
  75. v-for="value in indexTable"
  76. :field="value.field"
  77. :header="value.header"
  78. :key="value.field"
  79. />
  80. <Column>
  81. <template #body="{ data }">
  82. <AppButtonLink
  83. icon="pi pi-pencil"
  84. class="p-button-icon-only p-button-rounded p-button-text"
  85. v-tooltip.bottom="'Ubah User'"
  86. :href="route('users.edit', data.id)"
  87. />
  88. <Button
  89. v-if="data.role_id !== 1"
  90. icon="pi pi-key"
  91. class="p-button-icon-only p-button-rounded p-button-text"
  92. v-tooltip.bottom="'Reset Kata Sandi'"
  93. @click="onResetPassword(data)"
  94. />
  95. <Button
  96. v-if="data.role_id !== 1"
  97. icon="pi pi-trash"
  98. class="p-button-icon-only p-button-rounded p-button-text"
  99. v-tooltip.bottom="'Hapus User'"
  100. @click="onDelete(data)"
  101. />
  102. </template>
  103. </Column>
  104. </DataTable>
  105. <AppPagination :links="users.links" />
  106. </DashboardLayout>
  107. </template>