11import { useState , useEffect } from "react" ;
2- import { useNavigate } from "@tanstack/react-router" ;
32import { BCDesignTokens } from "epic.theme" ;
43import { AllDocumentModel , DocumentStatus } from "@/models/Document" ;
5- import { Box , styled , Stack , FormControlLabel , Typography , Switch , Grid } from "@mui/material" ;
4+ import { Box , styled , Stack , Typography , Grid } from "@mui/material" ;
65import { ContentBoxSkeleton } from "../Shared/ContentBox/ContentBoxSkeleton" ;
76import { ContentBox } from "../Shared/ContentBox" ;
87import DocumentTable from "./DocumentTable" ;
@@ -22,28 +21,13 @@ type DocumentsParam = {
2221 documents ?: AllDocumentModel [ ] ;
2322 projectName : string ;
2423 projectId : string ;
25- categoryId : number ;
2624 documentLabel : string ;
2725} ;
2826
29- export const Documents = ( { projectName, projectId, categoryId, documentLabel, documents } : DocumentsParam ) => {
30- const navigate = useNavigate ( ) ;
31- const [ isToggled , setIsToggled ] = useState ( false ) ;
32- const [ isToggleEnabled , setIsToggleEnabled ] = useState < boolean | null > ( false ) ;
27+ export const Documents = ( { projectName, projectId, documentLabel, documents } : DocumentsParam ) => {
3328 const [ isAllApproved , setIsAllApproved ] = useState < boolean | null > ( false ) ;
3429
35- const handleToggle = ( event : React . ChangeEvent < HTMLInputElement > ) => {
36- const checked = event . target . checked ;
37- setIsToggled ( checked ) ;
38- if ( checked ) {
39- navigate ( {
40- to : `/projects/${ projectId } /document-category/${ categoryId } /consolidated-conditions` ,
41- } ) ;
42- }
43- } ;
44-
4530 useEffect ( ( ) => {
46- // Check if all amendments have status as true
4731 if ( documents && documents . length > 0 ) {
4832 const hasNullStatus = documents . some ( ( document ) => document . status === null ) ;
4933 if ( hasNullStatus ) {
@@ -52,18 +36,11 @@ export const Documents = ({ projectName, projectId, categoryId, documentLabel, d
5236 const allApproved = documents . every ( ( document ) => document . status === true ) ;
5337 setIsAllApproved ( allApproved ) ;
5438 }
55-
56- // Check if any document has is_latest_amendment_added as true
57- const hasLatestAmendment = documents . some ( doc => doc . is_latest_amendment_added === true ) ;
58- const anyLatestAmendmentAdded = hasNullStatus ? false : hasLatestAmendment ;
59-
60- setIsToggleEnabled ( anyLatestAmendmentAdded ) ;
6139 }
6240 } , [ documents ] ) ;
6341
6442 return (
6543 < Stack spacing = { 2 } direction = { "column" } sx = { { width : '100%' } } >
66- { /* Showing results message */ }
6744 < ContentBox
6845 mainLabel = {
6946 < Box component = "span" >
@@ -90,15 +67,14 @@ export const Documents = ({ projectName, projectId, categoryId, documentLabel, d
9067 } }
9168 >
9269 < Grid container direction = "row" paddingBottom = { 3 } >
93- < Grid item xs = { 6 } >
70+ < Grid item xs = { 12 } >
9471 < Box
9572 sx = { {
9673 px : 2.5 ,
97- display : "flex" , // Align items in a row
98- alignItems : "center" , // Vertically center the elements
74+ display : "flex" ,
75+ alignItems : "center" ,
9976 } }
10077 >
101- { /* Document Name and Icon */ }
10278 < Box sx = { { display : "flex" , alignItems : "center" } } >
10379 { documentLabel }
10480 < LayersOutlinedIcon fontSize = "small" sx = { { ml : 1 , mr : 1 } } />
@@ -108,19 +84,6 @@ export const Documents = ({ projectName, projectId, categoryId, documentLabel, d
10884 </ Box >
10985 </ Box >
11086 </ Grid >
111- < Grid item xs = { 6 } textAlign = "right" >
112- < FormControlLabel
113- control = {
114- < Switch
115- disabled = { ! isToggleEnabled } // Disable the switch based on the isToggleEnabled state
116- checked = { isToggled }
117- onChange = { handleToggle } // Add onChange handler to toggle and navigate
118- />
119- }
120- label = "View Consolidated Conditions"
121- labelPlacement = "end"
122- />
123- </ Grid >
12487 </ Grid >
12588 < Box height = { "100%" } px = { BCDesignTokens . layoutPaddingXsmall } >
12689 < CardInnerBox
0 commit comments