Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORV2-2848 - FE: Staff Edit Application in the Queue #1784

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import "../../../../common/components/dashboard/Dashboard.scss";
import { Banner } from "../../../../common/components/dashboard/components/banner/Banner";
import { ApplicationForm } from "../../pages/Application/ApplicationForm";
import { ApplicationContext } from "../../context/ApplicationContext";
import { ApplicationReview } from "../../pages/Application/ApplicationReview";
import { getCompanyIdFromSession } from "../../../../common/apiManager/httpRequestHandler";
import { Loading } from "../../../../common/pages/Loading";
import { ApplicationInQueueReview } from "../../../queue/components/ApplicationInQueueReview";
import { useApplicationForStepsQuery } from "../../hooks/hooks";
import { PERMIT_STATUSES } from "../../types/PermitStatus";
import {
Expand All @@ -25,12 +23,12 @@ import {
} from "../../types/PermitType";

import {
APPLICATION_STEP_CONTEXTS,
APPLICATION_STEPS,
ApplicationStep,
ApplicationStepContext,
ERROR_ROUTES,
} from "../../../../routes/constants";
import { ApplicationReview } from "../../pages/Application/ApplicationReview";

const displayHeaderText = (stepKey: ApplicationStep) => {
switch (stepKey) {
Expand Down Expand Up @@ -121,12 +119,11 @@ export const ApplicationStepPage = ({

const renderApplicationStep = () => {
if (applicationStep === APPLICATION_STEPS.REVIEW) {
return applicationStepContext === APPLICATION_STEP_CONTEXTS.QUEUE ? (
<ApplicationInQueueReview
return (
<ApplicationReview
applicationData={contextData.applicationData}
applicationStepContext={applicationStepContext}
/>
) : (
<ApplicationReview companyId={companyId} />
);
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
ApplicationStepContext,
ERROR_ROUTES,
} from "../../../../routes/constants";
import { useApplicationInQueueMetadata } from "../../../queue/hooks/hooks";

const FEATURE = "application";

Expand Down Expand Up @@ -183,6 +184,18 @@ export const ApplicationForm = ({
return updatedViolations;
};

const { data: applicationMetadata } = useApplicationInQueueMetadata({
applicationId: getDefaultRequiredVal("", currentFormData.permitId),
companyId,
});

const assignedUser = getDefaultRequiredVal(
"",
applicationMetadata?.assignedUser,
);

const currentUserIsAssignedUser = assignedUser === idirUserDetails?.userName;

// Check to see if all application values were already saved
const isApplicationSaved = () => {
// Check if all current form field values match field values already saved in application context
Expand All @@ -194,6 +207,10 @@ export const ApplicationForm = ({

// When "Continue" button is clicked
const onContinue = async (data: ApplicationFormData) => {
if (!currentUserIsAssignedUser) {
return;
}

const updatedViolations = await triggerPolicyValidation();
// prevent CV client continuing if there are policy engine validation errors
if (Object.keys(updatedViolations).length > 0 && !isStaffUser) {
Expand All @@ -204,6 +221,7 @@ export const ApplicationForm = ({
const vehicleData = serializePermitVehicleDetails(
data.permitData.vehicleDetails,
);

const savedVehicleDetails = await handleSaveVehicle(vehicleData);

// Save application before continuing
Expand Down Expand Up @@ -235,6 +253,10 @@ export const ApplicationForm = ({
additionalSuccessAction?: (permitId: string) => void,
savedVehicleInventoryDetails?: Nullable<PermitVehicleDetails>,
) => {
if (!currentUserIsAssignedUser) {
return;
}

if (isNull(savedVehicleInventoryDetails)) {
return navigate(ERROR_ROUTES.UNEXPECTED);
}
Expand All @@ -251,7 +273,6 @@ export const ApplicationForm = ({
},
},
};

await saveApplication(
{
data: applicationToBeSaved,
Expand Down
Loading
Loading