Skip to content

Commit 67236a7

Browse files
committed
make the alert show up at the right time
1 parent 1cede1b commit 67236a7

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/compounds/ActionsGroup/actions/ViewFiles.jsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState, useRef } from 'react'
22
import PropTypes from 'prop-types'
33
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
44
import {
5+
Alert,
56
Button,
67
CloseButton,
78
Form,
@@ -18,6 +19,8 @@ const ViewFiles = ({ backgroundColor, initialFiles, handleClose, onSubmit }) =>
1819
const fileRef = useRef(null)
1920
const [files, setFiles] = useState(initialFiles)
2021
const [tempFiles, setTempFiles] = useState([])
22+
const [showSuccessAlert, setShowSuccessAlert] = useState(false)
23+
//let newlyAddedFiles = []
2124
const documentTabs = [
2225
{
2326
eventKey: 'files',
@@ -44,19 +47,22 @@ const ViewFiles = ({ backgroundColor, initialFiles, handleClose, onSubmit }) =>
4447
const newBase64Files = await Promise.all(convertToBase64(fileArray))
4548
const newFiles = fileArray.map((file, index) => ({ [file.name]: newBase64Files[index] }))
4649
setTempFiles([...tempFiles, ...newFiles])
47-
console.log(tempFiles, 'tempFilesAfterAdd')
50+
if (showSuccessAlert) {
51+
setShowSuccessAlert(false)
52+
}
4853
fileRef.current.value = ''
4954
} catch (error) {
5055
throw new Error(error)
5156
}
5257
}
5358

54-
const handleSubmit = (event) => {
59+
const handleSubmit = async (event) => {
5560
event.preventDefault()
56-
onSubmit({ files: apiV2CompatibleStrings([...tempFiles]) })
57-
console.log(files, 'filesBeforeSubmit')
58-
//setFiles([...files, ...apiCompatibleTempFiles])
59-
setTempFiles([])
61+
await onSubmit({ files: apiV2CompatibleStrings([...tempFiles]) })
62+
if (tempFiles.length > 0) {
63+
setShowSuccessAlert(true)
64+
setTempFiles([])
65+
}
6066
}
6167

6268
const handleDeleteTempFile = (file) => {
@@ -98,11 +104,16 @@ const ViewFiles = ({ backgroundColor, initialFiles, handleClose, onSubmit }) =>
98104
</ListGroup.Item>
99105
)
100106
})}
107+
{showSuccessAlert &&
108+
<Alert variant='success' onClose={() => setShowSuccessAlert(false)} dismissible >
109+
Your files have been uploaded successfully. It may take some time for them to appear below.
110+
</Alert>
111+
}
101112
</ListGroup>
102113
<Tabs defaultActiveKey='files' id='document-tabs' justify fill>
103114
{documentTabs && documentTabs.map((tab) => {
104115
const { eventKey, title, status } = tab
105-
const filteredFiles = files.filter((f) => (status === f.status) || (status === 'Other File' && f.status === null))
116+
const filteredFiles = initialFiles.filter((f) => (status === f.status) || (status === 'Other File' && f.status === null))
106117
return (
107118
<Tab
108119
eventKey={eventKey}

0 commit comments

Comments
 (0)