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

Add supporting documents FE and BE #158

Merged
merged 3 commits into from
Aug 22, 2023
Merged
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
6 changes: 5 additions & 1 deletion backend/controller/files.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const getAllFilesByReferenceController = (req, res) => {
}

const bulkCreateFileController = (req, res) => {
bulkCreateFiles(req.files, req.params.reference_code)
bulkCreateFiles(
req.files,
req.params.reference_code,
req.query.isSupportingDocument
)
.then((newFiles) => res.status(200).json(newFiles))
.catch((err) => res.status(500).json('Error: ' + err))
}
Expand Down
5 changes: 2 additions & 3 deletions backend/service/files.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ const createFile = async (file, referenceCode, isSupportingDocument) => {
return newFile.save()
}

const bulkCreateFiles = (files, referenceCode) => {
const bulkCreateFiles = (files, referenceCode, isSupportingDocument) => {
const promises = files.map((file) =>
// TODO: support isPoDocument
createFile(file, referenceCode, false)
createFile(file, referenceCode, isSupportingDocument)
)
return Promise.all(promises)
}
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/components/FileViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@ const FileViewer = ({ file }) => {
const { isOpen, onOpen, onClose } = useDisclosure()
return (
<Box>
<Button onClick={onOpen}>{file.name}</Button>
<Button
onClick={onOpen}
wordBreak="break-all"
whiteSpace="normal"
textAlign="left"
height="fit-content"
py="4px"
>
{file.name}
</Button>
<FilePopUpModal isOpen={isOpen} onClose={onClose} file={file} />
</Box>
)
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/components/UploadFileModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const UploadFileModal = ({
onClose,
startingUploadedFiles,
refetchFiles,
isSupportingDocument,
}) => {
const ticket = useRecoilValue(currentTicketState)
const [filesToUpload, setFilesToUpload] = useState([])
Expand Down Expand Up @@ -56,7 +57,7 @@ const UploadFileModal = ({
formData.append('files', file)
})
createFilesResponse = axiosPreset.post(
`/files/bulk/${ticket.code}`,
`/files/bulk/${ticket.code}?isSupportingDocument=${isSupportingDocument}`,
formData,
{
headers: {
Expand Down Expand Up @@ -96,7 +97,11 @@ const UploadFileModal = ({
>
<ModalOverlay />
<ModalContent>
<ModalHeader>Upload Document</ModalHeader>
<ModalHeader>
{isSupportingDocument
? 'Upload Supporting Documents'
: 'Upload Files'}
</ModalHeader>
<ModalBody>
<FileUploader
handleChange={onFileAttach}
Expand Down
90 changes: 71 additions & 19 deletions frontend/src/pages/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ const Dashboard = () => {
onClose: onCloseUploadModal,
} = useDisclosure()

const {
isOpen: isSupportingDocumentsModalOpen,
onOpen: onOpenSupportingDocumentsModal,
onClose: onCloseSupportingDocumentsModal,
} = useDisclosure()

const auth = useAuth()
const [allUsers, setAllUsers] = useState({ users: [] })
const [isCurrentTicketReporter, setIsCurrentTicketReporter] =
Expand All @@ -74,6 +80,12 @@ const Dashboard = () => {
const [currentTicket, setCurrentTicket] = useRecoilState(currentTicketState)
const [allTickets, setAllTickets] = useRecoilState(allTicketsState)
const [uploadedFiles, setUploadedFiles] = useRecoilState(currentFiles)
const attachments = uploadedFiles?.filter(
(file) => !file.is_supporting_document
)
const supportingDocuments = uploadedFiles?.filter(
(file) => file.is_supporting_document
)

useEffect(() => {
const fetchData = async () => {
Expand Down Expand Up @@ -217,14 +229,12 @@ const Dashboard = () => {
{/* Do not display update/delete button for WATO Cash */}
{currentTicket.sf_link !== -1 &&
(isCurrentTicketReporter || auth.isDirector) && (
<Flex flexDir="row" mb="12px" gap="16px">
<Button
size="sm"
colorScheme="gray"
onClick={onOpenUploadModal}
>
<Text>Upload Files</Text>
</Button>
<Flex
flexDir="row"
mb="12px"
gap="16px"
flexWrap="wrap"
>
<Button
size="sm"
colorScheme="cyan"
Expand All @@ -239,6 +249,20 @@ const Dashboard = () => {
>
<Text>Delete</Text>
</Button>
<Button
size="sm"
colorScheme="gray"
onClick={onOpenUploadModal}
>
<Text>Upload Files</Text>
</Button>
<Button
size="sm"
colorScheme="blackAlpha"
onClick={onOpenSupportingDocumentsModal}
>
<Text>Upload Supporting Documents</Text>
</Button>
</Flex>
)}
{getCurrentTicketContentTable()}
Expand Down Expand Up @@ -279,16 +303,30 @@ const Dashboard = () => {
</Tbody>
</Table>
</Box>
<Box w="100%" mt="12px">
<Heading mb="8px" fontSize="2xl">
Attachments
</Heading>
<Grid gap="5px">
{uploadedFiles?.map((file) => {
return <FileViewer file={file} />
})}
</Grid>
</Box>
{supportingDocuments.length > 0 && (
<Box w="100%" mt="12px">
<Heading mb="8px" fontSize="2xl">
Supporting Documents
</Heading>
<Grid gap="5px">
{supportingDocuments?.map((file) => {
return <FileViewer file={file} />
})}
</Grid>
</Box>
)}
{attachments.length > 0 && (
<Box w="100%" mt="12px">
<Heading mb="8px" fontSize="2xl">
Uploaded Files
</Heading>
<Grid gap="5px">
{attachments?.map((file) => {
return <FileViewer file={file} />
})}
</Grid>
</Box>
)}
</VStack>
</Flex>
)
Expand All @@ -305,8 +343,22 @@ const Dashboard = () => {
<UploadFileModal
isOpen={isUploadModalOpen}
onClose={onCloseUploadModal}
startingUploadedFiles={uploadedFiles}
startingUploadedFiles={uploadedFiles?.filter(
(file) => !file.is_supporting_document
)}
refetchFiles={getUploadedFiles}
isSupportingDocument={false}
ansonjwhe marked this conversation as resolved.
Show resolved Hide resolved
/>
)}
{isSupportingDocumentsModalOpen && (
<UploadFileModal
isOpen={isSupportingDocumentsModalOpen}
onClose={onCloseSupportingDocumentsModal}
startingUploadedFiles={uploadedFiles?.filter(
(file) => file.is_supporting_document
)}
refetchFiles={getUploadedFiles}
isSupportingDocument={true}
/>
)}

Expand Down
Loading