From 987f6276fbd2fa9c2d9247e0153969244fb6dcaf Mon Sep 17 00:00:00 2001 From: john-tco Date: Mon, 31 Jul 2023 12:11:54 +0100 Subject: [PATCH] fix add, fix delete --- .../manage-departments/add/index.page.tsx | 4 +- .../delete/[id]/index.page.tsx | 19 ++-- .../edit/[id]/index.page.tsx | 89 +++++++++---------- .../manage-departments/index.page.tsx | 6 +- .../user/[id]/index.page.tsx | 1 - .../admin/src/services/SuperAdminService.ts | 2 +- .../QuestionPageGetServerSideProps.tsx | 3 +- 7 files changed, 62 insertions(+), 62 deletions(-) diff --git a/packages/admin/src/pages/super-admin-dashboard/manage-departments/add/index.page.tsx b/packages/admin/src/pages/super-admin-dashboard/manage-departments/add/index.page.tsx index 47913b731..9e0ddf844 100644 --- a/packages/admin/src/pages/super-admin-dashboard/manage-departments/add/index.page.tsx +++ b/packages/admin/src/pages/super-admin-dashboard/manage-departments/add/index.page.tsx @@ -26,7 +26,7 @@ export function getServerSideProps(context: GetServerSidePropsContext) { handleRequest, jwt: getUserTokenFromCookies(context.req), onErrorMessage: 'Failed to create department, please try again later.', - onSuccessRedirectHref: `/super-admin-dashboard/manage-departments/edit/${context.params?.id}`, + onSuccessRedirectHref: `/super-admin-dashboard/manage-departments/`, }); } @@ -45,7 +45,7 @@ const AddDepartmentPage = ({

Add a department

, - jwt: string - ) => deleteDepartmentInformation(body.id, jwt); + const handleRequest = async (_body: { _csrf: string }, jwt: string) => + deleteDepartmentInformation(context.params?.id as string, jwt); return QuestionPageGetServerSideProps({ context, @@ -27,7 +25,7 @@ export function getServerSideProps(context: GetServerSidePropsContext) { handleRequest, jwt: getUserTokenFromCookies(context.req), onErrorMessage: 'Failed to delete department, please try again later.', - onSuccessRedirectHref: `/super-admin-dashboard/manage-departments/edit/${context.params?.id}`, + onSuccessRedirectHref: `/super-admin-dashboard/manage-departments/`, }); } @@ -37,8 +35,6 @@ const DeleteDepartmentPage = ({ csrfToken, fieldErrors, }: InferProps) => { - const { publicRuntimeConfig } = getConfig(); - return ( <> @@ -47,9 +43,13 @@ const DeleteDepartmentPage = ({

Delete department

+

+ If you delete this department, all of its information will be lost. + You cannot undo this action. +

+ + - - Delete department - -
-
- - - +
+

Edit department

+ + + +
+ + + + Delete department + +
+
); diff --git a/packages/admin/src/pages/super-admin-dashboard/manage-departments/index.page.tsx b/packages/admin/src/pages/super-admin-dashboard/manage-departments/index.page.tsx index 01dd064b3..e53916c5e 100644 --- a/packages/admin/src/pages/super-admin-dashboard/manage-departments/index.page.tsx +++ b/packages/admin/src/pages/super-admin-dashboard/manage-departments/index.page.tsx @@ -44,7 +44,11 @@ const ManageDepartmentsPage = ({ hasWiderKeyColumn rows={departments.map((dept, idx) => getDepartmentRow(idx, dept))} /> - + Add new department diff --git a/packages/admin/src/pages/super-admin-dashboard/user/[id]/index.page.tsx b/packages/admin/src/pages/super-admin-dashboard/user/[id]/index.page.tsx index 1d75c48c8..63abe2c26 100644 --- a/packages/admin/src/pages/super-admin-dashboard/user/[id]/index.page.tsx +++ b/packages/admin/src/pages/super-admin-dashboard/user/[id]/index.page.tsx @@ -28,7 +28,6 @@ const UserPage = ({ user }: UserPageProps) => { return ( <> -
axios.delete( - `${process.env.USER_SERVICE_URL}/department/${id}`, + `${process.env.USER_SERVICE_URL}/department/${Number(id)}`, axiosUserServiceConfig(userToken) ); diff --git a/packages/gap-web-ui/src/components/question-page/QuestionPageGetServerSideProps.tsx b/packages/gap-web-ui/src/components/question-page/QuestionPageGetServerSideProps.tsx index 33bb7c1a7..39fc15eaa 100644 --- a/packages/gap-web-ui/src/components/question-page/QuestionPageGetServerSideProps.tsx +++ b/packages/gap-web-ui/src/components/question-page/QuestionPageGetServerSideProps.tsx @@ -25,6 +25,7 @@ import { * * @returns A redirect to the relevant location, or a set of props needed to load a page */ + export default async function QuestionPageGetServerSideProps< T extends PageBodyResponse, K extends FetchPageData, @@ -56,7 +57,7 @@ export default async function QuestionPageGetServerSideProps< return { props: { - csrfToken: ((req as any).csrfToken?.() || '') as string, + csrfToken: (req as any).csrfToken?.() || '', formAction: resolvedUrl, fieldErrors, pageData,