11import { useState , useEffect } from "react" ;
22import { useNavigate } from "@tanstack/react-router" ;
33import { BCDesignTokens } from "epic.theme" ;
4- import { AllDocumentModel , DocumentStatus } from "@/models/Document" ;
4+ import { AllDocumentModel , DocumentStatus , DocumentTypeModel } from "@/models/Document" ;
55import { Box , styled , Stack , FormControlLabel , Typography , Switch , Grid } from "@mui/material" ;
66import { ContentBoxSkeleton } from "../Shared/ContentBox/ContentBoxSkeleton" ;
77import { ContentBox } from "../Shared/ContentBox" ;
88import DocumentTable from "./DocumentTable" ;
99import DocumentStatusChip from "../Projects/DocumentStatusChip" ;
1010import LayersOutlinedIcon from '@mui/icons-material/LayersOutlined' ;
11+ import AddIcon from '@mui/icons-material/Add' ;
12+ import LoadingButton from "../Shared/Buttons/LoadingButton" ;
13+ import { CreateDocumentModal } from "../Projects/CreateDocumentModal" ;
14+ import { ProjectModel } from "@/models/Project" ;
1115
1216export const CardInnerBox = styled ( Box ) ( {
1317 display : "flex" ,
@@ -24,13 +28,26 @@ type DocumentsParam = {
2428 projectId : string ;
2529 categoryId : number ;
2630 documentLabel : string ;
31+ project ?: ProjectModel ;
32+ documentType ?: DocumentTypeModel [ ] ;
2733} ;
2834
29- export const Documents = ( { projectName, projectId, categoryId, documentLabel, documents } : DocumentsParam ) => {
35+ export const Documents = ( { projectName, projectId, categoryId, documentLabel, documents, project , documentType } : DocumentsParam ) => {
3036 const navigate = useNavigate ( ) ;
3137 const [ isToggled , setIsToggled ] = useState ( false ) ;
3238 const [ isToggleEnabled , setIsToggleEnabled ] = useState < boolean | null > ( false ) ;
3339 const [ isAllApproved , setIsAllApproved ] = useState < boolean | null > ( false ) ;
40+ const [ openModal , setOpenModal ] = useState ( false ) ;
41+ const [ isOpeningModal , setIsOpeningModal ] = useState ( false ) ;
42+
43+ const handleOpenAddDocument = ( ) => {
44+ setIsOpeningModal ( true ) ;
45+ setOpenModal ( true ) ;
46+ } ;
47+
48+ const handleCloseAddDocument = ( ) => {
49+ setOpenModal ( false ) ;
50+ } ;
3451
3552 const handleToggle = ( event : React . ChangeEvent < HTMLInputElement > ) => {
3653 const checked = event . target . checked ;
@@ -108,13 +125,43 @@ export const Documents = ({ projectName, projectId, categoryId, documentLabel, d
108125 </ Box >
109126 </ Box >
110127 </ Grid >
111- < Grid item xs = { 6 } textAlign = "right" >
128+ < Grid item xs = { 6 } textAlign = "right" sx = { { display : "flex" , alignItems : "center" , justifyContent : "flex-end" , gap : 2 } } >
129+ { project && documentType && (
130+ < LoadingButton
131+ variant = "contained"
132+ onClick = { handleOpenAddDocument }
133+ loading = { isOpeningModal }
134+ sx = { {
135+ display : "flex" ,
136+ padding : "8px 22px 7px 15px" ,
137+ alignItems : "center" ,
138+ gap : "14.178px" ,
139+ height : "70%" ,
140+ borderRadius : "4px" ,
141+ border : "2px solid #353433" ,
142+ backgroundColor : "#013366" ,
143+ color : "#FFF" ,
144+ textAlign : "center" ,
145+ fontFamily : '"BC Sans"' ,
146+ fontSize : "16px" ,
147+ fontStyle : "normal" ,
148+ fontWeight : 400 ,
149+ lineHeight : "27.008px" ,
150+ "&:hover" : {
151+ backgroundColor : "#002a52" ,
152+ border : "2px solid #353433" ,
153+ } ,
154+ } }
155+ >
156+ < AddIcon fontSize = "small" /> Add Document
157+ </ LoadingButton >
158+ ) }
112159 < FormControlLabel
113160 control = {
114161 < Switch
115- disabled = { ! isToggleEnabled } // Disable the switch based on the isToggleEnabled state
162+ disabled = { ! isToggleEnabled }
116163 checked = { isToggled }
117- onChange = { handleToggle } // Add onChange handler to toggle and navigate
164+ onChange = { handleToggle }
118165 />
119166 }
120167 label = "View Consolidated Conditions"
@@ -135,6 +182,17 @@ export const Documents = ({ projectName, projectId, categoryId, documentLabel, d
135182 </ Typography >
136183 </ Box >
137184 </ ContentBox >
185+ { project && documentType && (
186+ < CreateDocumentModal
187+ open = { openModal }
188+ onClose = { handleCloseAddDocument }
189+ documentType = { documentType }
190+ projectArray = { [ project ] }
191+ preselectedProject = { project }
192+ restrictToCategoryId = { categoryId }
193+ onTransitionEnd = { ( ) => setIsOpeningModal ( false ) }
194+ />
195+ ) }
138196 </ Stack >
139197 ) ;
140198} ;
0 commit comments