frontend/Components/FileUploader/index.tsx

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-08-26 20:02:52 +03:00
import React, { useState } from "react";
import { Button, message, Upload } from "antd"
import Icon, { UploadOutlined } from '@ant-design/icons';
import 'antd/dist/antd.css';
2022-08-27 12:17:39 +03:00
import { host } from "../../pages/api/consts";
2022-08-26 20:02:52 +03:00
interface FileUploaderIE{
onResponse: (response:any)=>void
}
export const FileUploader:React.FC<FileUploaderIE> = (data) =>{
const props = {
name: 'file',
2022-08-27 12:17:39 +03:00
action: host + '/api/site/docx/',
2022-08-26 20:02:52 +03:00
headers: {
authorization: 'authorization-text',
},
onChange(info:any) {
if (info.file.status !== 'uploading') {
}
if (info.file.status === 'done') {
data.onResponse(info.file.response)
message.success(`${info.file.name} file uploaded successfully`);
} else if (info.file.status === 'error') {
message.error(`${info.file.name} file upload failed.`);
}
},
};
return (
<Upload {...props}>
<Button icon={<UploadOutlined></UploadOutlined>}>Click to Upload</Button>
</Upload>
);
}