-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.tsx
61 lines (55 loc) · 1.62 KB
/
utils.tsx
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
50
51
52
53
54
55
56
57
58
59
60
61
import { ProFormMoney } from "@ant-design/pro-components";
import { Col, message } from "antd";
export const MoneyForm = (
label: string,
onChange: (value: number) => void,
isPercentage = false
) =>
<Col span={12}>
<ProFormMoney
colSize={12}
label={label}
locale="it-IT"
placeholder={isPercentage ? "%" : "€ 0"}
customSymbol={isPercentage ? "%" : ""}
min={0}
max={isPercentage ? 99 : 9999999999999}
onChange={(value: number) => onChange(value)}
/>
</Col>
export const drawerProps = {
name: 'file',
multiple: true,
action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
onChange(info: any) {
const { status } = info.file;
if (status !== 'uploading') {
console.log(info.file, info.fileList);
}
if (status === 'done') {
message.success(`${info.file.name} file uploaded successfully.`);
} else if (status === 'error') {
message.error(`${info.file.name} file upload failed.`);
}
},
};
export const uploadImage = async (file: any, setIcon: (arg: any) => void) => {
const data = new FormData();
data.append("file", file.file);
data.append("upload_preset", "lazkktrh");
const res = await fetch(
`https://api.cloudinary.com/v1_1/dgfnyulqh/image/upload`,
{
method: "POST",
body: data,
}
);
const img = await res.json();
if (img) {
file.onSuccess(img);
setIcon(img.secure_url)
}
else {
file.onError(img);
}
}