Skip to content

Commit

Permalink
Merge pull request #183 from nitheesh-aot/requirements
Browse files Browse the repository at this point in the history
Requirements
  • Loading branch information
nitheesh-aot authored Dec 31, 2024
2 parents 79f5459 + 416f073 commit 83e758b
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,28 @@ const InspectionFileTabs: React.FC<InspectionFileTabsProps> = () => {
<Tabs
value={currentTab}
onChange={handleChange}
TabIndicatorProps={{
style: {
background: BCDesignTokens.surfaceColorBorderDark,
},
}}
sx={{
minHeight: "36px",
marginTop: "-0.5rem",
paddingLeft: "3.75rem",
"& .MuiTabs-flexContainer": {
gap: "1rem",
},
"& .MuiTab-root": {
paddingX: "0.5rem",
"&:first-of-type": {
paddingLeft: "0",
},
},
"& .Mui-selected": {
color: BCDesignTokens.typographyColorPrimary,
fontWeight: BCDesignTokens.typographyFontWeightsBold,
},
}}
>
<Tab label="Details" sx={tabStyle} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ const InspectionGeneralInformation: React.FC<
key={property.name}
propertyName={property.name}
propertyValue={property.value}
linksList={property.link ? [property.value] : null}
linkRoute={property.link ? "/ce-database/case-files" : null}
linksList={property.link ? [property.value] : undefined}
linkRoute={property.link ? "/ce-database/case-files" : undefined}
/>
))}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ const RequirementFormSchema = yup.object().shape({
complianceFinding: yup
.object<IRType>()
.nullable()
.required("Primary is required"),
.required("Compliance Finding is required"),
enforcementAction: yup
.array()
.of(yup.object<IRStatus>())
.min(1, "At least one Type is required")
.required("Type is required"),
.min(1, "At least one Enforcement Action is required")
.required("Enforcement Action is required"),
findings: yup
.object({
html: yup.string().required("Entry is required"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { FC } from "react";
import { FC, useState } from "react";
import { Box, Button } from "@mui/material";
import { AddRounded } from "@mui/icons-material";
import { useModal } from "@/store/modalStore";
import { notify } from "@/store/snackbarStore";
import RequirementSourceModal from "./RequirementSourceModal";

import { RequirementSourceFormData } from "@/models/InspectionRequirement";
import RequirementSourceCard from "./RequirementSourceCard";

const RequirementFormRight: FC = () => {
const { setOpen, setClose } = useModal();
const [requirementSourceFormData, setRequirementSourceFormData] = useState<
RequirementSourceFormData[]
>([]);

const handleOnSubmit = (submitMsg: string) => {
const handleOnSubmit = (data: RequirementSourceFormData) => {
setClose();
notify.success(submitMsg);
// eslint-disable-next-line no-console
console.log(data);
setRequirementSourceFormData((prevData) => [...prevData, data]);
};

const handleAddRequirementSourceModal = () => {
setOpen({
content: <RequirementSourceModal onSubmit={handleOnSubmit} />,
Expand All @@ -24,21 +29,22 @@ const RequirementFormRight: FC = () => {
return (
<Box
sx={{
paddingTop: "1.5rem",
paddingX: "1rem",
padding: "1.5rem 1rem",
width: "510px",
overflow: "auto",
boxSizing: "border-box",
}}
>
<Button
variant="outlined"
color="primary"
color="secondary"
onClick={handleAddRequirementSourceModal}
startIcon={<AddRounded />}
>
Requirement Source
</Button>
{requirementSourceFormData.map((data, index) => (
<RequirementSourceCard key={index} data={data} index={index} />
))}
</Box>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import { FC, memo, useState } from "react";
import {
Box,
Typography,
Button,
Stack,
Accordion,
AccordionSummary,
AccordionDetails,
IconButton,
Tooltip,
} from "@mui/material";
import {
AddRounded,
DeleteOutlineRounded,
EditOutlined,
ExpandLessRounded,
ExpandMoreRounded,
PostAddOutlined,
} from "@mui/icons-material";
import { RequirementSourceFormData } from "@/models/InspectionRequirement";
import { BCDesignTokens } from "epic.theme";
import ParagraphWithReadMore from "@/components/Shared/ParagraphWithReadMore";
import { RequirementSourceEnum } from "@/utils/constants";

type RequirementSourceCardProps = {
data: RequirementSourceFormData;
index: number;
};

const RequirementSourceCard: FC<RequirementSourceCardProps> = memo(
({ data, index }) => {
const [isExpanded, setIsExpanded] = useState(index === 0);

const isCondition = [
RequirementSourceEnum.SCHEDULE_B,
RequirementSourceEnum.EAC,
RequirementSourceEnum.EACA,
].includes(data.requirementSource?.id as RequirementSourceEnum);

return (
<Accordion
expanded={isExpanded}
onChange={(_, expanded) => {
setIsExpanded(expanded);
}}
sx={{
marginTop: "1rem",
border: `1px solid ${BCDesignTokens.surfaceColorBorderDefault}`,
borderRadius: BCDesignTokens.layoutBorderRadiusMedium,
"&.Mui-expanded:first-of-type": {
marginTop: "1rem",
},
}}
>
<AccordionSummary
aria-controls={`panel${index}-content`}
id={`requirement-source-panel${index}-header`}
sx={{
"&.Mui-expanded": {
minHeight: "48px",
padding: "0.875rem 1rem",
borderBottom: `1px solid ${BCDesignTokens.surfaceColorBorderDefault}`,
backgroundColor: BCDesignTokens.surfaceColorBackgroundLightGray,
"& .MuiAccordionSummary-content": {
margin: "0",
},
},
"& .MuiAccordionSummary-content": {
display: "flex",
justifyContent: "space-between",
gap: "1rem",
},
}}
>
<Box display={"flex"} alignItems={"flex-start"} gap={0.5}>
{isExpanded ? <ExpandLessRounded /> : <ExpandMoreRounded />}
<Typography variant="body2" fontWeight={700}>
{data.requirementSource?.name}
{data.requirementSource?.id === RequirementSourceEnum.EACA &&
` #${data.sourceAmendmentNumber}`}
</Typography>
</Box>
<Button
variant="text"
color="secondary"
size="small"
onClick={(e) => {
e.stopPropagation();
}}
startIcon={<AddRounded />}
sx={{
backgroundColor: "transparent",
paddingY: 0,
height: "auto",
"& .MuiButton-startIcon": {
mr: 0,
},
}}
>
{isCondition ? "Condition" : "Section"}
</Button>
</AccordionSummary>
<AccordionDetails>
<Stack>
<Box display={"flex"} justifyContent={"flex-end"} gap={".25rem"}>
<Tooltip title="Add Related Document" arrow>
<IconButton size="small" color="secondary">
<PostAddOutlined />
</IconButton>
</Tooltip>
<Tooltip title="Edit" arrow>
<IconButton size="small" color="secondary">
<EditOutlined />
</IconButton>
</Tooltip>
<Tooltip title="Delete" arrow>
<IconButton size="small" color="secondary">
<DeleteOutlineRounded />
</IconButton>
</Tooltip>
</Box>
<Box
sx={{
display: "flex",
flexDirection: "row",
gap: "1rem",
marginBottom: ".5rem",
}}
>
<Box>
<Typography
variant="subtitle2"
color={BCDesignTokens.typographyColorPlaceholder}
>
{isCondition ? "Condition #:" : "Section #:"}
</Typography>
<Typography variant="body2" fontWeight={700}>
{data.sourceNumber}
</Typography>
</Box>
<Box>
<Typography
variant="subtitle2"
color={BCDesignTokens.typographyColorPlaceholder}
>
Title:
</Typography>
<Typography variant="body2" fontWeight={700}>
{data.sourceTitle}
</Typography>
</Box>
</Box>
<Box>
<Typography
variant="subtitle2"
color={BCDesignTokens.typographyColorPlaceholder}
>
Description:
</Typography>
<ParagraphWithReadMore
maxHeight={84}
renderTypography={
<Typography variant="body2" display={"flex"} flex={1}>
{data.description?.text}
</Typography>
}
/>
</Box>
</Stack>
</AccordionDetails>
</Accordion>
);
}
);

export default RequirementSourceCard;
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { useRequirementSourcesData } from "@/hooks/useComplaints";
import { RequirementSourceEnum } from "@/utils/constants";

type RequirementSourceModalProps = {
onSubmit: (submitMsg: string) => void;
onSubmit: (data: RequirementSourceFormData) => void;
};

const requirementSourceFormSchema = yup.object().shape({
requirementSource: yup
.object<RequirementSource>()
.nullable()
.required("Name is required"),
.required("Requirement Source is required"),
sourceNumber: yup.string().nullable(),
sourceTitle: yup.string().nullable(),
sourceAmendmentNumber: yup.string().nullable(),
Expand Down Expand Up @@ -72,14 +72,10 @@ const RequirementSourceModal: React.FC<RequirementSourceModalProps> = ({
reset(defaultValues);
}, [defaultValues, reset]);

const onSuccess = () => {
onSubmit("Successfully added!");
};

const onSubmitHandler = (data: RequirementSourceSchemaType) => {
// eslint-disable-next-line no-console
console.log(data);
onSuccess();
onSubmit(data as RequirementSourceFormData);
};

return (
Expand Down

0 comments on commit 83e758b

Please sign in to comment.