Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

create-flow-modal.tsx 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { IModalManagerChildrenProps } from '@/components/modal-manager';
  2. import { useTranslate } from '@/hooks/commonHooks';
  3. import { useFetchFlowTemplates } from '@/hooks/flow-hooks';
  4. import { useSelectItem } from '@/hooks/logic-hooks';
  5. import { Card, Flex, Form, Input, Modal, Space, Typography } from 'antd';
  6. import classNames from 'classnames';
  7. import { useEffect } from 'react';
  8. import GraphAvatar from './graph-avatar';
  9. import styles from './index.less';
  10. const { Title } = Typography;
  11. interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
  12. loading: boolean;
  13. initialName: string;
  14. onOk: (name: string, templateId: string) => void;
  15. showModal?(): void;
  16. }
  17. const CreateFlowModal = ({
  18. visible,
  19. hideModal,
  20. loading,
  21. initialName,
  22. onOk,
  23. }: IProps) => {
  24. const [form] = Form.useForm();
  25. const { t } = useTranslate('common');
  26. const { data: list } = useFetchFlowTemplates();
  27. const { selectedId, handleItemClick } = useSelectItem(list?.at(0)?.id);
  28. type FieldType = {
  29. name?: string;
  30. };
  31. const handleOk = async () => {
  32. const ret = await form.validateFields();
  33. return onOk(ret.name, selectedId);
  34. };
  35. useEffect(() => {
  36. if (visible) {
  37. form.setFieldValue('name', initialName);
  38. }
  39. }, [initialName, form, visible]);
  40. return (
  41. <Modal
  42. title={t('createFlow', { keyPrefix: 'flow' })}
  43. open={visible}
  44. onOk={handleOk}
  45. width={600}
  46. onCancel={hideModal}
  47. okButtonProps={{ loading }}
  48. confirmLoading={loading}
  49. >
  50. <Form
  51. name="basic"
  52. labelCol={{ span: 4 }}
  53. wrapperCol={{ span: 20 }}
  54. autoComplete="off"
  55. layout={'vertical'}
  56. form={form}
  57. >
  58. <Form.Item<FieldType>
  59. label={<b>{t('name')}</b>}
  60. name="name"
  61. rules={[{ required: true, message: t('namePlaceholder') }]}
  62. >
  63. <Input />
  64. </Form.Item>
  65. </Form>
  66. <Title level={5}>{t('createFromTemplates', { keyPrefix: 'flow' })}</Title>
  67. <Flex vertical gap={16} className={styles.templatesBox}>
  68. {list?.map((x) => (
  69. <Card
  70. key={x.id}
  71. className={classNames(styles.flowTemplateCard, {
  72. [styles.selectedFlowTemplateCard]: selectedId === x.id,
  73. })}
  74. onClick={handleItemClick(x.id)}
  75. >
  76. <Space size={'middle'}>
  77. <GraphAvatar avatar={x.avatar}></GraphAvatar>
  78. <b>{x.title}</b>
  79. </Space>
  80. <p>{x.description}</p>
  81. </Card>
  82. ))}
  83. </Flex>
  84. </Modal>
  85. );
  86. };
  87. export default CreateFlowModal;