Skip to content

Commit

Permalink
Add report prop to permit condition form and disable button if report…
Browse files Browse the repository at this point in the history
… exists

This commit introduces a new optional `report` prop to the `AddReportToPermitConditionForm` component, allowing it to use an existing report if available. Additionally, it modifies the permit condition layer to disable the "Add Report" button when a report already exists for the sub-condition, and ensures permits are refetched after adding a new report.
  • Loading branch information
matbusby-fw committed Oct 30, 2024
1 parent 54c0474 commit 7321bd4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ interface AddReportToPermitConditionFormProps {
permitGuid: string;
condition: IPermitCondition;
modalView?: boolean;
report?: IMineReport;
}

export const AddReportToPermitConditionForm: FC<AddReportToPermitConditionFormProps> = ({
onSubmit,
condition,
permitGuid,
modalView = true,
report,
}) => {
const report = condition?.report;
const [isEditMode, setIsEditMode] = React.useState(modalView);

return (
Expand All @@ -52,7 +53,7 @@ export const AddReportToPermitConditionForm: FC<AddReportToPermitConditionFormPr
? { ...report, stepPath: condition.stepPath }
: {
mine_report_status_code: MINE_REPORT_SUBMISSION_CODES.NON,
condition: condition.stepPath,
stepPath: condition.stepPath,
permit_condition_category_code: condition.condition_category_code,
permit_condition_type_code: REPORT_TYPE_CODES.PRR,
permit_condition_id: condition.permit_condition_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { closeModal, openModal } from "@mds/common/redux/actions/modalActions";
import { useParams } from "react-router-dom";
import { AddReportToPermitConditionForm } from "../../Forms/reports/AddReporttoPermitConditionForm";
import { createMineReport } from "@mds/common/redux/actionCreators/reportActionCreator";
import { fetchPermits } from "@mds/common/redux/actionCreators/permitActionCreator";

interface PermitConditionLayerProps {
condition: IPermitCondition;
Expand Down Expand Up @@ -61,6 +62,7 @@ const PermitConditionLayer: FC<PermitConditionLayerProps> = ({

const addNewReport = async (values) => {
await dispatch(createMineReport(mineGuid, values));
dispatch(fetchPermits(mineGuid));
dispatch(closeModal());
};

Expand Down Expand Up @@ -127,6 +129,7 @@ const PermitConditionLayer: FC<PermitConditionLayerProps> = ({
}}
icon={<FontAwesomeIcon icon={faClipboard} className="margin-medium--right" />}
type="default"
disabled={!!subCondition.report}
>
Add Report
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ const PermitConditions: FC<PermitConditionProps> = ({
onSubmit={() => {}}
condition={cond}
permitGuid={permitGuid}
report={cond.report}
/>
</Collapse.Panel>
))}
Expand Down

0 comments on commit 7321bd4

Please sign in to comment.