accounts-list.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { useTranslation } from 'react-i18next';
  2. import { Button, Form, Input, Space } from 'antd';
  3. import { MinusOutlined, PlusOutlined } from '@ant-design/icons';
  4. import { RandomUtil } from '@/utils';
  5. import { InputAddon } from '@/components/ui';
  6. export default function AccountsList() {
  7. const { t } = useTranslation();
  8. return (
  9. <Form.List name={['settings', 'accounts']}>
  10. {(fields, { add, remove }) => (
  11. <>
  12. <Form.Item label={t('pages.inbounds.form.accounts')}>
  13. <Button
  14. size="small"
  15. onClick={() => add({
  16. user: RandomUtil.randomLowerAndNum(8),
  17. pass: RandomUtil.randomLowerAndNum(12),
  18. })}
  19. >
  20. <PlusOutlined /> {t('add')}
  21. </Button>
  22. </Form.Item>
  23. {fields.length > 0 && (
  24. <Form.Item wrapperCol={{ span: 24 }}>
  25. {fields.map((field, idx) => (
  26. <Space.Compact key={field.key} className="mb-8" block>
  27. <InputAddon>{String(idx + 1)}</InputAddon>
  28. <Form.Item name={[field.name, 'user']} noStyle>
  29. <Input placeholder={t('username')} />
  30. </Form.Item>
  31. <Form.Item name={[field.name, 'pass']} noStyle>
  32. <Input placeholder={t('password')} />
  33. </Form.Item>
  34. <Button onClick={() => remove(field.name)}>
  35. <MinusOutlined />
  36. </Button>
  37. </Space.Compact>
  38. ))}
  39. </Form.Item>
  40. )}
  41. </>
  42. )}
  43. </Form.List>
  44. );
  45. }