Skip to content

Commit

Permalink
chore: refactoring activity, additional reporting data and new entran…
Browse files Browse the repository at this point in the history
…t form
  • Loading branch information
pbastia committed Dec 30, 2024
1 parent 94749ca commit 23afd14
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import safeJsonParse from "@bciers/utils/src/safeJsonParse";
import debounce from "lodash.debounce";
import { useSearchParams } from "next/navigation";
import MultiStepFormWithTaskList from "@bciers/components/form/MultiStepFormWithTaskList";
import { multiStepHeaderSteps } from "../taskList/multiStepHeaderConfig";
import { multiStepHeaderSteps } from "@reporting/src/app/components/taskList/multiStepHeaderConfig";
import { customizeValidator } from "@rjsf/validator-ajv8";

const CUSTOM_FIELDS = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
import React, { useState } from "react";
import MultiStepFormWithTaskList from "@bciers/components/form/MultiStepFormWithTaskList";
import { RJSFSchema } from "@rjsf/utils";
import { TaskListElement } from "@bciers/components/navigation/reportingTaskList/types";
import {
additionalReportingDataSchema,
additionalReportingDataUiSchema,
additionalReportingDataWithElectricityGeneratedSchema,
} from "@reporting/src/data/jsonSchema/additionalReportingData/additionalReportingData";
import { actionHandler } from "@bciers/actions";
import { useSearchParams } from "next/navigation";
import { multiStepHeaderSteps } from "@reporting/src/app/components/taskList/multiStepHeaderConfig";
import {
ActivePage,
getAdditionalInformationTaskList,
} from "../../taskList/3_additionalInformation";

interface AdditionalReportingDataProps {
versionId: number;
Expand Down Expand Up @@ -53,23 +57,6 @@ export default function AdditionalReportingDataForm({
? additionalReportingDataWithElectricityGeneratedSchema
: additionalReportingDataSchema;

const taskListElements: TaskListElement[] = [
{
type: "Page",
title: "Additional reporting data",
isActive: true,
link: `/reports/${versionId}/additional-reporting-data`,
},
];

if (isNewEntrant) {
taskListElements.push({
type: "Page",
title: "New entrant information",
link: `/reports/${versionId}/new-entrant-information`,
});
}

const handleSubmit = async (data: any) => {
const endpoint = `reporting/report-version/${versionId}/additional-data`;
const method = "POST";
Expand All @@ -90,14 +77,12 @@ export default function AdditionalReportingDataForm({
return (
<MultiStepFormWithTaskList
initialStep={2}
steps={[
"Operation Information",
"Report Information",
"Additional Information",
"Compliance Summary",
"Sign-off & Submit",
]}
taskListElements={taskListElements}
steps={multiStepHeaderSteps}
taskListElements={getAdditionalInformationTaskList(
versionId,
ActivePage.AdditionalReportingData,
isNewEntrant,
)}
schema={schema}
uiSchema={additionalReportingDataUiSchema}
formData={formData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default async function NewEntrantInformation({
const taskListElements = getAdditionalInformationTaskList(
version_id,
ActivePage.NewEntrantInformation,
true,
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import React, { useState } from "react";
import MultiStepFormWithTaskList from "@bciers/components/form/MultiStepFormWithTaskList";
import { TaskListElement } from "@bciers/components/navigation/reportingTaskList/types";
import { useRouter } from "next/navigation";

import { actionHandler } from "@bciers/actions";
import {
Expand Down Expand Up @@ -32,7 +31,6 @@ export default function NewEntrantInformationForm({
!initialFormData.assertion_statement,
);

const router = useRouter();
const saveAndContinueUrl = `/reports/${version_id}/compliance-summary`;

const handleChange = (e: IChangeEvent) => {
Expand All @@ -52,7 +50,7 @@ export default function NewEntrantInformationForm({
});
if (response.error) throw new Error(response.error);

router.push(saveAndContinueUrl);
return true;
};
return (
<MultiStepFormWithTaskList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@ export enum ActivePage {
"NewEntrantInformation",
}

export const getAdditionalInformationTaskList = (
export const getAdditionalInformationTaskList: (
versionId: number,
activeIndex?: ActivePage | number,
) => {
const taskListData: TaskListElement[] = [
{
type: "Page",
title: "Additional reporting data",
isChecked: true,
link: `/reports/${versionId}/additional-reporting-data`,
isActive: activeIndex === ActivePage.AdditionalReportingData,
},
{
type: "Page",
title: "New entrant information",
isActive: activeIndex === ActivePage.NewEntrantInformation,
link: `/reports/${versionId}/new-entrant-information`,
},
];
isNewEntrant?: boolean,
) => TaskListElement[] = (versionId, activeIndex, isNewEntrant) => {
const additionalReportingDataItem: TaskListElement = {
type: "Page",
title: "Additional reporting data",
isChecked: true,
link: `/reports/${versionId}/additional-reporting-data`,
isActive: activeIndex === ActivePage.AdditionalReportingData,
};

return taskListData;
const newEntrantItem: TaskListElement = {
type: "Page",
title: "New entrant information",
isActive: activeIndex === ActivePage.NewEntrantInformation,
link: `/reports/${versionId}/new-entrant-information`,
};

return isNewEntrant
? [additionalReportingDataItem, newEntrantItem]
: [additionalReportingDataItem];
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface Props {
steps: string[];
taskListElements: TaskListElement[];
onSubmit: () => void;
noFormSave: () => void;
children?: React.ReactNode;
cancelUrl?: string;
backUrl?: string;
Expand All @@ -33,6 +34,7 @@ const MultiStepWrapperWithTaskList: React.FC<Props> = ({
steps,
taskListElements,
onSubmit,
noFormSave,
children,
backUrl,
continueUrl,
Expand Down Expand Up @@ -62,6 +64,7 @@ const MultiStepWrapperWithTaskList: React.FC<Props> = ({
backUrl={backUrl}
continueUrl={continueUrl}
buttonText={submittingButtonText}
noFormSave={noFormSave}
saveAndContinue={onSubmit}
isRedirecting={isRedirecting}
isSaving={isSaving}
Expand Down

0 comments on commit 23afd14

Please sign in to comment.