diff --git a/src/pages/tenant/standards/bpa-report/builder.js b/src/pages/tenant/standards/bpa-report/builder.js
index 9ccbec216736..b943e243ec21 100644
--- a/src/pages/tenant/standards/bpa-report/builder.js
+++ b/src/pages/tenant/standards/bpa-report/builder.js
@@ -4,19 +4,14 @@ import {
Container,
Typography,
Button,
- FormControl,
- InputLabel,
- Select,
- MenuItem,
Grid,
IconButton,
Stack,
SvgIcon,
} from "@mui/material";
import { useEffect, useState } from "react";
-import Head from "next/head";
import DeleteIcon from "@mui/icons-material/Delete";
-import { useForm } from "react-hook-form";
+import { useForm, useWatch } from "react-hook-form";
import CippButtonCard from "../../../../components/CippCards/CippButtonCard";
import CippFormComponent from "../../../../components/CippComponents/CippFormComponent";
import { ArrowLeftIcon } from "@mui/x-date-pickers";
@@ -25,6 +20,7 @@ import { CippFormCondition } from "../../../../components/CippComponents/CippFor
import { ApiGetCall, ApiPostCall } from "../../../../api/ApiCall";
import { CippApiResults } from "../../../../components/CippComponents/CippApiResults";
import { CippHead } from "../../../../components/CippComponents/CippHead";
+import { Add, Save } from "@mui/icons-material";
const Page = () => {
const router = useRouter();
@@ -55,18 +51,28 @@ const Page = () => {
template.name = `${template.name} (Clone)`;
}
setLayoutMode(template.style);
- //if the template style is tenant, create enough cards to hold the frontend fields
- if (template.style === "Tenant") {
- setBlockCards(
- template.Fields.map((field, index) => {
- return {
- id: `block-${index}`,
- };
- })
- );
- }
+ setBlockCards(
+ template.Fields.map((field, index) => {
+ return {
+ id: `block-${index}`,
+ };
+ })
+ );
+
+ const convertedTemplate = {
+ ...template,
+ Fields: template.Fields.map((field) => ({
+ ...field,
+ ExtractFields: field.ExtractFields
+ ? field.ExtractFields.map((ef) => ({
+ label: ef,
+ value: ef,
+ }))
+ : [],
+ })),
+ };
- formControl.reset(template);
+ formControl.reset(convertedTemplate);
}
}
}, [bpaTemplateList.isSuccess]);
@@ -152,10 +158,9 @@ const Page = () => {
addBPATemplate.mutate({ url: "/api/AddBPATemplate", data: cleanedData });
};
- const handleLayoutModeChange = (event) => {
- const newMode = event.target.value;
+ const handleLayoutModeChange = (newMode) => {
setLayoutMode(newMode);
- formControl.setValue("style", newMode);
+ //formControl.setValue("style", newMode);
// Reset cards based on the layout mode
if (newMode === "Table") {
@@ -175,6 +180,14 @@ const Page = () => {
}
};
+ const style = useWatch({ control: formControl.control, name: "style" });
+
+ useEffect(() => {
+ if (style && style !== layoutMode) {
+ handleLayoutModeChange(style);
+ }
+ }, [style]);
+
const onSubmit = (data) => {};
return (
<>
@@ -209,55 +222,43 @@ const Page = () => {
-
>
}
title="Report Settings"
>
-
+
{/* First item for Report Name and Layout Mode */}
-
- Layout Mode
-
-
+
-
- {/* Third item for Buttons */}
- {layoutMode === "Tenant" && (
-
-
-
- Add Frontend Card
-
-
-
- )}
- {/* Canvas Area */}
-
- Canvas
-
+
+ Fields
+ }>
+ Add Field
+
+
{blockCards.map((block, index) => (
@@ -269,16 +270,16 @@ const Page = () => {
key={block.id}
>
handleRemoveBlock(block.id)} // Remove block on click
- >
-
-
- )
+ handleRemoveBlock(block.id)} // Remove block on click
+ >
+
+
}
>
{/* Form inside each card */}
@@ -310,7 +311,8 @@ const Page = () => {
@@ -477,13 +479,17 @@ const Page = () => {
type="autoComplete"
formControl={formControl}
multiple={false}
- api={{
- queryKey: `ListBPA`,
- url: "/api/ListBPA",
- dataKey: "Keys",
- labelField: (option) => `${option}`,
- valueField: (option) => `${option}`,
- }}
+ options={
+ bpaTemplateList.data
+ ?.flatMap(
+ (template) => template.Fields?.map((field) => field.name) ?? []
+ )
+ .filter(
+ (value, index, self) => value && self.indexOf(value) === index
+ )
+ .map((field) => ({ label: field, value: field }))
+ .sort((a, b) => a.label.localeCompare(b.label)) ?? []
+ }
/>