Skip to content

Commit

Permalink
remove navigate(APPLICATION_QUEUE_ROUTES.EDIT) and deserialize applic…
Browse files Browse the repository at this point in the history
…ation response before passing as props to ApplicationInQueueReview
  • Loading branch information
glen-aot committed Oct 9, 2024
1 parent b0cbfd1 commit 70f189a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { ConfirmationCheckboxes } from "./ConfirmationCheckboxes";
import { FeeSummary } from "../../../../components/feeSummary/FeeSummary";
import { PermitType } from "../../../../types/PermitType";
import { Nullable } from "../../../../../../common/types/common";
import { PERMIT_REVIEW_CONTEXTS, PermitReviewContext } from "../../../../types/PermitReviewContext";
import {
PERMIT_REVIEW_CONTEXTS,
PermitReviewContext,
} from "../../../../types/PermitReviewContext";

export const ReviewFeeSummary = ({
hasAttemptedSubmission,
Expand Down Expand Up @@ -35,7 +38,9 @@ export const ReviewFeeSummary = ({
hasAttemptedSubmission={hasAttemptedSubmission}
areAllChecked={areAllConfirmed}
setAreAllChecked={setAreAllConfirmed}
shouldDisableCheckboxes={reviewContext === PERMIT_REVIEW_CONTEXTS.QUEUE}
shouldDisableCheckboxes={
reviewContext === PERMIT_REVIEW_CONTEXTS.QUEUE
}
/>
</Box>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ import {
useRejectApplicationInQueueMutation,
} from "../hooks/hooks";

import {
APPLICATION_QUEUE_ROUTES,
APPLICATION_STEPS,
IDIR_ROUTES,
} from "../../../routes/constants";
import { APPLICATION_STEPS, IDIR_ROUTES } from "../../../routes/constants";

export const ApplicationInQueueReview = ({
applicationData,
Expand Down Expand Up @@ -58,7 +54,7 @@ export const ApplicationInQueueReview = ({
const [hasAttemptedSubmission, setHasAttemptedSubmission] = useState(false);

const handleEdit = () => {
navigate(APPLICATION_QUEUE_ROUTES.EDIT(companyId, applicationData?.permitId));
return;
};

const isSuccess = (status?: number) => status === 201;
Expand Down Expand Up @@ -94,7 +90,7 @@ export const ApplicationInQueueReview = ({
const handleReject = async (): Promise<void> => {
setHasAttemptedSubmission(true);
if (!allConfirmed) return;

await rejectApplication({
applicationId: applicationData?.permitId,
companyId,
Expand Down
52 changes: 22 additions & 30 deletions frontend/src/features/queue/pages/ReviewApplicationInQueue.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import { Box } from "@mui/material";
import { useContext } from "react";
import { Navigate, useParams } from "react-router-dom";

import OnRouteBCContext from "../../../common/authentication/OnRouteBCContext";
import { Banner } from "../../../common/components/dashboard/components/banner/Banner";
import { Loading } from "../../../common/pages/Loading";
// import { UniversalUnauthorized } from "../../../common/pages/UniversalUnauthorized";
import { useApplicationDetailsQuery } from "../../permits/hooks/hooks";
import { ApplicationInQueueReview } from "../components/ApplicationInQueueReview";
import { applyWhenNotNullable, getDefaultRequiredVal } from "../../../common/helpers/util";
import {
applyWhenNotNullable,
getDefaultRequiredVal,
} from "../../../common/helpers/util";
import { ERROR_ROUTES } from "../../../routes/constants";
import { deserializeApplicationResponse } from "../../permits/helpers/deserializeApplication";
import { UniversalUnexpected } from "../../../common/pages/UniversalUnexpected";

export const ReviewApplicationInQueue = () => {
const { idirUserDetails } = useContext(OnRouteBCContext);
const {
companyId: companyIdParam,
permitId: permitIdParam,
} = useParams();

const companyId: number = applyWhenNotNullable(id => Number(id), companyIdParam, 0);
const { companyId: companyIdParam, permitId: permitIdParam } = useParams();

const companyId: number = applyWhenNotNullable(
(id) => Number(id),
companyIdParam,
0,
);
const permitId = getDefaultRequiredVal("", permitIdParam);

const {
query: {
data: applicationData,
},
query: { data: applicationData, isLoading: applicationDataIsLoading },
} = useApplicationDetailsQuery({
companyId,
permitId,
Expand All @@ -34,22 +33,13 @@ export const ReviewApplicationInQueue = () => {
return <Navigate to={ERROR_ROUTES.UNEXPECTED} />;
}

if (
typeof applicationData === "undefined" ||
typeof idirUserDetails === "undefined"
) {
if (applicationDataIsLoading) {
return <Loading />;
}

/*
* Find another way to authorize user, as application details doesn't have "claimedBy" field
*
* // If current user is not the claimant of the application, show unauthorized
* if (idirUserDetails.userName !== application?.claimedBy) {
* return <UniversalUnauthorized />;
* }
*/

if (!applicationData) {
return <UniversalUnexpected />;
}
return (
<div className="review-application-in-queue">
<Box
Expand All @@ -61,8 +51,10 @@ export const ReviewApplicationInQueue = () => {
>
<Banner bannerText="Review and Confirm Details" />
</Box>

<ApplicationInQueueReview />

<ApplicationInQueueReview
applicationData={deserializeApplicationResponse(applicationData)}
/>
</div>
);
};
2 changes: 2 additions & 0 deletions vehicles/src/common/constants/permit.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ export const TROW_MAX_VALID_DURATION = 366;

export const PERMIT_TYPES_FOR_QUEUE: readonly PermitType[] = [
PermitType.SINGLE_TRIP_OVERSIZE,
// TODO remove this
PermitType.TERM_OVERSIZE,
];

0 comments on commit 70f189a

Please sign in to comment.