-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.ts
62 lines (52 loc) ยท 1.56 KB
/
1.ts
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
62
import { message } from 'antd';
import { useState } from 'react';
/**
* ํ
์ด๋ธ ๋ก์ฐ์์ดํ
์ ์ญ์ ํ๋ ์ปค์คํ
ํ
* @param {Function} deleteMutation - ์ญ์ ๋ฎคํ
์ด์
* @param {(String[] | String)} deleteTarget - ์ญ์ ํ id(s)
* @param {Function} setDeleteTarget - ์ญ์ ๋์ ์ ํํ๋ ํจ์
* @returns {[Promise, {deleting: Boolean}]} - [์ญ์ ํจ์, ์ญ์ ์ค]
*/
interface IObj {
deleteTarget: string | string[],
setDeleteTarget: () => void,
}
interface IUseDeleteTableRow {
deleteMutation: (variables: unknown) => void,
}
const useDeleteTableRow = (
deleteMutation: IUseDeleteTableRow,
{ deleteTarget, setDeleteTarget }: IObj
): [() => Promise<unknown>, {deleting: Boolean}] => {
const [deleting, setDeleting] = useState(false);
const handleDelete = async () => {
const input = {
input: {
where: {
...(Array.isArray(deleteTarget)
? { id_in: deleteTarget }
: { id: deleteTarget }),
},
},
};
if (!window.confirm('์ ๋ง ์ญ์ ํ์๊ฒ ์ต๋๊น?')) return;
setDeleting(true);
try {
await deleteMutation({
variables: input,
});
} catch (e) {
message.error(`์ญ์ ์คํจ ${e.message}`, 3);
setDeleting(false);
return;
}
message.success(`์ญ์ ๋์์ต๋๋ค.`, 3);
setDeleteTarget([]);
setDeleting(false);
};
return [handleDelete, { deleting }];
};
export default useDeleteTableRow;
enum AdsPlatform {
'Admob', 'Applovin', 'AdColony', 'IronSource', 'Inmobi', 'Kidoz', 'UnityAds', 'Vungle'
}