| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <v-container fluid> | 
					
						
							| 
									
										
										
										
											2023-01-07 11:30:45 -08:00
										 |  |  |     <BaseDialog | 
					
						
							|  |  |  |       v-model="deleteDialog" | 
					
						
							|  |  |  |       :title="$tc('general.confirm')" | 
					
						
							|  |  |  |       color="error" | 
					
						
							|  |  |  |       @confirm="deleteUser(deleteTargetId)" | 
					
						
							|  |  |  |     > | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |       <template #activator> </template> | 
					
						
							| 
									
										
										
										
											2022-12-01 06:26:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-07 11:30:45 -08:00
										 |  |  |       <v-card-text> | 
					
						
							|  |  |  |         <v-alert v-if="isUserOwnAccount" type="warning" text outlined> | 
					
						
							|  |  |  |           {{ $t("general.confirm-delete-own-admin-account") }} | 
					
						
							| 
									
										
										
										
											2022-12-01 06:26:50 +01:00
										 |  |  |         </v-alert> | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |         {{ $t("general.confirm-delete-generic") }} | 
					
						
							|  |  |  |       </v-card-text> | 
					
						
							|  |  |  |     </BaseDialog> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-21 20:45:27 +01:00
										 |  |  |     <BaseCardSectionTitle :title="$tc('user.user-management')"> </BaseCardSectionTitle> | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |     <section> | 
					
						
							|  |  |  |       <v-toolbar color="background" flat class="justify-between"> | 
					
						
							| 
									
										
										
										
											2022-08-13 13:18:12 -08:00
										 |  |  |         <BaseButton to="/admin/manage/users/create" class="mr-2"> | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |           {{ $t("general.create") }} | 
					
						
							|  |  |  |         </BaseButton> | 
					
						
							| 
									
										
										
										
											2022-08-13 13:18:12 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-21 20:45:27 +01:00
										 |  |  |         <BaseOverflowButton mode="event" :items="ACTIONS_OPTIONS" @unlock-all-users="unlockAllUsers"> | 
					
						
							| 
									
										
										
										
											2022-08-13 13:18:12 -08:00
										 |  |  |         </BaseOverflowButton> | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |       </v-toolbar> | 
					
						
							|  |  |  |       <v-data-table | 
					
						
							|  |  |  |         :headers="headers" | 
					
						
							|  |  |  |         :items="users || []" | 
					
						
							|  |  |  |         item-key="id" | 
					
						
							|  |  |  |         class="elevation-0" | 
					
						
							|  |  |  |         elevation="0" | 
					
						
							|  |  |  |         hide-default-footer | 
					
						
							|  |  |  |         disable-pagination | 
					
						
							|  |  |  |         :search="search" | 
					
						
							|  |  |  |         @click:row="handleRowClick" | 
					
						
							|  |  |  |       > | 
					
						
							|  |  |  |         <template #item.admin="{ item }"> | 
					
						
							|  |  |  |           <v-icon right :color="item.admin ? 'success' : null"> | 
					
						
							|  |  |  |             {{ item.admin ? $globals.icons.checkboxMarkedCircle : $globals.icons.windowClose }} | 
					
						
							|  |  |  |           </v-icon> | 
					
						
							|  |  |  |         </template> | 
					
						
							|  |  |  |         <template #item.actions="{ item }"> | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |           <v-btn | 
					
						
							|  |  |  |             icon | 
					
						
							|  |  |  |             :disabled="item.id == 1" | 
					
						
							|  |  |  |             color="error" | 
					
						
							|  |  |  |             @click.stop=" | 
					
						
							|  |  |  |               deleteDialog = true; | 
					
						
							| 
									
										
										
										
											2023-01-07 11:30:45 -08:00
										 |  |  |               deleteTargetId = item.id; | 
					
						
							|  |  |  |             " | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |           > | 
					
						
							|  |  |  |             <v-icon> | 
					
						
							|  |  |  |               {{ $globals.icons.delete }} | 
					
						
							|  |  |  |             </v-icon> | 
					
						
							|  |  |  |           </v-btn> | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |         </template> | 
					
						
							|  |  |  |       </v-data-table> | 
					
						
							|  |  |  |       <v-divider></v-divider> | 
					
						
							|  |  |  |     </section> | 
					
						
							|  |  |  |   </v-container> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2022-12-01 06:26:50 +01:00
										 |  |  | import { defineComponent, reactive, ref, toRefs, useContext, useRouter, computed } from "@nuxtjs/composition-api"; | 
					
						
							| 
									
										
										
										
											2022-08-13 13:18:12 -08:00
										 |  |  | import { useAdminApi } from "~/composables/api"; | 
					
						
							|  |  |  | import { alert } from "~/composables/use-toast"; | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  | import { useUser, useAllUsers } from "~/composables/use-user"; | 
					
						
							| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  | import { UserOut } from "~/lib/api/types/user"; | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							|  |  |  |   layout: "admin", | 
					
						
							|  |  |  |   setup() { | 
					
						
							| 
									
										
										
										
											2022-08-13 13:18:12 -08:00
										 |  |  |     const api = useAdminApi(); | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |     const refUserDialog = ref(); | 
					
						
							| 
									
										
										
										
											2022-12-01 06:26:50 +01:00
										 |  |  |     const { $auth } = useContext(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-05 19:07:02 -06:00
										 |  |  |     const user = computed(() => $auth.user); | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-21 20:45:27 +01:00
										 |  |  |     const { $globals, i18n } = useContext(); | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const router = useRouter(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-07 11:30:45 -08:00
										 |  |  |     const isUserOwnAccount = computed(() => { | 
					
						
							|  |  |  |       return state.deleteTargetId === user.value?.id; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-21 20:45:27 +01:00
										 |  |  |     const ACTIONS_OPTIONS = [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         text: i18n.t("user.reset-locked-users"), | 
					
						
							|  |  |  |         icon: $globals.icons.lock, | 
					
						
							|  |  |  |         event: "unlock-all-users", | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |     const state = reactive({ | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |       deleteDialog: false, | 
					
						
							| 
									
										
										
										
											2023-01-07 11:30:45 -08:00
										 |  |  |       deleteTargetId: "", | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |       search: "", | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const { users, refreshAllUsers } = useAllUsers(); | 
					
						
							| 
									
										
										
										
											2023-01-07 11:30:45 -08:00
										 |  |  |     const { loading, deleteUser: deleteUserMixin } = useUser(refreshAllUsers); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function deleteUser(id: string) { | 
					
						
							|  |  |  |       deleteUserMixin(id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (isUserOwnAccount.value) { | 
					
						
							|  |  |  |         $auth.logout(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function handleRowClick(item: UserOut) { | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  |       router.push(`/admin/manage/users/${item.id}`); | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // ==========================================================
 | 
					
						
							|  |  |  |     // Constants / Non-reactive
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const headers = [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         text: i18n.t("user.user-id"), | 
					
						
							|  |  |  |         align: "start", | 
					
						
							|  |  |  |         value: "id", | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       { text: i18n.t("user.username"), value: "username" }, | 
					
						
							|  |  |  |       { text: i18n.t("user.full-name"), value: "fullName" }, | 
					
						
							|  |  |  |       { text: i18n.t("user.email"), value: "email" }, | 
					
						
							|  |  |  |       { text: i18n.t("group.group"), value: "group" }, | 
					
						
							| 
									
										
										
										
											2023-02-26 13:12:16 -06:00
										 |  |  |       { text: i18n.t("user.auth-method"), value: "authMethod" }, | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |       { text: i18n.t("user.admin"), value: "admin" }, | 
					
						
							|  |  |  |       { text: i18n.t("general.delete"), value: "actions", sortable: false, align: "center" }, | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-13 13:18:12 -08:00
										 |  |  |     async function unlockAllUsers(): Promise<void> { | 
					
						
							|  |  |  |       const { data } = await api.users.unlockAllUsers(true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (data) { | 
					
						
							|  |  |  |         const unlocked = data.unlocked ?? 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         alert.success(`${unlocked} user(s) unlocked`); | 
					
						
							|  |  |  |         refreshAllUsers(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |     return { | 
					
						
							| 
									
										
										
										
											2023-01-07 11:30:45 -08:00
										 |  |  |       isUserOwnAccount, | 
					
						
							| 
									
										
										
										
											2022-08-13 13:18:12 -08:00
										 |  |  |       unlockAllUsers, | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |       ...toRefs(state), | 
					
						
							|  |  |  |       headers, | 
					
						
							|  |  |  |       deleteUser, | 
					
						
							|  |  |  |       loading, | 
					
						
							|  |  |  |       refUserDialog, | 
					
						
							|  |  |  |       users, | 
					
						
							| 
									
										
										
										
											2022-12-01 06:26:50 +01:00
										 |  |  |       user, | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |       handleRowClick, | 
					
						
							| 
									
										
										
										
											2023-03-21 20:45:27 +01:00
										 |  |  |       ACTIONS_OPTIONS, | 
					
						
							| 
									
										
										
										
											2021-11-23 18:57:24 -09:00
										 |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   head() { | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       title: this.$t("sidebar.manage-users") as string, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | </script> |