Skip to content

Commit 87b318e

Browse files
committed
chore: implement start past report flow
chore: revert
1 parent 594b5c7 commit 87b318e

10 files changed

Lines changed: 253 additions & 28 deletions

File tree

bciers/apps/administration/app/data/jsonSchema/operationInformation/administrationRegistrationInformation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export const createAdministrationRegistrationInformationSchema =
4141
throw new Error("Failed to retrieve reporting activities information");
4242
// fetch valid reporting years for OptedOutOperation dropdown
4343
const validReportingYears: { reporting_year: number }[] =
44-
// NOTE: getReportingYears() includes optional query param exclude_past.
45-
// Not using it immediately due to timing of opt-out feature rollout relative to reporting year,
44+
// NOTE: getReportingYears() includes optional query param scope.
45+
// Not using it here immediately due to timing of opt-out feature rollout relative to reporting year,
4646
// but will be able to make use of this feature in the future to simplify the dropdown list
4747
await getReportingYears();
4848
if (validReportingYears && "error" in validReportingYears)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import defaultPageFactory from "@bciers/components/nextPageFactory/defaultPageFactory";
2+
import Page from "@reporting/src/app/components/report/StartReportPage";
3+
4+
export default defaultPageFactory(Page);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import defaultPageFactory from "@bciers/components/nextPageFactory/defaultPageFactory";
2+
import Page from "@reporting/src/app/components/report/StartReportPage";
3+
4+
export default defaultPageFactory(Page);

bciers/apps/reporting/src/app/components/operations/PastReports.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1-
import PastReports from "./PastReports";
2-
import { ReportSearchParams } from "./types";
1+
import Link from "next/link";
2+
import { fetchPastReportsPageData } from "./fetchPastReportsPageData";
3+
import PastReportsDataGrid from "./PastReportsDataGrid";
4+
import { ReportRow, ReportSearchParams } from "./types";
35

46
export default async function PastReportsPage({
57
searchParams,
68
}: {
79
searchParams: ReportSearchParams;
810
}) {
9-
return <PastReports searchParams={searchParams} />;
11+
const pastReports: { rows: ReportRow[]; row_count: number } =
12+
await fetchPastReportsPageData(searchParams);
13+
14+
const buttonStartReport = (
15+
<div className="flex w-full justify-end pb-6">
16+
<Link
17+
className="link-button-blue"
18+
href="../reports/previous-years/start-a-report"
19+
>
20+
Start a Report
21+
</Link>
22+
</div>
23+
);
24+
25+
return (
26+
<div className="mt-5">
27+
{buttonStartReport}
28+
<PastReportsDataGrid initialData={pastReports} />
29+
</div>
30+
);
1031
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"use client";
2+
3+
import { useState } from "react";
4+
import { Alert, Button } from "@mui/material";
5+
import { actionHandler } from "@bciers/actions";
6+
import FormBase from "@bciers/components/form/FormBase";
7+
import { RJSFSchema, UiSchema } from "@rjsf/utils";
8+
import { useRouter } from "next/navigation";
9+
10+
interface StartReportFormProps {
11+
schema: RJSFSchema;
12+
uiSchema: UiSchema;
13+
}
14+
15+
interface StartReportFormData {
16+
reporting_year?: number;
17+
reporting_operation?: string;
18+
}
19+
20+
export default function StartReportForm({
21+
schema,
22+
uiSchema,
23+
}: StartReportFormProps) {
24+
const router = useRouter();
25+
const [formData, setFormData] = useState<StartReportFormData>({});
26+
const [errorList, setErrorList] = useState([] as any[]);
27+
28+
const submitHandler = async (data: { formData?: StartReportFormData }) => {
29+
setErrorList([]);
30+
31+
const response = await actionHandler(
32+
"reporting/reports/start",
33+
"POST",
34+
"/reports/start",
35+
{
36+
body: JSON.stringify({
37+
reporting_year: data.formData?.reporting_year,
38+
operation_id: data.formData?.reporting_operation,
39+
}),
40+
},
41+
);
42+
43+
if (response.error) {
44+
setErrorList([{ message: response.error }]);
45+
return;
46+
}
47+
48+
window.location.href = `/reports/${response.report_version_id}`;
49+
};
50+
51+
return (
52+
<FormBase
53+
formData={formData}
54+
schema={schema}
55+
uiSchema={uiSchema}
56+
onChange={(data: any) => setFormData(data.formData)}
57+
onSubmit={submitHandler}
58+
>
59+
{errorList.length > 0 &&
60+
errorList.map((e: any) => (
61+
<Alert key={e.message} severity="error">
62+
{e?.stack ?? e.message}
63+
</Alert>
64+
))}
65+
66+
<div className="flex justify-between pt-6">
67+
<Button
68+
variant="outlined"
69+
onClick={() => router.back()}
70+
className="min-w-[120px] border-bc-blue py-2.5 text-bc-links hover:border-bc-primary-blue"
71+
>
72+
Back
73+
</Button>
74+
75+
<Button
76+
variant="contained"
77+
type="submit"
78+
className="min-w-[120px] bg-bc-blue py-2.5 hover:bg-bc-primary-blue"
79+
>
80+
Start Report
81+
</Button>
82+
</div>
83+
</FormBase>
84+
);
85+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { createStartReportSchemas } from "@reporting/src/data/jsonSchema/report/startReport";
2+
import StartReportForm from "@reporting/src/app/components/report/StartReportForm";
3+
4+
export default async function StartReportPage() {
5+
const { schema, uiSchema } = await createStartReportSchemas();
6+
7+
return (
8+
<div className="mt-5">
9+
<StartReportForm schema={schema} uiSchema={uiSchema} />
10+
</div>
11+
);
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export interface ReportHistoryRow {
2+
id: number;
3+
version: string;
4+
updated_at: string;
5+
status: string;
6+
report_type: string;
7+
submitted_by: string;
8+
}
9+
export interface ReportHistorySearchParams {
10+
[key: string]: string | number | undefined;
11+
version?: string;
12+
updated_at?: string;
13+
status?: number;
14+
report_type?: string;
15+
submitted_by?: string;
16+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import FieldTemplate from "@bciers/components/form/fields/FieldTemplate";
2+
import { RJSFSchema, UiSchema } from "@rjsf/utils";
3+
import {
4+
getReportingYears,
5+
getCurrentUsersOperations,
6+
} from "@bciers/actions/api";
7+
8+
type ReportingYear = {
9+
reporting_year: number;
10+
};
11+
12+
type ReportingOperation = {
13+
id: string;
14+
name: string;
15+
reporting_year: number;
16+
};
17+
18+
interface CombinedRJSFSchemas {
19+
schema: RJSFSchema;
20+
uiSchema: UiSchema;
21+
}
22+
23+
export const createStartReportSchemas =
24+
async (): Promise<CombinedRJSFSchemas> => {
25+
const [reportingYears, operations]: [
26+
ReportingYear[],
27+
ReportingOperation[],
28+
] = await Promise.all([
29+
getReportingYears("past"),
30+
getCurrentUsersOperations(),
31+
]);
32+
33+
const schema: RJSFSchema = {
34+
type: "object",
35+
title: "Start a Report",
36+
37+
required: ["reporting_year", "reporting_operation"],
38+
39+
properties: {
40+
reporting_year: {
41+
type: "number",
42+
title: "Reporting Year",
43+
anyOf: reportingYears.map((year) => ({
44+
const: year.reporting_year,
45+
title: String(year.reporting_year),
46+
})),
47+
},
48+
49+
reporting_operation: {
50+
type: "string",
51+
title: "Reporting Operation",
52+
},
53+
},
54+
55+
dependencies: {
56+
reporting_year: {
57+
oneOf: reportingYears.map((year) => ({
58+
properties: {
59+
reporting_year: {
60+
const: year.reporting_year,
61+
},
62+
63+
reporting_operation: {
64+
type: "string",
65+
title: "Reporting Operation",
66+
anyOf: operations
67+
.filter(
68+
(operation) =>
69+
operation.reporting_year === year.reporting_year,
70+
)
71+
.map((operation) => ({
72+
const: operation.id,
73+
title: operation.name,
74+
})),
75+
},
76+
},
77+
})),
78+
},
79+
},
80+
};
81+
82+
const uiSchema: UiSchema = {
83+
"ui:FieldTemplate": FieldTemplate,
84+
"ui:classNames": "form-heading-label",
85+
86+
reporting_year: {
87+
"ui:widget": "ComboBox",
88+
"ui:placeholder": "Select Reporting Year",
89+
},
90+
91+
reporting_operation: {
92+
"ui:widget": "ComboBox",
93+
"ui:placeholder": "Select Reporting Operation",
94+
},
95+
};
96+
97+
return {
98+
schema,
99+
uiSchema,
100+
};
101+
};

bciers/libs/actions/src/api/getReportingYears.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { actionHandler } from "@bciers/actions";
22

3-
async function getReportingYears(exclude_past?: boolean) {
4-
const query = exclude_past ? `?exclude_past=${exclude_past}` : "";
3+
export type ReportingYearScope = "all" | "past";
4+
5+
async function getReportingYears(scope: ReportingYearScope = "all") {
6+
const query = scope === "all" ? "" : `?scope=${scope}`;
7+
58
return actionHandler(`reporting/reporting-years${query}`, "GET", "");
69
}
710

0 commit comments

Comments
 (0)