1
1
import React , { useState , useRef } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import {
4
- Button ,
5
- CloseButton ,
6
- Form ,
7
- InputGroup ,
8
- ListGroup ,
4
+ // Button,
5
+ // CloseButton,
6
+ // Form,
7
+ // InputGroup,
8
+ // ListGroup,
9
9
Offcanvas ,
10
10
Tab ,
11
11
Tabs } from 'react-bootstrap'
12
- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
12
+ // import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
13
13
import FilesTable from '../../../components/FilesTable/FilesTable'
14
- import { apiV2CompatibleStrings , convertToBase64 } from '../../../resources/utilityFunctions'
14
+ // import { apiV2CompatibleStrings, convertToBase64 } from '../../../resources/utilityFunctions'
15
15
16
16
const ViewFiles = ( { initialFiles, handleClose, show } ) => {
17
- const fileRef = useRef ( null )
18
- const [ files , setFiles ] = useState ( [ ] )
17
+ // TODO(summercook):
18
+ // - comment back in the following 2 lines & above imports once posting messages/attachments is working
19
+ // const fileRef = useRef(null)
20
+ // const [files, setFiles] = useState([])
19
21
const documentTabs = [
20
22
{
21
23
eventKey : 'files' ,
@@ -35,84 +37,88 @@ const ViewFiles = ({ initialFiles, handleClose, show }) => {
35
37
} ,
36
38
]
37
39
38
- // TODO(summercook): update this method once posting messages is working- may need to use the handleSendingMessagesOrFiles to post
39
- // need to check if we should just a different endpoint to post attachments
40
- const handleSubmit = ( event ) => {
41
- event . preventDefault ( )
42
- onSubmit ( { files : apiV2CompatibleStrings ( files ) } )
43
- }
40
+ // TODO(summercook):
41
+ // - comment back in the following 3 methods once posting messages/attachments is working
42
+ // may need to use the handleSendingMessagesOrFiles to post
43
+ // const handleSubmit = (event) => {
44
+ // event.preventDefault()
45
+ // onSubmit({ files: apiV2CompatibleStrings(files) })
46
+ // }
44
47
45
- const handleAddFile = async ( event ) => {
46
- event . preventDefault ( )
47
- try {
48
- // "event.target.files" returns a FileList, which looks like an array but does not respond to array methods
49
- // except "length". we are using the spread syntax to set "files" to be an iterable array
50
- const fileArray = [ ...event . target . files ]
51
- const newBase64Files = await Promise . all ( convertToBase64 ( fileArray ) )
52
- const newFiles = fileArray . map ( ( file , index ) => ( { [ file . name ] : newBase64Files [ index ] } ) )
48
+ // const handleAddFile = async (event) => {
49
+ // event.preventDefault()
50
+ // try {
51
+ // // "event.target.files" returns a FileList, which looks like an array but does not respond to array methods
52
+ // // except "length". we are using the spread syntax to set "files" to be an iterable array
53
+ // const fileArray = [...event.target.files]
54
+ // const newBase64Files = await Promise.all(convertToBase64(fileArray))
55
+ // const newFiles = fileArray.map((file, index) => ({ [file.name]: newBase64Files[index] }))
53
56
54
- setFiles ( [ ...files , ...newFiles ] )
55
- fileRef . current . value = ''
56
- } catch ( error ) {
57
- throw new Error ( error )
58
- }
59
- }
57
+ // setFiles([...files, ...newFiles])
58
+ // fileRef.current.value = ''
59
+ // } catch (error) {
60
+ // throw new Error(error)
61
+ // }
62
+ // }
60
63
61
- const handleDeleteFile = ( file ) => {
62
- const remainingFiles = files . filter ( ( obj ) => obj !== file )
63
- setFiles ( remainingFiles )
64
- }
64
+ // const handleDeleteFile = (file) => {
65
+ // const remainingFiles = files.filter((obj) => obj !== file)
66
+ // setFiles(remainingFiles)
67
+ // }
65
68
66
69
return (
67
70
< Offcanvas show = { show } onHide = { handleClose } placement = 'end' scroll = 'true' >
68
71
< Offcanvas . Header className = 'd-flex border-bottom px-3 py-2 bg-light' closeButton >
69
72
< Offcanvas . Title > Documents</ Offcanvas . Title >
70
73
</ Offcanvas . Header >
71
74
< Offcanvas . Body className = 'border rounded p-2 m-3' >
72
- < Form >
73
- < h6 className = 'mt-3' > Upload Additional Documents</ h6 >
74
- < InputGroup controlId = 'attachments' className = 'mb-3' >
75
- < Form . Control
76
- multiple
77
- type = 'file'
78
- onChange = { handleAddFile }
79
- ref = { fileRef }
80
- />
81
- < Button
82
- variant = 'outline-primary'
83
- onClick = { handleSubmit }
84
- type = 'submit'
85
- >
86
- < FontAwesomeIcon icon = 'fa-upload' />
87
- </ Button >
88
- </ InputGroup >
89
- </ Form >
90
- < ListGroup variant = 'flush' >
91
- { files . map ( ( file ) => {
92
- const fileName = Object . keys ( file ) [ 0 ]
75
+ { /* TODO(summercook): see above comment */ }
76
+ { /* <Form>
77
+ <h6 className='mt-3'>Upload Additional Documents</h6>
78
+ <InputGroup controlId='attachments' className='mb-3'>
79
+ <Form.Control
80
+ multiple
81
+ type='file'
82
+ onChange={handleAddFile}
83
+ ref={fileRef}
84
+ />
85
+ <Button
86
+ variant='outline-primary'
87
+ onClick={handleSubmit}
88
+ type='submit'
89
+ >
90
+ <FontAwesomeIcon icon='fa-upload' />
91
+ </Button>
92
+ </InputGroup>
93
+ </Form>
94
+ <ListGroup variant='flush'>
95
+ {files.map((file) => {
96
+ const fileName = Object.keys(file)[0]
93
97
94
- return (
95
- < ListGroup . Item key = { fileName } className = 'd-flex align-items-center' >
96
- < span > { fileName } </ span >
97
- < CloseButton onClick = { ( ) => handleDeleteFile ( file ) } className = 'ms-auto' />
98
- </ ListGroup . Item >
99
- )
100
- } ) }
101
- </ ListGroup >
102
- < Tabs defaultActiveKey = "files" id = "document-tabs" >
103
- { documentTabs && documentTabs . map ( tab => {
104
- const { eventKey, title, status } = tab
105
- let filteredFiles = initialFiles . filter ( f => ( status === f . status ) || ( status === 'Other File' && f . status === null ) )
106
- return (
107
- < Tab eventKey = { eventKey } title = { title } className = 'p-2' >
108
- < FilesTable
109
- files = { filteredFiles }
110
- status = { status }
111
- handleDeleteFile = { handleDeleteFile } />
112
- </ Tab >
113
- )
114
- } ) }
115
- </ Tabs >
98
+ return (
99
+ <ListGroup.Item key={fileName} className='d-flex align-items-center'>
100
+ <span>{fileName}</span>
101
+ <CloseButton onClick={() => handleDeleteFile(file)} className='ms-auto' />
102
+ </ListGroup.Item>
103
+ )
104
+ }) }
105
+ </ListGroup> */ }
106
+ < Tabs defaultActiveKey = "files" id = "document-tabs" >
107
+ { documentTabs && documentTabs . map ( tab => {
108
+ const { eventKey, title, status } = tab
109
+ let filteredFiles = initialFiles . filter ( f => ( status === f . status ) || ( status === 'Other File' && f . status === null ) )
110
+ return (
111
+ < Tab eventKey = { eventKey } title = { title } className = 'p-2' >
112
+ < FilesTable
113
+ files = { filteredFiles }
114
+ status = { status }
115
+ // TODO(summercook): see above comment
116
+ // handleDeleteFile={handleDeleteFile}
117
+ />
118
+ </ Tab >
119
+ )
120
+ } ) }
121
+ </ Tabs >
116
122
</ Offcanvas . Body >
117
123
</ Offcanvas >
118
124
)
0 commit comments