From 3e0d225d8bd72e1b65e5dd4135419d04626c7940 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Mon, 1 Aug 2022 15:14:49 +0100 Subject: [PATCH] fix add all functionality within groupId screen --- .../portal/manage/groups/[groupId].svelte | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte index d5a595a536..17c16c639b 100644 --- a/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte +++ b/packages/builder/src/pages/builder/portal/manage/groups/[groupId].svelte @@ -26,18 +26,36 @@ let popover let searchTerm = "" let selectedUsers = [] - let prevSearch = undefined, - search = undefined + let prevSearch = undefined let pageInfo = createPaginationStore() let loaded = false $: page = $pageInfo.page - $: fetchUsers(page, search) + $: fetchUsers(page, searchTerm) $: group = $groups.find(x => x._id === groupId) async function addAll() { - group.users = selectedUsers + selectedUsers = [...selectedUsers, ...filtered.map(u => u._id)] + + let reducedUserObjects = filtered.map(u => { + return { + _id: u._id, + email: u.email, + } + }) + group.users = [...reducedUserObjects, ...group.users] + await groups.actions.save(group) + + $users.data.forEach(async user => { + let userToEdit = await users.get(user._id) + let userGroups = userToEdit.userGroups || [] + userGroups.push(groupId) + await users.save({ + ...userToEdit, + userGroups, + }) + }) } async function selectUser(id) { @@ -100,7 +118,7 @@ prevSearch = search try { pageInfo.loading() - await users.search({ page, search }) + await users.search({ page, email: search }) pageInfo.fetched($users.hasNextPage, $users.nextPage) } catch (error) { notifications.error("Error getting user list")