summaryrefslogtreecommitdiff
path: root/src/components/ModalSourceIP.tsx
blob: a4066014f4707dd186944c085709b9d8896514f2 (plain)
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
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) => {
    sourceMap[index][key] = val;
    setSourceMap(Array.from(sourceMap));
  };

  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={() => sourceMap.splice(index, 1)}>{t('delete')}</Button>
              </td>
            </tr>
          ))}
        </tbody>
      </table>
      <div>
        <div className={s.iptableTipContainer}>{t('sourceip_tip')}</div>
        <Button onClick={() => sourceMap.push({ reg: '', name: '' })}>{t('add_tag')}</Button>
      </div>
    </BaseModal>
  );
}