diff --git a/frontend/composables/use-groups.ts b/frontend/composables/use-groups.ts index 7a84d2305..d74a2f47a 100644 --- a/frontend/composables/use-groups.ts +++ b/frontend/composables/use-groups.ts @@ -45,28 +45,11 @@ export const useGroupSelf = function () { export const useGroups = function () { const api = useUserApi(); const loading = ref(false); + const groups = ref(null); - function getAllGroups() { + async function getAllGroups() { loading.value = true; - const asyncKey = String(Date.now()); - const { data: groups } = useAsyncData(asyncKey, async () => { - const { data } = await api.groups.getAll(1, -1, { orderBy: "name", orderDirection: "asc" }); ; - - if (data) { - return data.items; - } - else { - return null; - } - }); - - loading.value = false; - return groups; - } - - async function refreshAllGroups() { - loading.value = true; - const { data } = await api.groups.getAll(1, -1, { orderBy: "name", orderDirection: "asc" }); ; + const { data } = await api.groups.getAll(1, -1, { orderBy: "name", orderDirection: "asc" }); if (data) { groups.value = data.items; @@ -78,11 +61,15 @@ export const useGroups = function () { loading.value = false; } + async function refreshAllGroups() { + await getAllGroups(); + } + async function deleteGroup(id: string | number) { loading.value = true; const { data } = await api.groups.deleteOne(id); loading.value = false; - refreshAllGroups(); + await refreshAllGroups(); return data; } @@ -93,9 +80,13 @@ export const useGroups = function () { if (data && groups.value) { groups.value.push(data); } + loading.value = false; } - const groups = getAllGroups(); + // Initialize data on first call + if (!groups.value) { + getAllGroups(); + } return { groups, getAllGroups, refreshAllGroups, deleteGroup, createGroup }; }; diff --git a/frontend/composables/use-households.ts b/frontend/composables/use-households.ts index 2e7d53a5b..146b142c1 100644 --- a/frontend/composables/use-households.ts +++ b/frontend/composables/use-households.ts @@ -48,28 +48,11 @@ export const useHouseholdSelf = function () { export const useAdminHouseholds = function () { const api = useAdminApi(); const loading = ref(false); + const households = ref(null); - function getAllHouseholds() { + async function getAllHouseholds() { loading.value = true; - const asyncKey = String(Date.now()); - const { data: households } = useAsyncData(asyncKey, async () => { - const { data } = await api.households.getAll(1, -1, { orderBy: "name, group.name", orderDirection: "asc" }); - - if (data) { - return data.items; - } - else { - return null; - } - }); - - loading.value = false; - return households; - } - - async function refreshAllHouseholds() { - loading.value = true; - const { data } = await api.households.getAll(1, -1, { orderBy: "name, group.name", orderDirection: "asc" }); ; + const { data } = await api.households.getAll(1, -1, { orderBy: "name, group.name", orderDirection: "asc" }); if (data) { households.value = data.items; @@ -81,11 +64,15 @@ export const useAdminHouseholds = function () { loading.value = false; } + async function refreshAllHouseholds() { + await getAllHouseholds(); + } + async function deleteHousehold(id: string | number) { loading.value = true; const { data } = await api.households.deleteOne(id); loading.value = false; - refreshAllHouseholds(); + await refreshAllHouseholds(); return data; } @@ -96,9 +83,9 @@ export const useAdminHouseholds = function () { if (data && households.value) { households.value.push(data); } + loading.value = false; } - const households = getAllHouseholds(); function useHouseholdsInGroup(groupIdRef: Ref) { return computed( () => { @@ -109,6 +96,10 @@ export const useAdminHouseholds = function () { ); } + if (!households.value) { + getAllHouseholds(); + } + return { households, useHouseholdsInGroup, diff --git a/frontend/pages/admin/manage/households/index.vue b/frontend/pages/admin/manage/households/index.vue index 2f6b306de..78346d9c6 100644 --- a/frontend/pages/admin/manage/households/index.vue +++ b/frontend/pages/admin/manage/households/index.vue @@ -14,7 +14,6 @@ :items="groups" item-title="name" item-value="id" - :return-object="false" variant="filled" :label="$t('household.household-group')" :rules="[validators.required]" @@ -94,10 +93,7 @@ icon color="error" variant="text" - @click.stop=" - confirmDialog = true; - deleteTarget = +item.id; - " + @click.stop="confirmDialog = true; deleteTarget = item.id" > {{ $globals.icons.delete }} @@ -114,7 +110,7 @@ - diff --git a/frontend/pages/admin/manage/users/create.vue b/frontend/pages/admin/manage/users/create.vue index 7009b68a4..0fa39abc4 100644 --- a/frontend/pages/admin/manage/users/create.vue +++ b/frontend/pages/admin/manage/users/create.vue @@ -21,26 +21,23 @@ @@ -60,82 +57,51 @@ -