From f5789bb6006366e5a1ee3d5be7baf959d6d4b9d6 Mon Sep 17 00:00:00 2001 From: Sharath Thokala Date: Mon, 29 Jan 2024 11:41:36 +0000 Subject: [PATCH] Add remove file logic --- .../App/Form/Summary/Sections/SendRequest.tsx | 16 ++--- .../MultiFileUpload/MultiFileUpload.tsx | 71 +++++++++---------- .../MultiFileUpload/MultiFileUpload.types.ts | 1 + .../DisabilityProofStep.tsx | 12 ++++ 4 files changed, 56 insertions(+), 44 deletions(-) diff --git a/src/components/App/Form/Summary/Sections/SendRequest.tsx b/src/components/App/Form/Summary/Sections/SendRequest.tsx index 7d0ffc1..57741be 100644 --- a/src/components/App/Form/Summary/Sections/SendRequest.tsx +++ b/src/components/App/Form/Summary/Sections/SendRequest.tsx @@ -28,14 +28,14 @@ const SendYourRequest = () => { const fileData = []; const applicationNumber = Math.floor(Math.random() * 10000000 + 1).toString(); const files = [ - formDataState.ApplicantPhoto, - ...formDataState.proofDocumentArms, - ...formDataState.proofDocumentBlind, - ...formDataState.proofDocumentDeaf, - ...formDataState.proofDocumentDrive, - ...formDataState.proofDocumentLanguage, - ...formDataState.proofDocumentLearn, - ...formDataState.proofDocumentWalk, + [formDataState.ApplicantPhoto], + formDataState.proofDocumentArms ? [...formDataState.proofDocumentArms] : [], + formDataState.proofDocumentBlind ? [...formDataState.proofDocumentBlind] : [], + formDataState.proofDocumentDeaf ? [...formDataState.proofDocumentDeaf] : [], + formDataState.proofDocumentDrive ? [...formDataState.proofDocumentDrive] : [], + formDataState.proofDocumentLanguage ? [...formDataState.proofDocumentLanguage] : [], + formDataState.proofDocumentLearn ? [...formDataState.proofDocumentLearn] : [], + formDataState.proofDocumentWalk ? [...formDataState.proofDocumentWalk] : [], ]; const checkAnswersEl = document.getElementById('application-summary'); // remove change button diff --git a/src/components/shared/MultiFileUpload/MultiFileUpload.tsx b/src/components/shared/MultiFileUpload/MultiFileUpload.tsx index da150e6..65315eb 100644 --- a/src/components/shared/MultiFileUpload/MultiFileUpload.tsx +++ b/src/components/shared/MultiFileUpload/MultiFileUpload.tsx @@ -6,14 +6,13 @@ import { Icon } from 'components/shared'; import s from './MultiFileUpload.module.scss'; import { TMultiFileUploadProps } from './MultiFileUpload.types'; -// prettier-ignore - const FileUpload = ({ name, label, hint, defaultFiles, updateFiles, + removeFile, error, accept, }: TMultiFileUploadProps): JSX.Element => { @@ -21,13 +20,13 @@ const FileUpload = ({ const handleFocus = () => setIsFileInputFocused(true); const handleBlur = () => setIsFileInputFocused(false); - // const dFiles = defaultFiles ? [...defaultFiles] : []; + const selectedFiles = defaultFiles ? [...defaultFiles] : []; // const previewUrl = defaultFile ? URL.createObjectURL(defaultFile) : undefined; const handleChange = (e: React.ChangeEvent) => { const fileList = e.target?.files; - const files = fileList ? [...fileList] : []; + const files = fileList ? [...selectedFiles, ...fileList] : selectedFiles; if (!files) return; updateFiles(files); @@ -49,14 +48,12 @@ const FileUpload = ({ - No files selected - - {defaultFiles ? (defaultFiles.map((file, i) => ( - //
  • - // {file.name} - {file.type} - //
  • - <> -
    - - {file.name} -
    -
    - preview -
    - - ))) : (<>)} + + {selectedFiles.length > 0 ? 'Add more files' : 'No files selected'} + + {defaultFiles ? ( + defaultFiles.map((file, i) => ( + <> +
    + + {file.name} +
    + + )) + ) : ( + <> + )} ); diff --git a/src/components/shared/MultiFileUpload/MultiFileUpload.types.ts b/src/components/shared/MultiFileUpload/MultiFileUpload.types.ts index 4126b43..1806539 100644 --- a/src/components/shared/MultiFileUpload/MultiFileUpload.types.ts +++ b/src/components/shared/MultiFileUpload/MultiFileUpload.types.ts @@ -8,5 +8,6 @@ export type TMultiFileUploadProps = { hint?: string; defaultFiles?: Nullable; updateFiles: (files: Nullable) => void; + removeFile: (file: File) => void; accept?: string; }; diff --git a/src/components/sharedSteps/DisabilityProofStep/DisabilityProofStep.tsx b/src/components/sharedSteps/DisabilityProofStep/DisabilityProofStep.tsx index ce0bd37..c3e0eee 100644 --- a/src/components/sharedSteps/DisabilityProofStep/DisabilityProofStep.tsx +++ b/src/components/sharedSteps/DisabilityProofStep/DisabilityProofStep.tsx @@ -98,6 +98,17 @@ const DisabilityProofStep = ({ handleNavigation(); } }; + const deleteFile = (file: File) => { + if (identityDocument.currentValue !== null) { + const array = [...identityDocument.currentValue]; + const index = identityDocument.currentValue.indexOf(file); + if (index > -1) { + array.splice(index, 1); + identityDocument.set(array); + } + } + }; + // const one = !question.includes('learn') ? 'one' : 'at least two'; return (