Skip to content

Commit 7f8f84b

Browse files
committed
#3885: Refactored and finished UI
1 parent e0e9d8a commit 7f8f84b

3 files changed

Lines changed: 36 additions & 21 deletions

File tree

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/BOM/MaterialForm/BOMCopyConfirmModal.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
import { Console } from 'console';
21
import NERModal from '../../../../../components/NERModal';
32

43
export interface BOMCopyConfirmModalProps {
54
open: boolean;
65
onHide: () => void;
76
onSuccess?: () => void;
7+
materialsCount: number;
8+
sourceProjectName: string;
9+
currentProjectName: string;
810
}
911

10-
const BOMCopyConfirmModal = ({ open, onHide, onSuccess }: BOMCopyConfirmModalProps) => {
11-
// TODO: make the actual message
12+
const BOMCopyConfirmModal = ({
13+
open,
14+
onHide,
15+
onSuccess,
16+
materialsCount,
17+
sourceProjectName,
18+
currentProjectName
19+
}: BOMCopyConfirmModalProps) => {
20+
const message = `Are you sure you want to copy ${materialsCount} materials from ${sourceProjectName} to ${currentProjectName}?`;
1221
return (
1322
<NERModal open={open} onHide={onHide} onSubmit={onSuccess} title="Confirm Copy">
14-
Are you sure you want to copy [X] materials from [Source Project Name] to [Current Project Name]?
23+
<p>{message}</p>
1524
</NERModal>
1625
);
1726
};

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/BOM/MaterialForm/MaterialFormView.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
Button,
32
FormControl,
43
FormHelperText,
54
FormLabel,
@@ -23,7 +22,6 @@ import { displayEnum } from '../../../../../utils/pipes';
2322
import { MaterialStatus } from 'shared';
2423
import React from 'react';
2524
import { AddCircle } from '@mui/icons-material';
26-
import BOMCopyConfirmModal from './BOMCopyConfirmModal';
2725

2826
export interface MaterialFormViewProps {
2927
submitText: 'Add' | 'Edit';
@@ -72,7 +70,6 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
7270
const quantity = watch('quantity');
7371
const price = watch('price');
7472
const subtotal = quantity && price ? quantity * price : 0;
75-
const [bomConfirmOpen, setBomConfirmOpen] = React.useState(false);
7673

7774
return (
7875
<NERFormModal
@@ -487,7 +484,7 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
487484
pt: 1
488485
}}
489486
>
490-
<Button
487+
{/* <Button
491488
variant="contained"
492489
disableElevation
493490
onClick={() => {
@@ -503,17 +500,10 @@ const MaterialFormView: React.FC<MaterialFormViewProps> = ({
503500
}}
504501
>
505502
COPY FROM EXISTING BOM
506-
</Button>
503+
</Button> */}
507504
</Box>
508505
</Grid>
509506
)}
510-
<BOMCopyConfirmModal
511-
open={bomConfirmOpen}
512-
onHide={() => {
513-
setBomConfirmOpen(false);
514-
}}
515-
onSuccess={() => {}}
516-
></BOMCopyConfirmModal>
517507
</NERFormModal>
518508
);
519509
};

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/BOMTab.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { Box } from '@mui/system';
22
import { MaterialPreview, Project, isGuest } from 'shared';
33
import { NERButton } from '../../../components/NERButton';
44
import WarningIcon from '@mui/icons-material/Warning';
5+
import React, { useState } from 'react';
56
import { Tooltip, useTheme } from '@mui/material';
6-
import { useState } from 'react';
77
import BOMTableWrapper from './BOM/BOMTableWrapper';
88
import CreateMaterialModal from './BOM/MaterialForm/CreateMaterialModal';
99
import CreateAssemblyModal from './BOM/AssemblyForm/CreateAssemblyModal';
@@ -13,6 +13,7 @@ import { useCurrentUser } from '../../../hooks/users.hooks';
1313
import LoadingIndicator from '../../../components/LoadingIndicator';
1414
import ErrorPage from '../../ErrorPage';
1515
import { useGetAssembliesForWbsElement, useGetMaterialsForWbsElement } from '../../../hooks/bom.hooks';
16+
import BOMCopyConfirmModal from './BOM/MaterialForm/BOMCopyConfirmModal';
1617

1718
export const addMaterialCosts = (accumulator: number, currentMaterial: MaterialPreview) =>
1819
currentMaterial.subtotal ?? 0 + accumulator;
@@ -22,8 +23,9 @@ const BOMTab = ({ project }: { project: Project }) => {
2223
const [hideColumn, setHideColumn] = useState<boolean[]>(initialHideColumn);
2324
const [showAddMaterial, setShowAddMaterial] = useState(false);
2425
const [showAddAssembly, setShowAddAssembly] = useState(false);
25-
const theme = useTheme();
26+
const [bomConfirmOpen, setBomConfirmOpen] = React.useState(false);
2627

28+
const theme = useTheme();
2729
const user = useCurrentUser();
2830

2931
const {
@@ -93,12 +95,26 @@ const BOMTab = ({ project }: { project: Project }) => {
9395
>
9496
Show All Columns
9597
</NERButton>
96-
{/*
97-
<NERButton variant="contained" onClick={() => {}} disabled={isGuest(user.role)}>
98+
<NERButton
99+
variant="contained"
100+
onClick={() => {
101+
setBomConfirmOpen(true);
102+
}}
103+
disabled={isGuest(user.role)}
104+
>
98105
Copy Existing BOM
99106
</NERButton>
100-
*/}
101107
</Box>
108+
<BOMCopyConfirmModal
109+
open={bomConfirmOpen}
110+
onHide={() => {
111+
setBomConfirmOpen(false);
112+
}}
113+
onSuccess={() => {}}
114+
materialsCount={1}
115+
sourceProjectName={'Source Project'}
116+
currentProjectName={'Target Project'}
117+
></BOMCopyConfirmModal>
102118
<Box display="flex" gap="20px" alignItems="center">
103119
<Box sx={{ backgroundColor: theme.palette.background.paper, padding: '8px 14px 8px 14px', borderRadius: '6px' }}>
104120
Budget: ${project.budget}

0 commit comments

Comments
 (0)