Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useToast } from '../../../../../../hooks/toasts.hooks';
import * as yup from 'yup';
import { Controller, useFieldArray, useForm } from 'react-hook-form';
import { yupResolver } from '@hookform/resolvers/yup';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import NERFormModal from '../../../../../../components/NERFormModal';
import { Autocomplete, Button, Grid, IconButton, List, ListItem, Typography } from '@mui/material';
import { FormControl, FormHelperText, FormLabel, TextField } from '@mui/material';
Expand All @@ -25,6 +25,13 @@ const ReviewFormModal = ({ open, handleClose, defaultValues, onSubmit, partsInPr
const [uploading, setUploading] = useState(false);
const { mutateAsync: uploadFile } = useUploadFile();

useEffect(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a useEffect in both files, just wrap handleClose in a callback that also clears the state. Then update the onHide= call. It should look something like this:

const handleCloseAndReset = () => {
  setFiles([]);
  setSelectedPartIndex(undefined); 
  handleClose();
};

if (!open) {
setFiles([]);
setSelectedPartIndex(undefined);
}
}, [open]);

const schema = yup.object().shape({
submissionId: yup.string().required(),
notes: yup.string().optional(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ const SubmissionFormModal = ({
const [uploading, setUploading] = useState(false);
const { mutateAsync: uploadFile } = useUploadFile();

useEffect(() => {
if (!open) {
setFiles([]);
}
}, [open]);

const schema = yup.object().shape({
partId: yup.string().required(),
name: yup.string().required(),
Expand Down
Loading