Skip to content

Commit

Permalink
Remove ability for PMs to edit Project Information on VRMS (#1634)
Browse files Browse the repository at this point in the history
* conditionally rendering project form based on auth.isAdmin, conditionally rendering badge in TitleBox based on whether the prop exists

* updates to auth.user.accessLevel

* removed console.logs
  • Loading branch information
lcchrty authored May 16, 2024
1 parent 29172a0 commit 4474bb6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 66 deletions.
95 changes: 52 additions & 43 deletions client/src/components/ProjectForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function ProjectForm({
formData,
projectToEdit,
isEdit,
setFormData
setFormData,
}) {
const history = useHistory();

Expand All @@ -74,11 +74,11 @@ export default function ProjectForm({
const [editMode, setEditMode] = useState(false);
const { auth } = useAuth();
const [isModalOpen, setIsModalOpen] = useState(false);
const handleOpen = () => setIsModalOpen(true)
const handleClose = () => setIsModalOpen(false)
const handleOpen = () => setIsModalOpen(true);
const handleClose = () => setIsModalOpen(false);
const checkFields = () => {
history.push("/projects")
}
history.push('/projects');
};

/**
* React Hook Forms
Expand All @@ -95,7 +95,7 @@ export default function ProjectForm({
handleSubmit,
reset,
formState: { errors },
control
control,
} = useForm({
mode: 'all',
// Holds the current project data in state.
Expand All @@ -104,7 +104,7 @@ export default function ProjectForm({
},
});

const { dirtyFields } = useFormState({control})
const { dirtyFields } = useFormState({ control });

// ----------------- Submit requests -----------------

Expand Down Expand Up @@ -134,8 +134,6 @@ export default function ProjectForm({
setEditMode(false);
};



// ----------------- Handles and Toggles -----------------

// Handles the location radio button change.
Expand Down Expand Up @@ -229,46 +227,51 @@ export default function ProjectForm({
<Box sx={{ textAlign: 'center' }}>
<Typography variant="h1">Project Management</Typography>
</Box>
<TitledBox
title={editMode ? 'Editing Project' : 'Project Information'}
badge={isEdit ? editIcon() : addIcon()}
{auth.user.accessLevel === 'admin' ? (
<TitledBox
title={editMode ? 'Editing Project' : 'Project Information'}
badge={isEdit ? editIcon() : addIcon()}
/>
) : (
<TitledBox title={'Project Information'} />
)}
<form
id="project-form"
onSubmit={handleSubmit((data) => {
isEdit ? submitEditProject(data) : submitNewProject(data);
})}
>

<form
id="project-form"
onSubmit={handleSubmit((data) => {
isEdit ? submitEditProject(data) : submitNewProject(data);
})}
>

{arr.map((input) => (
<ValidatedTextField
key={input.name}
register={register}
isEdit={isEdit}
editMode={editMode}
locationType={locationType}
locationRadios={locationRadios}
errors={errors}
input={input}
/>
))}
<ChangesModal
open={isModalOpen}
onClose={handleClose}
destination={'/projects'}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
handleClose={handleClose}
{arr.map((input) => (
<ValidatedTextField
key={input.name}
register={register}
isEdit={isEdit}
editMode={editMode}
locationType={locationType}
locationRadios={locationRadios}
errors={errors}
input={input}
/>
))}
<ChangesModal
open={isModalOpen}
onClose={handleClose}
destination={'/projects'}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
handleClose={handleClose}
/>
</form>
</form>
{auth.user.accessLevel === 'admin' ? (
<Box>
<Grid container justifyContent="space-evenly" sx={{ my: 3 }}>
<Grid item xs="auto">
<StyledButton
type="submit"
form="project-form"
variant={!isEdit ? 'secondary' : !editMode ? 'contained' : 'secondary'}
variant={
!isEdit ? 'secondary' : !editMode ? 'contained' : 'secondary'
}
cursor="pointer"
disabled={isEdit ? !editMode : false}
>
Expand All @@ -279,14 +282,20 @@ export default function ProjectForm({
<StyledButton
variant="contained"
cursor="pointer"
onClick={!editMode || Object.keys(dirtyFields).length === 0 ? checkFields: handleOpen}
onClick={
!editMode || Object.keys(dirtyFields).length === 0
? checkFields
: handleOpen
}
>
Close
</StyledButton>
</Grid>
</Grid>
</Box>
</TitledBox>
) : (
''
)}
</Box>
) : (
<Redirect to="/login" />
Expand Down
44 changes: 21 additions & 23 deletions client/src/components/parts/boxes/TitledBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@ import React from 'react';
import { Box, Typography, Divider } from '@mui/material';

export default function TitledBox({ title, children, badge, childrenBoxSx }) {
return (
<Box sx={{ bgcolor: '#F5F5F5', my: 3 }}>
<Box
sx={{
p: 2,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Box>
<Typography sx={{ fontSize: '18px', fontWeight: '600' }}>
{title}
</Typography>
</Box>
{badge}
</Box>
<Divider sx={{ borderColor: 'rgba(0,0,0,1)' }} />
<Box sx={{ py: 2, px: 4, ...childrenBoxSx }}>{children}</Box>
return (
<Box sx={{ bgcolor: '#F5F5F5', my: 3 }}>
<Box
sx={{
p: 2,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Box>
<Typography sx={{ fontSize: '18px', fontWeight: '600' }}>
{title}
</Typography>
</Box>
);


}
{badge ? badge : ' '}
</Box>
<Divider sx={{ borderColor: 'rgba(0,0,0,1)' }} />
<Box sx={{ py: 2, px: 4, ...childrenBoxSx }}>{children}</Box>
</Box>
);
}

0 comments on commit 4474bb6

Please sign in to comment.