11import { useState , useEffect } from "react" ;
22import { BCDesignTokens } from "epic.theme" ;
3- import { AllDocumentModel , DocumentStatus } from "@/models/Document" ;
3+ import { AllDocumentModel , DocumentStatus , DocumentTypeModel } from "@/models/Document" ;
44import { Box , styled , Stack , Typography , Grid } from "@mui/material" ;
55import { ContentBoxSkeleton } from "../Shared/ContentBox/ContentBoxSkeleton" ;
66import { ContentBox } from "../Shared/ContentBox" ;
77import DocumentTable from "./DocumentTable" ;
88import DocumentStatusChip from "../Projects/DocumentStatusChip" ;
99import LayersOutlinedIcon from '@mui/icons-material/LayersOutlined' ;
10+ import AddIcon from '@mui/icons-material/Add' ;
11+ import LoadingButton from "../Shared/Buttons/LoadingButton" ;
12+ import { CreateDocumentModal } from "../Projects/CreateDocumentModal" ;
13+ import { ProjectModel } from "@/models/Project" ;
1014
1115export const CardInnerBox = styled ( Box ) ( {
1216 display : "flex" ,
@@ -21,11 +25,25 @@ type DocumentsParam = {
2125 documents ?: AllDocumentModel [ ] ;
2226 projectName : string ;
2327 projectId : string ;
28+ categoryId : number ;
2429 documentLabel : string ;
30+ project ?: ProjectModel ;
31+ documentType ?: DocumentTypeModel [ ] ;
2532} ;
2633
27- export const Documents = ( { projectName, projectId, documentLabel, documents } : DocumentsParam ) => {
34+ export const Documents = ( { projectName, projectId, categoryId , documentLabel, documents, project , documentType } : DocumentsParam ) => {
2835 const [ isAllApproved , setIsAllApproved ] = useState < boolean | null > ( false ) ;
36+ const [ openModal , setOpenModal ] = useState ( false ) ;
37+ const [ isOpeningModal , setIsOpeningModal ] = useState ( false ) ;
38+
39+ const handleOpenAddDocument = ( ) => {
40+ setIsOpeningModal ( true ) ;
41+ setOpenModal ( true ) ;
42+ } ;
43+
44+ const handleCloseAddDocument = ( ) => {
45+ setOpenModal ( false ) ;
46+ } ;
2947
3048 useEffect ( ( ) => {
3149 if ( documents && documents . length > 0 ) {
@@ -67,7 +85,7 @@ export const Documents = ({ projectName, projectId, documentLabel, documents }:
6785 } }
6886 >
6987 < Grid container direction = "row" paddingBottom = { 3 } >
70- < Grid item xs = { 12 } >
88+ < Grid item xs = { 6 } >
7189 < Box
7290 sx = { {
7391 px : 2.5 ,
@@ -84,6 +102,38 @@ export const Documents = ({ projectName, projectId, documentLabel, documents }:
84102 </ Box >
85103 </ Box >
86104 </ Grid >
105+ < Grid item xs = { 6 } textAlign = "right" sx = { { display : "flex" , alignItems : "center" , justifyContent : "flex-end" , gap : 2 } } >
106+ { project && documentType && (
107+ < LoadingButton
108+ variant = "contained"
109+ onClick = { handleOpenAddDocument }
110+ loading = { isOpeningModal }
111+ sx = { {
112+ display : "flex" ,
113+ padding : "8px 22px 7px 15px" ,
114+ alignItems : "center" ,
115+ gap : "14.178px" ,
116+ height : "70%" ,
117+ borderRadius : "4px" ,
118+ border : "2px solid #353433" ,
119+ backgroundColor : "#013366" ,
120+ color : "#FFF" ,
121+ textAlign : "center" ,
122+ fontFamily : '"BC Sans"' ,
123+ fontSize : "16px" ,
124+ fontStyle : "normal" ,
125+ fontWeight : 400 ,
126+ lineHeight : "27.008px" ,
127+ "&:hover" : {
128+ backgroundColor : "#002a52" ,
129+ border : "2px solid #353433" ,
130+ } ,
131+ } }
132+ >
133+ < AddIcon fontSize = "small" /> Add Document
134+ </ LoadingButton >
135+ ) }
136+ </ Grid >
87137 </ Grid >
88138 < Box height = { "100%" } px = { BCDesignTokens . layoutPaddingXsmall } >
89139 < CardInnerBox
@@ -98,6 +148,17 @@ export const Documents = ({ projectName, projectId, documentLabel, documents }:
98148 </ Typography >
99149 </ Box >
100150 </ ContentBox >
151+ { project && documentType && (
152+ < CreateDocumentModal
153+ open = { openModal }
154+ onClose = { handleCloseAddDocument }
155+ documentType = { documentType }
156+ projectArray = { [ project ] }
157+ preselectedProject = { project }
158+ restrictToCategoryId = { categoryId }
159+ onTransitionEnd = { ( ) => setIsOpeningModal ( false ) }
160+ />
161+ ) }
101162 </ Stack >
102163 ) ;
103164} ;
0 commit comments