-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathindex.jsx
69 lines (63 loc) · 2.02 KB
/
index.jsx
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
63
64
65
66
67
68
69
import { useEffect, useState } from 'react';
import { Modal } from 'antd';
import { useDispatch, useSelector } from 'react-redux';
import { crud } from '@/redux/crud/actions';
import { useCrudContext } from '@/context/crud';
import { useAppContext } from '@/context/appContext';
import { selectDeletedItem } from '@/redux/crud/selectors';
import { valueByString } from '@/utils/helpers';
import useLanguage from '@/locale/useLanguage';
export default function DeleteModal({ config }) {
const translate = useLanguage();
let {
entity,
deleteModalLabels,
deleteMessage = translate('are_you_sure_you_want_to_delete'),
modalTitle = translate('delete_confirmation'),
} = config;
const dispatch = useDispatch();
const { current, isLoading, isSuccess } = useSelector(selectDeletedItem);
const { state, crudContextAction } = useCrudContext();
const { appContextAction } = useAppContext();
const { panel, readBox } = crudContextAction;
const { navMenu } = appContextAction;
const { isModalOpen } = state;
const { modal } = crudContextAction;
const [displayItem, setDisplayItem] = useState('');
useEffect(() => {
if (isSuccess) {
console.log('🚀 ~ useEffect ~ DeleteModal isSuccess:', isSuccess);
modal.close();
dispatch(crud.list({ entity }));
// dispatch(crud.resetAction({actionType:"delete"})); // check here maybe it wrong
}
if (current) {
let labels = deleteModalLabels.map((x) => valueByString(current, x)).join(' ');
setDisplayItem(labels);
}
}, [isSuccess, current]);
const handleOk = () => {
const id = current._id;
dispatch(crud.delete({ entity, id }));
readBox.close();
modal.close();
panel.close();
navMenu.collapse();
};
const handleCancel = () => {
if (!isLoading) modal.close();
};
return (
<Modal
title={modalTitle}
open={isModalOpen}
onOk={handleOk}
onCancel={handleCancel}
confirmLoading={isLoading}
>
<p>
{deleteMessage} {displayItem}
</p>
</Modal>
);
}