Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

index.tsx 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import { IModalManagerChildrenProps } from '@/components/modal-manager';
  2. import { useTranslate } from '@/hooks/common-hooks';
  3. import { Form, Input, Modal } from 'antd';
  4. import { useEffect } from 'react';
  5. interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
  6. loading: boolean;
  7. initialName: string;
  8. onOk: (name: string) => void;
  9. showModal?(): void;
  10. }
  11. const RenameModal = ({
  12. visible,
  13. onOk,
  14. loading,
  15. initialName,
  16. hideModal,
  17. }: IProps) => {
  18. const [form] = Form.useForm();
  19. const { t } = useTranslate('common');
  20. type FieldType = {
  21. name?: string;
  22. };
  23. const handleOk = async () => {
  24. const ret = await form.validateFields();
  25. onOk(ret.name);
  26. };
  27. const onFinish = (values: any) => {
  28. console.log('Success:', values);
  29. };
  30. const onFinishFailed = (errorInfo: any) => {
  31. console.log('Failed:', errorInfo);
  32. };
  33. useEffect(() => {
  34. if (visible) {
  35. form.setFieldValue('name', initialName);
  36. }
  37. }, [initialName, form, visible]);
  38. return (
  39. <Modal
  40. title={t('rename')}
  41. open={visible}
  42. onOk={handleOk}
  43. onCancel={hideModal}
  44. okButtonProps={{ loading }}
  45. >
  46. <Form
  47. name="basic"
  48. labelCol={{ span: 4 }}
  49. wrapperCol={{ span: 20 }}
  50. style={{ maxWidth: 600 }}
  51. onFinish={onFinish}
  52. onFinishFailed={onFinishFailed}
  53. autoComplete="off"
  54. form={form}
  55. >
  56. <Form.Item<FieldType>
  57. label={t('name')}
  58. name="name"
  59. rules={[{ required: true, message: t('namePlaceholder') }]}
  60. >
  61. <Input />
  62. </Form.Item>
  63. </Form>
  64. </Modal>
  65. );
  66. };
  67. export default RenameModal;