Skip to content

Commit 83433a7

Browse files
committed
approve now works and editting part doesn't change status
1 parent 5855c8a commit 83433a7

3 files changed

Lines changed: 15 additions & 22 deletions

File tree

src/frontend/src/pages/PartPage/PartPageComponents/PartActionsMenu.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ const PartActionsMenu: React.FC<PartActionsMenuProps> = ({
113113
history.push(reviewLink);
114114
};
115115

116-
const latestReview =
117-
submission?.reviews && submission.reviews.length > 0
118-
? [...submission.reviews].sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())[0]
119-
: null;
120-
121116
const handleReopen = async () => {
122117
try {
123118
await editPart({
@@ -257,13 +252,11 @@ const PartActionsMenu: React.FC<PartActionsMenuProps> = ({
257252
onSubmit={onSubmitEditSubmission}
258253
partsInProject={partsInProject}
259254
/>
260-
{latestReview && (
261-
<ApprovePartModal
262-
open={showApproveSubmission}
263-
handleClose={() => setShowApproveSubmission(false)}
264-
review={latestReview}
265-
/>
266-
)}
255+
<ApprovePartModal
256+
open={showApproveSubmission}
257+
handleClose={() => setShowApproveSubmission(false)}
258+
submission={submission}
259+
/>
267260
<DeleteModal />
268261
{/* for preview image upload button */}
269262
<input

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/PartReview/PartReviewComponents/PartFormModels/ApprovePartModal.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ import { useForm } from 'react-hook-form';
22
import { yupResolver } from '@hookform/resolvers/yup';
33
import { Grid, FormControl, FormLabel, FormHelperText } from '@mui/material';
44
import * as yup from 'yup';
5-
import { Review_Status, PartReview } from 'shared';
5+
import { Review_Status, PartSubmission } from 'shared';
66
import { useToast } from '../../../../../../hooks/toasts.hooks';
7-
import { useEditPartReview } from '../../../../../../hooks/part-review.hooks';
7+
import { useCreatePartReview } from '../../../../../../hooks/part-review.hooks';
88
import NERFormModal from '../../../../../../components/NERFormModal';
99
import ReactHookTextField from '../../../../../../components/ReactHookTextField';
1010

1111
interface ApprovePartModalProps {
1212
open: boolean;
1313
handleClose: () => void;
14-
review: PartReview;
14+
submission: PartSubmission;
1515
}
1616

1717
const schema = yup.object().shape({
1818
notes: yup.string().optional()
1919
});
2020

21-
const ApprovePartModal = ({ open, handleClose, review }: ApprovePartModalProps) => {
21+
const ApprovePartModal = ({ open, handleClose, submission }: ApprovePartModalProps) => {
2222
const toast = useToast();
23-
const { mutateAsync: updateReview } = useEditPartReview();
23+
const { mutateAsync: createReview } = useCreatePartReview();
2424

2525
const {
2626
handleSubmit,
@@ -33,11 +33,11 @@ const ApprovePartModal = ({ open, handleClose, review }: ApprovePartModalProps)
3333

3434
const onFormSubmit = async (data: { notes?: string }) => {
3535
try {
36-
await updateReview({
37-
partReviewId: review.partReviewId,
38-
notes: data.notes,
36+
await createReview({
37+
submissionId: submission.partSubmissionId,
3938
status: Review_Status.APPROVED,
40-
fileIds: review.fileIds
39+
fileIds: [],
40+
notes: data.notes
4141
});
4242

4343
toast.success('Part Approved!');

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/PartReview/PartReviewComponents/PartFormModels/PartFormModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const PartFormModal = ({ open, handleClose, defaultValues, onSubmit, partsInProj
6767
handleClose();
6868
await onSubmit({
6969
...data,
70-
reviewStatus: Review_Status.IN_PROGRESS,
70+
reviewStatus: defaultValues ? defaultValues.status : Review_Status.IN_PROGRESS,
7171
tagIds,
7272
assigneeIds,
7373
reviewerIds

0 commit comments

Comments
 (0)