-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFileAttachmentPanel.tsx
More file actions
49 lines (45 loc) · 1.72 KB
/
FileAttachmentPanel.tsx
File metadata and controls
49 lines (45 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2023-2026 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/
import React, { FC, memo, useCallback } from 'react';
import { FileAttachmentForm } from '@labkey/components';
import { Map } from 'immutable';
import { Draft, produce } from 'immer';
import { FileAttachmentModel } from "./models";
interface Props {
model: FileAttachmentModel;
onInputChange: (model: FileAttachmentModel) => void;
onSaveBtnHandler: () => void;
}
// Functional component which would be rendered as part of the parent component
export const FileAttachmentPanel: FC<Props> = memo((props) => {
const { model, onInputChange, onSaveBtnHandler } = props;
const onFileChange = useCallback((files: Map<string, File>) => {
const updatedModel = produce(model, (draft: Draft<FileAttachmentModel>) => {
draft['filesToUpload'] = files;
});
onInputChange(updatedModel);
}, [model, onInputChange]);
return (
<div className='panel panel-default'>
<div className='panel-heading'>
My File Attachments
</div>
<div className='panel-body'>
<FileAttachmentForm
acceptedFormats=".jpg, .pdf, .png"
allowDirectories
allowMultiple
includeDirectoryFiles
fileCountSuffix="included"
showLabel={false}
showButtons
onSubmit={onSaveBtnHandler}
onFileChange={onFileChange}
/>
</div>
</div>
);
})