Merge branch 'develop' of https://gitlab.com/empatnusabangsa/ppob/ppob-frontend into develop
This commit is contained in:
commit
ede5e7c368
|
@ -65,15 +65,26 @@ 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%",
|
||||||
render: (text, record) =>
|
render: (text, record) =>
|
||||||
new Intl.NumberFormat("id-ID", {
|
new Intl.NumberFormat("id-ID", {
|
||||||
style: "currency",
|
style: "currency",
|
||||||
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",
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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,40 +30,31 @@ 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>
|
||||||
) : (
|
</div>
|
||||||
<Button icon={<UploadOutlined/>}>Click to Upload</Button>
|
|
||||||
)}
|
|
||||||
</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) => {
|
||||||
|
@ -95,101 +77,85 @@ export const PaybackModal = ({visible, onCreate, onCancel, initialData}) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
visible={visible}
|
visible={visible}
|
||||||
title={"Create a new Payback"}
|
title={"Create a new Payback"}
|
||||||
okText={"Create"}
|
okText={"Create"}
|
||||||
cancelText="Cancel"
|
cancelText="Cancel"
|
||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
form.resetFields();
|
|
||||||
onCancel();
|
|
||||||
}}
|
|
||||||
onOk={() => {
|
|
||||||
form
|
|
||||||
.validateFields()
|
|
||||||
.then((values) => {
|
|
||||||
handleSubmit(values);
|
|
||||||
console.log(values);
|
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
})
|
onCancel();
|
||||||
.catch((info) => {
|
}}
|
||||||
console.log("Validate Failed:", info);
|
onOk={() => {
|
||||||
});
|
form
|
||||||
}}
|
.validateFields()
|
||||||
>
|
.then((values) => {
|
||||||
<Form
|
handleSubmit(values);
|
||||||
form={form}
|
console.log(values);
|
||||||
layout="vertical"
|
form.resetFields();
|
||||||
name="form_in_modal"
|
})
|
||||||
initialValues={initialData}
|
.catch((info) => {
|
||||||
|
console.log("Validate Failed:", info);
|
||||||
|
});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Form.Item
|
<Form
|
||||||
name="destination"
|
form={form}
|
||||||
label="destination"
|
layout="vertical"
|
||||||
rules={[{required: true, message: "Please input Name!"}]}
|
name="form_in_modal"
|
||||||
initialValue={store.authentication.profileData.superior?.id}
|
initialValues={initialData}
|
||||||
>
|
>
|
||||||
<Input/>
|
<Form.Item
|
||||||
</Form.Item>
|
name="destination"
|
||||||
<Form.Item
|
label="destination"
|
||||||
label="Upload Picture"
|
rules={[{required: true, message: "Please input Name!"}]}
|
||||||
name="image_prove"
|
initialValue={store.authentication.profileData.superior?.id}
|
||||||
>
|
>
|
||||||
<div
|
<Input/>
|
||||||
style={{
|
</Form.Item>
|
||||||
display: "flex",
|
<Form.Item
|
||||||
justifyContent: "space-between",
|
label="Upload Picture"
|
||||||
alignItems: "center",
|
name="image_prove"
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<Upload
|
<Upload
|
||||||
name="image_prove"
|
listType="picture-card"
|
||||||
maxCount={1}
|
fileList={fileList}
|
||||||
className="avatar-uploader"
|
onPreview={(file) => {
|
||||||
// listType="picture-card"
|
setPreviewImage(file.url || file.filename);
|
||||||
action={appConfig.apiUrl + "/files"}
|
setPreviewVisible(file.url || file.filename);
|
||||||
fileList={fileList}
|
}}
|
||||||
beforeUpload={beforeUpload}
|
showUploadList={true}
|
||||||
onPreview={handlePreview}
|
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={{
|
||||||
marginTop: 12,
|
marginTop: 12,
|
||||||
color: "rgba(0, 0, 0, 0.45)",
|
color: "rgba(0, 0, 0, 0.45)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Max size of file 2 mb
|
Max size of file 2 mb
|
||||||
</h5>
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
</Form.Item>
|
||||||
<h5>Preview</h5>
|
<Form.Item
|
||||||
<div>
|
name="amount"
|
||||||
<img
|
label="amount"
|
||||||
src={previewImage}
|
rules={[{required: true, message: "Please input Amount!"}]}
|
||||||
alt="preview"
|
>
|
||||||
style={{width: "100%"}}
|
<Input/>
|
||||||
/>
|
</Form.Item>
|
||||||
</div>
|
</Form>
|
||||||
<h5>{previewTitle}</h5>
|
</Modal>
|
||||||
<h5>
|
|
||||||
{previewUpload}
|
|
||||||
{previewTitle && <span>{`${previewTitle ?? ""}`}</span>}
|
|
||||||
</h5>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
name="amount"
|
|
||||||
label="amount"
|
|
||||||
rules={[{required: true, message: "Please input Amount!"}]}
|
|
||||||
>
|
|
||||||
<Input/>
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
</Modal>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user