Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear files after upload #3355

Merged
merged 3 commits into from
Dec 8, 2021
Merged
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
11 changes: 8 additions & 3 deletions frontend-react/src/pages/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ library.add(faSync);
export const Upload = () => {
const { authState } = useOktaAuth();
const [isSubmitting, setIsSubmitting] = useState(false);
const [fileInputResetValue, setFileInputResetValue] = useState(0);
const [fileContent, setFileContent] = useState("");
const [warnings, setWarnings] = useState([]);
const [errors, setErrors] = useState([]);
Expand Down Expand Up @@ -80,7 +81,9 @@ export const Upload = () => {
}
};

const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
const handleFileChange = async (
event: React.ChangeEvent<HTMLInputElement>
) => {
try {
if (!event?.currentTarget?.files?.length) {
// no files selected
Expand Down Expand Up @@ -163,6 +166,8 @@ export const Upload = () => {
}
}
setButtonText("Upload another file");
// Changing the key to force the FileInput to reset. Otherwise it won't recognize changes to the file's content unless the file name changes
setFileInputResetValue(fileInputResetValue + 1);
setIsSubmitting(false);
};

Expand Down Expand Up @@ -324,7 +329,6 @@ export const Upload = () => {
</table>
</div>
)}

<Form onSubmit={(e) => handleSubmit(e)}>
<FormGroup className="margin-bottom-3">
<Label
Expand All @@ -335,11 +339,12 @@ export const Upload = () => {
Upload your COVID-19 lab results as a .CSV.
</Label>
<FileInput
key={fileInputResetValue}
id="upload-csv-input"
name="upload-csv-input"
aria-describedby="upload-csv-input-label"
accept=".csv, text/csv"
onChange={(e) => handleChange(e)}
onChange={(e) => handleFileChange(e)}
required
/>
</FormGroup>
Expand Down