Skip to content

Commit

Permalink
Fixed bug with redirect and removing roles blocking user
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-tco committed Aug 11, 2023
1 parent e502cea commit 5bb8e00
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5bb8e00

Please sign in to comment.