Skip to content

Commit 3b04b3b

Browse files
authored
fix(RV-428): Fix change upload flow to reflect UI (#494)
1 parent 6e251da commit 3b04b3b

9 files changed

+34
-17
lines changed

frontend/package-lock.json

+10-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/components/ExtractUploadFile.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ export const ExtractUploadFile: React.FC<ExtractUploadFileProps> = ({
150150
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
151151
if (event.target.files && event.target.files.length > 0) {
152152
const files = Array.from(event.target.files);
153+
if (files.length > 0) {
154+
setUploadedFile([]);
155+
clearFiles();
156+
setHasError(false);
157+
}
153158
setUploadedFile(files);
154159
const filesObj: IFilesObj = { files };
155160
localStorage.setItem("files", JSON.stringify(filesObj));
@@ -243,8 +248,9 @@ export const ExtractUploadFile: React.FC<ExtractUploadFileProps> = ({
243248
>
244249
{uploadedFile.length} file(s) selected
245250
</label>
246-
{!isUploadComplete && (
247251
<FileInput
252+
hidePreview
253+
accept=".pdf"
248254
multiple
249255
onChange={handleChange}
250256
id={`file-input-multiple-${id}-2`}
@@ -253,7 +259,6 @@ export const ExtractUploadFile: React.FC<ExtractUploadFileProps> = ({
253259
chooseText="Change file(s)"
254260
dragText=" "
255261
/>
256-
)}
257262
</div>
258263
<div
259264
className="display-flex flex-column width-full height-full margin-bottom-2 margin-top-1"
@@ -352,6 +357,7 @@ export const ExtractUploadFile: React.FC<ExtractUploadFileProps> = ({
352357
style={{ width: "80%" }}
353358
>
354359
<FileInput
360+
accept=".pdf"
355361
multiple
356362
onChange={handleChange}
357363
id={`file-input-multiple-${id}-1`}

frontend/src/components/FileInput.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export const FileInputForwardRef: React.ForwardRefRenderFunction<
177177
}
178178
}
179179
setFiles(fileArr);
180-
180+
console.log('change')
181181
if (onChange) onChange(e);
182182
};
183183

frontend/src/components/FileInput/file-input.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type FileInputProps = {
1919
disabled?: boolean;
2020
multiple?: boolean;
2121
accept?: string;
22+
hidePreview?: boolean;
2223
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
2324
onDrop?: (e: React.DragEvent) => void;
2425
};
@@ -43,6 +44,7 @@ export const FileInputForwardRef: React.ForwardRefRenderFunction<
4344
multiple,
4445
className,
4546
accept,
47+
hidePreview,
4648
onChange,
4749
onDrop,
4850
...inputProps
@@ -103,15 +105,14 @@ export const FileInputForwardRef: React.ForwardRefRenderFunction<
103105
filePreviews.push(
104106
<FilePreview
105107
key={key}
108+
hidePreview
106109
imageId={imageId}
107110
file={files[parseInt(`${i}`)]}
108111
/>,
109112
);
110113
}
111114
}
112-
113115
const instructionClasses = classnames("usa-file-input__instructions", {
114-
"display-none": filePreviews.length > 0,
115116
});
116117

117118
const previewHeaderText =
@@ -187,7 +188,7 @@ export const FileInputForwardRef: React.ForwardRefRenderFunction<
187188
onDragLeave={handleDragLeave}
188189
onDrop={handleDrop}
189190
>
190-
{filePreviews.length > 0 && (
191+
{filePreviews.length > 0 && !hidePreview && (
191192
<div
192193
data-testid="file-input-preview-heading"
193194
className="usa-file-input__preview-heading"

frontend/src/components/FileInput/file-preview.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ const SPACER_GIF =
77
export const FilePreview = ({
88
imageId,
99
file,
10+
hidePreview,
1011
}: {
1112
imageId: string;
1213
file: File;
14+
hidePreview?: boolean;
1315
}): React.ReactElement => {
1416
const [previewSrc, setPreviewSrc] = useState(SPACER_GIF);
1517
const [showGenericPreview, setShowGenericPreview] = useState(false);
@@ -47,7 +49,7 @@ export const FilePreview = ({
4749
return (
4850
<div
4951
data-testid="file-input-preview"
50-
className="usa-file-input__preview"
52+
className={`${hidePreview ? 'display-none' : ''} usa-file-input__preview`}
5153
aria-hidden="true"
5254
>
5355
<img

frontend/src/components/UploadFile.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323

2424
.dashed-container-upload {
25-
height: 160px;
25+
height: 245px;
2626
}
2727

2828
.upload-back-button {

frontend/src/components/UploadFile.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export const Uploadfile = () => {
2323
const file = fileList[i];
2424
filesObj["files"].push(file);
2525
}
26+
if(files.length > 0) {
27+
clearFiles();
28+
localStorage.setItem("files", JSON.stringify('{}'));
29+
}
2630
localStorage.setItem("files", JSON.stringify(filesObj));
2731
addFile(event.target?.files[0]);
2832
}
@@ -59,6 +63,7 @@ export const Uploadfile = () => {
5963
<div className="display-flex flex-column flex-align-center width-full height-full">
6064
<FileInput
6165
onChange={handleChange}
66+
accept=".pdf"
6267
id={`file-input-${id}`}
6368
className="padding-bottom-2"
6469
name="file-input-single"

frontend/src/pages/AnnotateTemplate.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ const AnnotateTemplate: React.FC = () => {
214214
<UploadHeader
215215
title="Annotate new template"
216216
onBack={() => navigate("/new-template/upload")}
217+
onSubmit={handleSubmit}
217218
/>
218219
<Divider margin="0px" />
219220
<div className="display-flex flex-justify-center padding-top-4">

frontend/src/pages/__snapshots__/UploadTemplate.test.tsx.snap

+1
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ exports[`UploadTemplate component > matches the snapshot 1`] = `
201201
data-testid="file-input-box"
202202
/>
203203
<input
204+
accept=".pdf"
204205
class="usa-file-input__input"
205206
data-testid="file-input-input"
206207
id="file-input-:r0:"

0 commit comments

Comments
 (0)