Perbaikan Project PPOB
This commit is contained in:
@@ -280,7 +280,7 @@ export const DetailUser = observer(() => {
|
||||
"detail gambar"
|
||||
);
|
||||
return (
|
||||
<div className={["ppob-container"].join(" ")}>
|
||||
<div className={[""].join(" ")}>
|
||||
<BreadcumbComponent data={routeData} />
|
||||
<Card>
|
||||
<Row style={{ marginBottom: 10 }}>
|
||||
|
||||
@@ -1,141 +0,0 @@
|
||||
import React from 'react';
|
||||
import { Image, Modal, Upload, message } from 'antd';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { http } from "../utils/http";
|
||||
|
||||
function getBase64(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.onload = () => resolve(reader.result);
|
||||
reader.onerror = error => reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
export class PicturesWall extends React.Component {
|
||||
state = {
|
||||
previewVisible: false,
|
||||
previewImage: '',
|
||||
previewTitle: '',
|
||||
fileList: [],
|
||||
};
|
||||
|
||||
handleCancel = () => this.setState({ previewVisible: false });
|
||||
|
||||
handlePreview = async file => {
|
||||
if (!file.url && !file.preview) {
|
||||
file.preview = await getBase64(file.originFileObj);
|
||||
}
|
||||
|
||||
this.setState({
|
||||
previewImage: file.url || file.preview,
|
||||
previewTitle: file.name || file.url.substring(file.url.lastIndexOf('/') + 1),
|
||||
previewVisible: true,
|
||||
});
|
||||
};
|
||||
|
||||
handlePreviewCancel = () => {
|
||||
this.setState({
|
||||
previewVisible: false,
|
||||
});
|
||||
};
|
||||
|
||||
handleChange = ({ fileList }, info) => {
|
||||
|
||||
// if (this.props.maxUpload) {
|
||||
// if (fileList.length > this.props.maxUpload) {
|
||||
// fileList.splice(0, 1)
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (info.file.status !== 'uploading') {
|
||||
// console.log(info.file, info.fileList);
|
||||
// }
|
||||
// if (info.file.status === 'done') {
|
||||
// message.success(`${info.file.name} file uploaded successfully`);
|
||||
// } else if (info.file.status === 'error') {
|
||||
// message.error(`${info.file.name} file upload failed.`);
|
||||
// }
|
||||
|
||||
this.setState({ fileList })
|
||||
};
|
||||
|
||||
render() {
|
||||
const { previewVisible, previewImage, fileList, previewTitle, handlePreviewCancel } = this.state;
|
||||
const uploadButton = (
|
||||
<div>
|
||||
<PlusOutlined />
|
||||
<div style={{ marginTop: 8 }}>Upload</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Upload
|
||||
action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
|
||||
listType="picture-card"
|
||||
fileList={fileList}
|
||||
accept={'.png, .jpg, .jpeg, .PNG, .JPG, .JPEG'}
|
||||
onPreview={this.handlePreview}
|
||||
onChange={this.handleChange}
|
||||
beforeUpload={(file) => {
|
||||
console.log({ file })
|
||||
http.uploadAntd({
|
||||
file,
|
||||
onError() {
|
||||
|
||||
},
|
||||
onProgress(event) {
|
||||
console.log({ event })
|
||||
},
|
||||
onSuccess: (res) => {
|
||||
if (this.props.onUpload) {
|
||||
const { fileList } = this.state
|
||||
const index = fileList.findIndex(d => d.uid === file.uid)
|
||||
|
||||
if (fileList.length > this.props.maxUpload) {
|
||||
this.setState({
|
||||
fileList: []
|
||||
}) && this.props.onUpload()
|
||||
message.error('Upload foto tidak boleh melebihi batas maksimal!');
|
||||
} else {
|
||||
fileList[index].path = res.body.path
|
||||
this.setState({
|
||||
...fileList
|
||||
})
|
||||
this.props.onUpload(fileList)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
return false;
|
||||
}}
|
||||
{...(this.props.uploadProps || {})}
|
||||
>
|
||||
{/* {fileList.length > this.props.maxUpload ?
|
||||
this.setState({
|
||||
fileList: []
|
||||
}) && this.props.onUpload() && null
|
||||
:
|
||||
''} */}
|
||||
{fileList.length >= this.props.maxUpload ? '' : uploadButton}
|
||||
</Upload>
|
||||
|
||||
<Modal
|
||||
visible={previewVisible}
|
||||
title={previewTitle}
|
||||
footer={null}
|
||||
onCancel={this.handleCancel}
|
||||
>
|
||||
<Image
|
||||
onClick={this.handleCancel}
|
||||
src={previewImage}
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default PicturesWall;
|
||||
Reference in New Issue
Block a user