Skip to content

Commit

Permalink
fix redirect on cms user
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanyvu committed Oct 22, 2024
1 parent 44bc6fc commit 7dd4725
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useParams } from "react-router-dom";
import { LoaderFunction, useParams } from "react-router-dom";
import { WithdrawRaiForm } from "./withdraw-rai";
import {
EnableWithdrawRaiForm,
DisableWithdrawRaiForm,
} from "./toggle-withdraw-rai";
import { queryClient } from "../../../router";
import { getItem } from "@/api";

// the keys will relate to this part of the route /actions/{key of postSubmissionForms}/authority/id
export const postSubmissionForms: Record<
Expand Down Expand Up @@ -38,3 +40,10 @@ export const PostSubmissionWrapper = () => {

return <PostSubmissionForm />;
};

export const postSubmissionLoader: LoaderFunction = async ({ params }) => {
return await queryClient.fetchQuery({
queryKey: ["record", params.id],
queryFn: async () => getItem(params.id),
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ActionForm } from "@/components/ActionForm";
import { formSchemas } from "@/formSchemas";
import { PackageSection } from "@/components/Form/content/PackageSection";
import { useParams } from "react-router-dom";
import { isCmsUser } from "shared-utils";

export const EnableWithdrawRaiForm = () => {
const { authority, id } = useParams();
Expand All @@ -26,6 +27,7 @@ export const EnableWithdrawRaiForm = () => {
body: `The state will be able to withdraw its RAI response. It may take up to a minute for this change to be applied.`,
variant: "success",
}}
conditionsDeterminingUserAccess={[isCmsUser]}
/>
);
};
Expand All @@ -51,6 +53,7 @@ export const DisableWithdrawRaiForm = () => {
body: `The state will not be able to withdraw its RAI response. It may take up to a minute for this change to be applied.`,
variant: "success",
}}
conditionsDeterminingUserAccess={[isCmsUser]}
/>
);
};
7 changes: 5 additions & 2 deletions react-app/src/router.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { createBrowserRouter } from "react-router-dom";
import * as F from "@/features";
import * as C from "@/components";
import { PostSubmissionWrapper } from "@/features/forms/post-submission/post-submissions-form";
import {
postSubmissionLoader,
PostSubmissionWrapper,
} from "@/features/forms/post-submission/post-submissions-form";
import { QueryClient } from "@tanstack/react-query";
export const queryClient = new QueryClient();

Expand Down Expand Up @@ -105,14 +108,14 @@ export const router = createBrowserRouter([
path: "/new-submission/spa/chip/landing/chip-eligibility",
element: <F.CHIPEligibilityLandingPage />,
},
{ path: "/action/:authority/:id/:type", element: <F.ActionPage /> },
{ path: "/webforms", element: <F.WebformsList /> },
{ path: "/webform/:id/:version", element: <F.Webform /> },
{ path: "/profile", element: <F.Profile /> },
{ path: "/guides/abp", element: <F.ABPGuide /> },
{
path: "/actions/:type/:authority/:id",
element: <PostSubmissionWrapper />,
loader: postSubmissionLoader,
},
],
loader: F.loader(queryClient),
Expand Down

0 comments on commit 7dd4725

Please sign in to comment.