-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from cameron-eyds/22476-Document-Upload
Documents Upload
- Loading branch information
Showing
8 changed files
with
129 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
document-service/documents-ui/src/assets/icons/attach_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
document-service/documents-ui/src/components/documentUpload/index.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<template> | ||
<FormWrapper name="'document-upload'"> | ||
<template #label> | ||
<h3>Upload Documents</h3> | ||
</template> | ||
|
||
<template #form> | ||
<UFormGroup | ||
:ui="{ help: 'ml-9', error: 'ml-9' }" | ||
:description="$t('documentUpload.description')" | ||
:help="$t('documentUpload.help')" | ||
:error="fileError" | ||
> | ||
<div class="flex flex-row"> | ||
<img class="mr-3" src="~/assets/icons/attach.svg" alt="Paperclip icon"> | ||
<UInput | ||
id="inputFile" | ||
accept=".pdf" | ||
class="mt-3 text-gray-200 w-full" | ||
content="text-gray-700" | ||
:placeholder="$t('documentUpload.placeholder')" | ||
type="file" | ||
multiple | ||
@change="uploadFile" | ||
/> | ||
</div> | ||
</UFormGroup> | ||
|
||
<section v-if="documents.length" class="mt-6 ml-1"> | ||
<h4 class="text-gray-700 font-bold text-[14px]">Documents:</h4> | ||
<div | ||
v-for="(supportingDocument, index) in documents" | ||
:key="supportingDocument.name" | ||
> | ||
<div class="flex flex-row items-center mt-2"> | ||
<img | ||
class="mr-1 h-[18px] w-[18px]" | ||
src="~/assets/icons/attach_dark.svg" | ||
alt="Attach icon" | ||
> | ||
<span>{{ supportingDocument.name }}</span> | ||
<UIcon | ||
name="i-mdi-delete" | ||
class="h-[18px] w-[18px] ml-1 cursor-pointer" | ||
@click="() => removeFile(index)" | ||
/> | ||
</div> | ||
</div> | ||
</section> | ||
|
||
</template> | ||
</FormWrapper> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
const { documents } = useDocumentIndexing() | ||
const t = useNuxtApp().$i18n.t | ||
const fileError = ref(null) | ||
/** | ||
* Uploads valid PDF files to the documents array. | ||
* @param {FileList} files - The list of files to be uploaded. | ||
*/ | ||
const uploadFile = (files: FileList) => { | ||
const validType = ['pdf'] | ||
const maxFileSizeMiB = 50 | ||
// Convert FileList to Array | ||
const allFiles = Array.from(files) | ||
// Validate each file | ||
const invalidFile = allFiles.find(file => { | ||
const extension = file.name.slice(-3).toLowerCase() | ||
const fileSize = file.size / 1024 / 1024 // in MiB | ||
const validFileType = validType.includes(extension) | ||
const validFileSize = fileSize <= maxFileSizeMiB | ||
if (!validFileSize) { | ||
fileError.value = t('documentUpload.fileSizeError') | ||
return true | ||
} else if (!validFileType) { | ||
fileError.value = t('documentUpload.fileTypeError') | ||
return true | ||
} | ||
return false | ||
}) | ||
// If all files are valid, add them to the documents array | ||
if (!invalidFile) { | ||
fileError.value = null | ||
documents.value.push(...allFiles) | ||
} | ||
} | ||
/** Remove a file from the documents array. */ | ||
const removeFile = (index: number) => { | ||
documents.value.splice(index, 1) | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters