From 5bb8e008f22a478be770cad1abd6e5406770f180 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 11 Aug 2023 13:14:09 +0100 Subject: [PATCH] Fixed bug with redirect and removing roles blocking user --- .../pages/super-admin-dashboard/user/[id]/block-user.page.tsx | 2 +- .../pages/super-admin-dashboard/user/[id]/block-user.test.tsx | 4 ++-- .../super-admin-dashboard/user/[id]/change-roles.page.tsx | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/admin/src/pages/super-admin-dashboard/user/[id]/block-user.page.tsx b/packages/admin/src/pages/super-admin-dashboard/user/[id]/block-user.page.tsx index ae359685d..baea5841a 100644 --- a/packages/admin/src/pages/super-admin-dashboard/user/[id]/block-user.page.tsx +++ b/packages/admin/src/pages/super-admin-dashboard/user/[id]/block-user.page.tsx @@ -31,7 +31,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { handleRequest, jwt: getUserTokenFromCookies(context.req), onErrorMessage: 'Failed to block user, please try again later.', - onSuccessRedirectHref: `/super-admin-dashboard/`, + onSuccessRedirectHref: `/super-admin-dashboard/user/${userId}`, }); } diff --git a/packages/admin/src/pages/super-admin-dashboard/user/[id]/block-user.test.tsx b/packages/admin/src/pages/super-admin-dashboard/user/[id]/block-user.test.tsx index 928227e3b..60b716cbb 100644 --- a/packages/admin/src/pages/super-admin-dashboard/user/[id]/block-user.test.tsx +++ b/packages/admin/src/pages/super-admin-dashboard/user/[id]/block-user.test.tsx @@ -76,14 +76,14 @@ describe('Block user page functionality', () => { it('POST request to getServerSideProps calls updateUserRoles', async () => { const context = getContext(() => ({ req: { method: 'POST', body: {} }, - params: { userId: '1234' }, + params: { userId: '1234', id: '1' }, })); const response = await getServerSideProps(context); expect(updateUserRoles).toHaveBeenCalled(); expect(response).toEqual({ redirect: { - destination: '/super-admin-dashboard/', + destination: '/super-admin-dashboard/user/1', statusCode: 302, }, }); diff --git a/packages/admin/src/pages/super-admin-dashboard/user/[id]/change-roles.page.tsx b/packages/admin/src/pages/super-admin-dashboard/user/[id]/change-roles.page.tsx index 3f0d708a7..a602f910f 100644 --- a/packages/admin/src/pages/super-admin-dashboard/user/[id]/change-roles.page.tsx +++ b/packages/admin/src/pages/super-admin-dashboard/user/[id]/change-roles.page.tsx @@ -22,7 +22,9 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { const userId = context.params?.id as string; async function handleRequest(body: PageBodyResponse, jwt: string) { - return updateUserRoles(userId, body.newUserRoles || [], jwt); + const findAndApplicantRoles = ['1', '2']; + const newUserRoles = findAndApplicantRoles.concat(body.newUserRoles || []); + return updateUserRoles(userId, newUserRoles, jwt); } async function fetchPageData(jwt: string) {