| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <v-container v-if="group" class="narrow-container"> | 
					
						
							|  |  |  |     <BasePageTitle> | 
					
						
							|  |  |  |       <template #header> | 
					
						
							|  |  |  |         <v-img max-height="125" max-width="125" :src="require('~/static/svgs/manage-group-settings.svg')"></v-img> | 
					
						
							|  |  |  |       </template> | 
					
						
							| 
									
										
										
										
											2023-03-21 20:45:27 +01:00
										 |  |  |       <template #title> {{ $t('group.admin-group-management') }} </template> | 
					
						
							|  |  |  |       {{ $t('group.admin-group-management-text') }} | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |     </BasePageTitle> | 
					
						
							|  |  |  |     <AppToolbar back> </AppToolbar> | 
					
						
							| 
									
										
										
										
											2023-03-21 20:45:27 +01:00
										 |  |  |     <v-card-text> {{ $t('group.group-id-value', [group.id]) }} </v-card-text> | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |     <v-form v-if="!userError" ref="refGroupEditForm" @submit.prevent="handleSubmit"> | 
					
						
							|  |  |  |       <v-card outlined> | 
					
						
							|  |  |  |         <v-card-text> | 
					
						
							| 
									
										
										
										
											2023-03-21 20:45:27 +01:00
										 |  |  |           <v-text-field v-model="group.name" :label="$t('group.group-name')"> </v-text-field> | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |           <GroupPreferencesEditor v-if="group.preferences" v-model="group.preferences" /> | 
					
						
							|  |  |  |         </v-card-text> | 
					
						
							|  |  |  |       </v-card> | 
					
						
							|  |  |  |       <div class="d-flex pa-2"> | 
					
						
							|  |  |  |         <BaseButton type="submit" edit class="ml-auto"> {{ $t("general.update") }}</BaseButton> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     </v-form> | 
					
						
							|  |  |  |   </v-container> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script lang="ts"> | 
					
						
							| 
									
										
										
										
											2023-10-26 15:26:14 +02:00
										 |  |  | import { defineComponent, useRoute, onMounted, ref, useContext } from "@nuxtjs/composition-api"; | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  | import GroupPreferencesEditor from "~/components/Domain/Group/GroupPreferencesEditor.vue"; | 
					
						
							|  |  |  | import { useAdminApi } from "~/composables/api"; | 
					
						
							|  |  |  | import { alert } from "~/composables/use-toast"; | 
					
						
							| 
									
										
										
										
											2022-10-22 11:51:07 -08:00
										 |  |  | import { GroupInDB } from "~/lib/api/types/user"; | 
					
						
							| 
									
										
										
										
											2022-01-09 07:15:23 +01:00
										 |  |  | import { VForm } from "~/types/vuetify"; | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default defineComponent({ | 
					
						
							|  |  |  |   components: { | 
					
						
							|  |  |  |     GroupPreferencesEditor, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   layout: "admin", | 
					
						
							|  |  |  |   setup() { | 
					
						
							|  |  |  |     const route = useRoute(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-26 15:26:14 +02:00
										 |  |  |     const { i18n } = useContext(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |     const groupId = route.value.params.id; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // ==============================================
 | 
					
						
							|  |  |  |     // New User Form
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const refGroupEditForm = ref<VForm | null>(null); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const adminApi = useAdminApi(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-21 21:22:02 +02:00
										 |  |  |     const group = ref<GroupInDB | null>(null); | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const userError = ref(false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     onMounted(async () => { | 
					
						
							|  |  |  |       const { data, error } = await adminApi.groups.getOne(groupId); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (error?.response?.status === 404) { | 
					
						
							| 
									
										
										
										
											2023-10-26 15:26:14 +02:00
										 |  |  |         alert.error(i18n.tc("user.user-not-found")); | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |         userError.value = true; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (data) { | 
					
						
							|  |  |  |         group.value = data; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async function handleSubmit() { | 
					
						
							| 
									
										
										
										
											2022-01-16 03:38:11 +01:00
										 |  |  |       if (!refGroupEditForm.value?.validate() || group.value === null) { | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const { response, data } = await adminApi.groups.updateOne(group.value.id, group.value); | 
					
						
							|  |  |  |       if (response?.status === 200 && data) { | 
					
						
							| 
									
										
										
										
											2024-01-30 12:41:37 -06:00
										 |  |  |         if (group.value.slug !== data.slug) { | 
					
						
							|  |  |  |           // the slug updated, which invalidates the nav URLs
 | 
					
						
							|  |  |  |           window.location.reload(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |         group.value = data; | 
					
						
							| 
									
										
										
										
											2024-01-30 12:41:37 -06:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         alert.error(i18n.tc("settings.settings-update-failed")); | 
					
						
							| 
									
										
										
										
											2021-11-25 14:17:02 -09:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return { | 
					
						
							|  |  |  |       group, | 
					
						
							|  |  |  |       userError, | 
					
						
							|  |  |  |       refGroupEditForm, | 
					
						
							|  |  |  |       handleSubmit, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | </script> |