Skip to content

Commit

Permalink
chore: prevent save and continue on error
Browse files Browse the repository at this point in the history
  • Loading branch information
shon-button committed Dec 20, 2024
1 parent 1d89f6e commit 49a12c6
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ export default function FacilityEmissionAllocationForm({

if (response?.error) {
setError(response.error);
return false;
} else {
setError(undefined);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function OperationReviewForm({
const [formDataState, setFormDataState] = useState<any>(formData);
const [facilityId, setFacilityId] = useState<number | null>(null);
const [operationType, setOperationType] = useState("");
const [error, setError] = useState(undefined);

// 🛸 Set up routing urls
const backUrl = `/reports`;
Expand Down Expand Up @@ -159,14 +160,18 @@ export default function OperationReviewForm({
) => {
const method = "POST";
const endpoint = `reporting/report-version/${reportVersionId}/report-operation`;

const formDataObject = safeJsonParse(JSON.stringify(data.formData));
const preparedData = prepareFormData(formDataObject);
const preparedData = prepareFormData(data.formData);
const payload = safeJsonParse(JSON.stringify(preparedData));
const response = await actionHandler(endpoint, method, endpoint, {
body: JSON.stringify(preparedData),
body: payload,
});

return response;
if (response?.error) {
setError(response.error);
return false;
} else {
setError(undefined);
}
};

const onChangeHandler = (data: { formData: any }) => {
Expand Down Expand Up @@ -221,6 +226,7 @@ export default function OperationReviewForm({
onChange={onChangeHandler}
backUrl={backUrl}
continueUrl={saveAndContinueUrl}
error={error}
/>
);
}
25 changes: 0 additions & 25 deletions bciers/apps/reporting/src/app/components/operations/Operations.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { fetchOperationsPageData } from "./fetchOperationsPageData";
import operationColumns from "../datagrid/models/operations/operationColumns";
import { OperationRow } from "./types";

const ReportingOperationDataGrid = ({
const OperationsDataGrid = ({
initialData,
}: {
initialData: {
Expand Down Expand Up @@ -41,4 +41,4 @@ const ReportingOperationDataGrid = ({
);
};

export default ReportingOperationDataGrid;
export default OperationsDataGrid;
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { getReportingYear } from "@reporting/src/app/utils/getReportingYear";
import Operations from "apps/reporting/src/app/components/operations/Operations";
import { OperationsSearchParams } from "apps/reporting/src/app/components/operations/types";
import {
OperationRow,
OperationsSearchParams,
} from "apps/reporting/src/app/components/operations/types";
import { formatDate } from "@reporting/src/app/utils/formatDate";
import { fetchOperationsPageData } from "@reporting/src/app/components/operations/fetchOperationsPageData";
import OperationsDataGrid from "@reporting/src/app/components/operations/OperationsDataGrid";

export default async function OperationsPage({
searchParams,
Expand All @@ -14,6 +19,17 @@ export default async function OperationsPage({
reportingYearObj.report_due_date,
"MMM DD,YYYY",
);

// Fetch operations data
const operations: {
rows: OperationRow[];
row_count: number;
} = await fetchOperationsPageData(searchParams);

if (!operations) {
return <div>No operations data in database.</div>;
}
// Render the DataGrid component
return (
<>
<div className="flex justify-between items-center">
Expand All @@ -22,7 +38,9 @@ export default async function OperationsPage({
</h2>
<h3 className="text-bc-text text-right">Reports due {reportDueDate}</h3>
</div>
<Operations searchParams={searchParams} />
<div className="mt-5">
<OperationsDataGrid initialData={operations} />
</div>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function VerificationForm({

if (response?.error) {
setError(response.error);
return;
return false;
} else {
setError(undefined);
}
Expand Down
10 changes: 8 additions & 2 deletions bciers/libs/components/src/form/MultiStepFormWithTaskList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ const MultiStepFormWithTaskList: React.FC<Props> = ({
const handleFormSave = async (data: any) => {
setIsSaving(true);
try {
await onSubmit(data);
if (canContinue) {
const response = await onSubmit(data);
let newCanContinue = true;
// Check the response to proceed
if (response !== undefined) {
newCanContinue = !!response;
setCanContinue(newCanContinue);
}
if (canContinue && newCanContinue) {
setIsRedirecting(true);
router.push(continueUrl);
} else {
Expand Down

0 comments on commit 49a12c6

Please sign in to comment.