1818
1919 <div class =" mx-auto max-w-7xl sm:px-6 lg:px-8" >
2020 <div class =" overflow-hidden bg-white shadow-xl sm:rounded-lg" >
21+
22+ <a href =" #" @click =" deleteSelectedUsers"
23+ class =" float-left px-4 mt-3 py-2 text-red-400 duration-100 rounded hover:text-red-600" >
24+ <svg xmlns =" http://www.w3.org/2000/svg" viewBox =" 0 0 24 24" class =" h-6 w-6" >
25+ <path stroke-linecap =" round" stroke-linejoin =" round" stroke-width =" 2" stroke =" currentColor"
26+ fill =" none"
27+ d =" M3 6h18M6 6l1 12a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-12M9 4v-1a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v1" />
28+ </svg >
29+ </a >
30+
2131 <div class =" flex justify-end mt-3" >
2232 <div class =" mb-3 xl:w-96" >
2333 <div class =" relative flex items-stretch w-4/5 mb-3 input-group" >
3949 </div >
4050 </div >
4151 </div >
52+
4253 <table class =" min-w-full divide-y divide-gray-200" >
4354 <thead class =" bg-gray-50" >
4455 <tr >
56+ <th scope =" col" ></th >
57+ <th scope =" col"
58+ class =" px-6 py-3 text-xs font-medium tracking-wider text-center text-gray-500 uppercase" >
59+ ID
60+ </th >
4561 <th scope =" col"
4662 class =" px-6 py-3 text-xs font-medium tracking-wider text-center text-gray-500 uppercase" >
4763 Name
6581 </thead >
6682 <tbody class =" bg-white divide-y divide-gray-200" >
6783 <tr v-for =" user in users.data" :key =" user.id" >
84+ <td >
85+ <input type =" checkbox" v-model =" selectedUsers" :value =" user.id"
86+ class =" ml-5 outline-none" />
87+ </td >
88+ <td class =" px-6 py-4 whitespace-nowrap" >
89+ <div class =" text-sm text-center text-gray-900" >
90+ {{ user.id }}
91+ </div >
92+ </td >
6893 <td class =" px-6 py-4 whitespace-nowrap" >
6994 <div class =" flex items-center justify-center" >
95+
7096 <div class =" ml-4" >
7197 <div class =" text-sm font-medium text-gray-900" >
7298 <inertia-link class =" transition hover:text-blue-500"
109135 d =" M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
110136 </svg >
111137 </a >
138+
112139 </td >
113140 </tr >
114141 </tbody >
@@ -133,6 +160,7 @@ export default {
133160 },
134161 data () {
135162 return {
163+ selectedUsers: [],
136164 term: this .$page .term || ' ' ,
137165 }
138166 },
@@ -150,6 +178,24 @@ export default {
150178 search () {
151179 this .$inertia .replace (this .route (' users.index' , { term: this .term }))
152180 },
181+ async deleteSelectedUsers () {
182+ if (this .selectedUsers .length === 0 ) {
183+ return ;
184+ }
185+
186+ const confirmed = confirm (` Are you sure you want to delete ${ this .selectedUsers .length } user(s)?` );
187+ if (! confirmed) {
188+ return ;
189+ }
190+
191+ try {
192+ await this .$inertia .post (' /users/delete' , { ids: this .selectedUsers });
193+ this .selectedUsers = [];
194+ } catch (error) {
195+ console .error (error);
196+ alert (' An error occurred while deleting the selected users.' );
197+ }
198+ },
153199 }
154200}
155201 </script >
0 commit comments