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
70
71
|
import React from 'react';
import { useTranslation } from 'react-i18next';
import BaseModal from '~/components/shared/BaseModal';
import Button from './Button';
import Input from './Input';
import s from './ModalSourceIP.module.scss';
export default function ModalSourceIP({ isOpen, onRequestClose, sourceMap, setSourceMap }) {
const { t } = useTranslation();
const setSource = (key, index, val) => {
setSourceMap((prev) =>
prev.map((source, currentIndex) =>
currentIndex === index ? { ...source, [key]: val } : source
)
);
};
const removeSource = (index) => {
setSourceMap((prev) => prev.filter((_, currentIndex) => currentIndex !== index));
};
const addSource = () => {
setSourceMap((prev) => [...prev, { reg: '', name: '' }]);
};
return (
<BaseModal isOpen={isOpen} onRequestClose={onRequestClose}>
<table className={s.sourceipTable}>
<thead>
<tr>
<th>{t('c_source')}</th>
<th>{t('device_name')}</th>
</tr>
</thead>
<tbody>
{sourceMap.map((source, index) => (
<tr key={`${index}`}>
<td>
<Input
type="text"
name="reg"
autoComplete="off"
value={source.reg}
onChange={(e) => setSource('reg', index, e.target.value)}
/>
</td>
<td>
<Input
type="text"
name="name"
autoComplete="off"
value={source.name}
onChange={(e) => setSource('name', index, e.target.value)}
/>
</td>
<td>
<Button onClick={() => removeSource(index)}>{t('delete')}</Button>
</td>
</tr>
))}
</tbody>
</table>
<div>
<div className={s.iptableTipContainer}>{t('sourceip_tip')}</div>
<Button onClick={addSource}>{t('add_tag')}</Button>
</div>
</BaseModal>
);
}
|