This commit is contained in:
ajat91.sudrajat 2021-12-21 15:22:13 +07:00
commit ede5e7c368
4 changed files with 122 additions and 140 deletions

View File

@ -65,7 +65,7 @@ export const SupplierComponent = observer((props) => {
width: "5%", width: "5%",
}, },
{ {
title: "Saldo", title: "Saldo di Supplier",
dataIndex: ["coa", "amount"], dataIndex: ["coa", "amount"],
key: ["coa", "amount"], key: ["coa", "amount"],
width: "20%", width: "20%",
@ -75,6 +75,17 @@ export const SupplierComponent = observer((props) => {
currency: "IDR", currency: "IDR",
}).format(text) }).format(text)
}, },
{
title: "Saldo di System",
dataIndex: ["coa_undistribute", "amount"],
key: ["coa_undistribute", "amount"],
width: "20%",
render: (text, record) =>
new Intl.NumberFormat("id-ID", {
style: "currency",
currency: "IDR",
}).format(text)
},
{ {
title: "Status", title: "Status",
dataIndex: "status", dataIndex: "status",

View File

@ -20,8 +20,10 @@ export const PaybackFromUser = observer(() => {
const init = async () => { const init = async () => {
try { try {
modalLoader.setLoading(true); modalLoader.setLoading(true);
await store.payback.getDataUser(); await Promise.allSettled([
await store.authentication.getProfile(); store.payback.getDataUser(),
store.authentication.getProfile()
]);
modalLoader.setLoading(false); modalLoader.setLoading(false);
} catch (e) { } catch (e) {
modalLoader.setLoading(false); modalLoader.setLoading(false);

View File

@ -1,37 +1,28 @@
import React, {useState, useEffect, useContext} from "react"; import React, {useContext, useState} from "react";
import { import {Form, Input, message, Modal, Upload,} from "antd";
Button,
Form,
Image,
Input,
message,
Modal,
Upload,
} from "antd";
import {useStore} from "../../utils/useStore"; import {useStore} from "../../utils/useStore";
import {appConfig} from "../../config/app"; import {LoadingOutlined, PlusOutlined} from "@ant-design/icons";
import {LoadingOutlined, UploadOutlined} from "@ant-design/icons";
import {ModalLoaderContext} from "../../utils/modal"; import {ModalLoaderContext} from "../../utils/modal";
import {http} from "../../utils/http";
import {appConfig} from "../../config/app";
export const PaybackModal = ({visible, onCreate, onCancel, initialData}) => { export const PaybackModal = ({visible, onCreate, onCancel, initialData}) => {
const [form] = Form.useForm(); const [form] = Form.useForm();
const store = useStore(); const store = useStore();
const [image, setImage] = useState("");
const [fileList, setFileList] = useState([]); const [fileList, setFileList] = useState([]);
const [previewTitle, setPreviewTitle] = useState("");
const [previewImage, setPreviewImage] = useState(""); const [previewImage, setPreviewImage] = useState("");
const [fileUrl, setFileUrl] = useState(""); const [previewVisible, setPreviewVisible] = useState(false);
const firstIndexFileList = fileList[0];
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const modalLoader = useContext(ModalLoaderContext); const modalLoader = useContext(ModalLoaderContext);
const beforeUpload = (file) => { const beforeUpload = (file) => {
let isPdf, isLt2M; let isLt2M;
let allowedFile = ["image/jpeg", "image/png", "application/pdf"]; let allowedFile = ["image/jpeg", "image/png"];
let isValid = allowedFile.includes(file.type); let isValid = allowedFile.includes(file.type);
if (!isValid) { if (!isValid) {
message.error("You can only upload PDF or Image file!"); message.error("You can only upload Image file!");
} }
// return file.type === 'application/pdf' ? true : Upload.LIST_IGNORE;
isLt2M = file.size / 1024 / 1024 < 2; isLt2M = file.size / 1024 / 1024 < 2;
if (!isLt2M) { if (!isLt2M) {
message.error("File must smaller than 2MB!"); message.error("File must smaller than 2MB!");
@ -39,42 +30,33 @@ export const PaybackModal = ({visible, onCreate, onCancel, initialData}) => {
return isValid && isLt2M ? true : Upload.LIST_IGNORE; return isValid && isLt2M ? true : Upload.LIST_IGNORE;
}; };
const handlePreview = async (file) => { const uploadHandler = async (args) => {
const fileUrl = appConfig.apiUrl + file.response.path; const file = args.file;
setPreviewTitle(file.url?.substring(file.url?.lastIndexOf("/") + 1)); const res = await http.upload(file);
setImage(`${appConfig.apiUrl}/config/image/${res.body.filename}`);
setFileList([{
uid: '-1',
name: 'image',
status: 'done',
url: `${appConfig.apiUrl}/config/image/${res.body.filename}`,
}]);
}; };
const handleChange = ({fileList}) => { const handleChange = (info) => {
setFileList(fileList); if (info.file.status === 'uploading') {
if (fileList.length && fileList[0].status === "done") { setLoading(true);
form.setFieldsValue({ return;
file_url: fileList[0].response.path,
});
console.log(fileList, "apaaaaaa");
setFileUrl(fileList[0].response.path);
setPreviewImage(fileList[0].response.path);
setPreviewTitle(fileList[0].name);
} }
setLoading(false)
}; };
const uploadButton = ( const uploadButton = (
<div> <div>
{loading ? ( {loading ? <LoadingOutlined/> : <PlusOutlined/>}
<LoadingOutlined/> <div style={{marginTop: 8}}>Click to Upload</div>
) : (
<Button icon={<UploadOutlined/>}>Click to Upload</Button>
)}
</div> </div>
); );
const previewUpload = (
<Image
className="w-full h-full"
preview={false}
src={!fileUrl ? null : `${appConfig.apiUrl}${fileUrl ?? ""}`}
/>
);
const handleSubmit = async (data) => { const handleSubmit = async (data) => {
console.log(data, "isi data2"); console.log(data, "isi data2");
try { try {
@ -134,27 +116,27 @@ export const PaybackModal = ({visible, onCreate, onCancel, initialData}) => {
<Form.Item <Form.Item
label="Upload Picture" label="Upload Picture"
name="image_prove" name="image_prove"
>
<div
style={{
display: "flex",
justifyContent: "space-between",
alignItems: "center",
}}
> >
<div> <div>
<Upload <Upload
name="image_prove" listType="picture-card"
maxCount={1}
className="avatar-uploader"
// listType="picture-card"
action={appConfig.apiUrl + "/files"}
fileList={fileList} fileList={fileList}
beforeUpload={beforeUpload} onPreview={(file) => {
onPreview={handlePreview} setPreviewImage(file.url || file.filename);
setPreviewVisible(file.url || file.filename);
}}
showUploadList={true}
onChange={handleChange} onChange={handleChange}
beforeUpload={(file) => beforeUpload(file)}
customRequest={(args) => uploadHandler(args)}
onRemove={(file) => {
setImage('');
setLoading(false);
setFileList([]);
}}
> >
{!firstIndexFileList ? uploadButton : null}
{image === "" ? uploadButton : null}
</Upload> </Upload>
<h5 <h5
style={{ style={{
@ -165,22 +147,6 @@ export const PaybackModal = ({visible, onCreate, onCancel, initialData}) => {
Max size of file 2 mb Max size of file 2 mb
</h5> </h5>
</div> </div>
<div>
<h5>Preview</h5>
<div>
<img
src={previewImage}
alt="preview"
style={{width: "100%"}}
/>
</div>
<h5>{previewTitle}</h5>
<h5>
{previewUpload}
{previewTitle && <span>{`${previewTitle ?? ""}`}</span>}
</h5>
</div>
</div>
</Form.Item> </Form.Item>
<Form.Item <Form.Item
name="amount" name="amount"

View File

@ -50,13 +50,16 @@ export const http = {
return req; return req;
}, },
upload: (file) => { upload: (file) => {
const request = superagent let req = superagent
.post(appConfig.apiUrl + '/files') .post(appConfig.apiUrl + '/config/upload-files')
.attach('file', file) .attach('file', file)
.use(authIntercept) .use(authIntercept)
.use(attachSuperagentLogger); .use(attachSuperagentLogger);
if (TokenUtil.accessToken) {
req = req.set('Authorization', 'Bearer ' + TokenUtil.accessToken);
}
return request; return req;
}, },
uploadAntd: (args) => { uploadAntd: (args) => {
const file = args.file; const file = args.file;