Skip to content

Commit

Permalink
fix add, fix delete
Browse files Browse the repository at this point in the history
  • Loading branch information
john-tco committed Jul 31, 2023
1 parent 525154f commit 987f627
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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/`,
});
}

Expand All @@ -45,7 +45,7 @@ const AddDepartmentPage = ({
<FlexibleQuestionPageLayout
fieldErrors={fieldErrors}
csrfToken={csrfToken}
formAction={publicRuntimeConfig.SUB_PATH + formAction}
formAction={formAction}
>
<h1 className="govuk-heading-l">Add a department</h1>
<TextInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ export function getServerSideProps(context: GetServerSidePropsContext) {
return { id: context.params?.id as string };
};

const handleRequest = async (
body: Omit<Department, 'name' | 'ggisID'>,
jwt: string
) => deleteDepartmentInformation(body.id, jwt);
const handleRequest = async (_body: { _csrf: string }, jwt: string) =>
deleteDepartmentInformation(context.params?.id as string, jwt);

return QuestionPageGetServerSideProps({
context,
fetchPageData,
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/`,
});
}

Expand All @@ -37,8 +35,6 @@ const DeleteDepartmentPage = ({
csrfToken,
fieldErrors,
}: InferProps<typeof getServerSideProps>) => {
const { publicRuntimeConfig } = getConfig();

return (
<>
<Meta title="Delete Department" />
Expand All @@ -47,9 +43,13 @@ const DeleteDepartmentPage = ({
<FlexibleQuestionPageLayout
fieldErrors={fieldErrors}
csrfToken={csrfToken}
formAction={publicRuntimeConfig.SUB_PATH + formAction}
formAction={formAction}
>
<h1 className="govuk-heading-l">Delete department</h1>
<p className="govuk-body">
If you delete this department, all of its information will be lost.
You cannot undo this action.
</p>
<div className="govuk-button-group">
<button
className="govuk-button govuk-button--warning"
Expand All @@ -58,7 +58,8 @@ const DeleteDepartmentPage = ({
Delete department
</button>
<a
href={`${publicRuntimeConfig.SUB_PATH}/super-admin-dashboard/manage-departments/edit/${id}`}
className="govuk-link"
href={`/super-admin-dashboard/manage-departments/edit/${id}`}
>
Cancel
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,54 +53,49 @@ const EditDepartmentPage = ({

return (
<>
<div className="govuk-grid-row govuk-!-padding-top-2">
<Meta title="Edit Department" />
<CustomLink isBackButton href={'/super-admin-dashboard/'} />
<div className="govuk-width-container">
<main className="govuk-main-wrapper govuk-main-wrapper--auto-spacing">
<div className="govuk-grid-row">
<h1 className="govuk-heading-l">Edit department</h1>
<FlexibleQuestionPageLayout
fieldErrors={fieldErrors}
csrfToken={csrfToken}
formAction={publicRuntimeConfig.SUB_PATH + formAction}
>
<TextInput
questionTitle={`Department name`}
titleSize="m"
fieldName="departmentName"
defaultValue={departmentName}
fieldErrors={fieldErrors}
TitleTag="h2"
/>
<TextInput
questionHintText={
'This should be the departments GGIS ID, not the ID of a grant within it.'
}
width="10"
questionTitle={`GGGIS ID number`}
titleSize="m"
fieldName="ggisId"
defaultValue={ggisID}
fieldErrors={fieldErrors}
TitleTag="h2"
/>
<div className="govuk-button-group">
<button className="govuk-button" data-module="govuk-button">
Save changes
</button>
<Meta title="Edit Department" />
<CustomLink isBackButton href={'/super-admin-dashboard/'} />

<a
href={`${publicRuntimeConfig.SUB_PATH}/super-admin-dashboard/manage-departments/delete/${id}`}
className="govuk-button govuk-button--warning"
>
Delete department
</a>
</div>
</FlexibleQuestionPageLayout>
</div>
</main>
</div>
<div className="govuk-!-padding-top-7">
<h1 className="govuk-heading-l">Edit department</h1>
<FlexibleQuestionPageLayout
fieldErrors={fieldErrors}
csrfToken={csrfToken}
formAction={formAction}
>
<TextInput
questionTitle={`Department name`}
titleSize="m"
fieldName="departmentName"
defaultValue={departmentName}
fieldErrors={fieldErrors}
TitleTag="h2"
/>
<TextInput
questionHintText={
'This should be the departments GGIS ID, not the ID of a grant within it.'
}
width="10"
questionTitle={`GGGIS ID number`}
titleSize="m"
fieldName="ggisId"
defaultValue={ggisID}
fieldErrors={fieldErrors}
TitleTag="h2"
/>
<div className="govuk-button-group">
<button className="govuk-button" data-module="govuk-button">
Save changes
</button>

<a
href={`${publicRuntimeConfig.SUB_PATH}/super-admin-dashboard/manage-departments/delete/${id}`}
className="govuk-button govuk-button--warning"
>
Delete department
</a>
</div>
</FlexibleQuestionPageLayout>
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ const ManageDepartmentsPage = ({
hasWiderKeyColumn
rows={departments.map((dept, idx) => getDepartmentRow(idx, dept))}
/>
<CustomLink href={`/manage-departments/add`} isButton isSecondaryButton>
<CustomLink
href={`/super-admin-dashboard/manage-departments/add`}
isButton
isSecondaryButton
>
Add new department
</CustomLink>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const UserPage = ({ user }: UserPageProps) => {
return (
<>
<Meta title="Manage User" />

<div className="govuk-!-padding-top-2">
<div className="govuk-width-container">
<a
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/services/SuperAdminService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const deleteDepartmentInformation = async (
userToken: string
) =>
axios.delete(
`${process.env.USER_SERVICE_URL}/department/${id}`,
`${process.env.USER_SERVICE_URL}/department/${Number(id)}`,
axiosUserServiceConfig(userToken)
);

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

0 comments on commit 987f627

Please sign in to comment.