From 52c7980e080c27faf13b54913d107da7fe9aee79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Mon, 17 May 2021 16:16:51 +0200 Subject: [PATCH] simplify fetching --- .../src/pages/builder/portal/manage/users/[userId].svelte | 8 +++++--- .../manage/users/_components/UpdateRolesModal.svelte | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte index 2d4b5d26c0..0581066db5 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/[userId].svelte @@ -29,9 +29,10 @@ } // Merge the Apps list and the roles response to get something that makes sense for the table - $: appList = Object.keys($apps?.data).map(app => ({ - name: $apps?.data?.[app]?.name, - role: $roleFetch?.data?.roles?.[app], + $: appList = Object.keys($apps?.data).map(id => ({ + ...$apps?.data?.[id], + _id: id, + role: $roleFetch?.data?.roles?.[id], })) let selectedApp @@ -49,6 +50,7 @@ } async function openUpdateRolesModal({ detail }) { + console.log(detail) selectedApp = detail editRolesModal.show() } diff --git a/packages/builder/src/pages/builder/portal/manage/users/_components/UpdateRolesModal.svelte b/packages/builder/src/pages/builder/portal/manage/users/_components/UpdateRolesModal.svelte index 8d09584577..4e47d96552 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/_components/UpdateRolesModal.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/_components/UpdateRolesModal.svelte @@ -9,8 +9,8 @@ const dispatch = createEventDispatcher() - const roles = fetchData(`/api/admin/roles/${app._id}`) - $: options = $roles?.data?.roles?.map(role => role._id) + const roles = app.roles + let options = roles.map(role => role._id) let selectedRole async function updateUserRoles() { @@ -22,7 +22,7 @@ }, }) if (res.status === 400) { - notifications.error("Failed to update role.") + notifications.error("Failed to update role") } else { notifications.success("Roles updated") dispatch("update")