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-2616 - Fix LOA bugs on FE #1560

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}

&__label {
color: $disabled-colour;
color: $bc-black;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo, useState } from "react";
import { useContext, useEffect, useMemo, useState } from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faArrowLeft, faArrowRight } from "@fortawesome/free-solid-svg-icons";
import { Button, Step, StepConnector, StepLabel, Stepper } from "@mui/material";
Expand All @@ -13,6 +13,7 @@ import { LOABasicInfo } from "./basic/LOABasicInfo";
import { Nullable } from "../../../../../common/types/common";
import { LOAFormData, loaDetailToFormData } from "../../../types/LOAFormData";
import { ERROR_ROUTES } from "../../../../../routes/constants";
import { SnackBarContext } from "../../../../../App";
import {
useCreateLOAMutation,
useFetchLOADetail,
Expand All @@ -36,6 +37,7 @@ export const LOASteps = ({
];

const navigate = useNavigate();
const { setSnackBar } = useContext(SnackBarContext);
const { data: loaDetail } = useFetchLOADetail(companyId, loaId);
const createLOAMutation = useCreateLOAMutation();
const updateLOAMutation = useUpdateLOAMutation();
Expand Down Expand Up @@ -77,7 +79,8 @@ export const LOASteps = ({

const handleFinish = async () => {
// Handle submitting LOA
const res = !loaId ? await createLOAMutation.mutateAsync({
const isLOACreation = !loaId;
const res = isLOACreation ? await createLOAMutation.mutateAsync({
zgong-gov marked this conversation as resolved.
Show resolved Hide resolved
companyId,
data: getValues(),
}) : await updateLOAMutation.mutateAsync({
Expand All @@ -87,6 +90,12 @@ export const LOASteps = ({
});

if (res.status === 200 || res.status === 201) {
setSnackBar({
showSnackbar: true,
setShowSnackbar: () => true,
message: isLOACreation ? `LOA Added` : `LOA Updated`,
alertType: isLOACreation ? "success" : "info",
});
onExit();
} else {
navigate(ERROR_ROUTES.UNEXPECTED);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState } from "react";
import { Dayjs } from "dayjs";
import { Checkbox } from "@mui/material";
import {
Expand All @@ -15,6 +16,12 @@ import { Nullable, Optional } from "../../../../../../common/types/common";
import { UploadedFile } from "../../../../components/SpecialAuthorizations/LOA/upload/UploadedFile";
import { UploadInput } from "../../../../components/SpecialAuthorizations/LOA/upload/UploadInput";
import { applyWhenNotNullable } from "../../../../../../common/helpers/util";
import { DeleteConfirmationDialog } from "../../../../../../common/components/dialog/DeleteConfirmationDialog";
import {
CustomDatePicker,
PAST_START_DATE_STATUSES,
} from "../../../../../../common/components/form/subFormComponents/CustomDatePicker";

import {
expiryMustBeAfterStart,
invalidUploadFormat,
Expand All @@ -23,7 +30,6 @@ import {
selectionRequired,
uploadSizeExceeded,
} from "../../../../../../common/helpers/validationMessages";
import { CustomDatePicker, PAST_START_DATE_STATUSES } from "../../../../../../common/components/form/subFormComponents/CustomDatePicker";

const FEATURE = "loa";

Expand Down Expand Up @@ -106,6 +112,8 @@ export const LOABasicInfo = ({
}: {
onRemoveDocument: () => Promise<boolean>;
}) => {
const [showDeleteDialog, setShowDeleteDialog] = useState<boolean>(false);

const {
control,
formState: { errors },
Expand All @@ -126,6 +134,10 @@ export const LOABasicInfo = ({
"",
);

const handleCancelDelete = () => {
setShowDeleteDialog(false);
};

const selectPermitType = (
permitType: keyof FieldPathValue<LOAFormData, "permitTypes">,
selected: boolean,
Expand Down Expand Up @@ -169,6 +181,7 @@ export const LOABasicInfo = ({
setValue("uploadFile", null);
clearErrors("uploadFile");
}
setShowDeleteDialog(false);
};

return (
Expand Down Expand Up @@ -328,7 +341,7 @@ export const LOABasicInfo = ({
{fileExists ? (
<UploadedFile
fileName={fileName}
onDelete={deleteFile}
onDelete={() => setShowDeleteDialog(true)}
/>
) : (
<UploadInput
Expand Down Expand Up @@ -363,6 +376,16 @@ export const LOABasicInfo = ({
className="loa-basic-info__notes"
/>
</div>

{showDeleteDialog ? (
<DeleteConfirmationDialog
showDialog={showDeleteDialog}
onCancel={handleCancelDelete}
onDelete={deleteFile}
itemToDelete="item"
confirmationMsg={"Are you sure you want to delete this?"}
/>
) : null}
</div>
);
};
Loading