import { Button, Divider, Input, Typography } from 'antd'; import React, { Fragment, useCallback, useRef, useState } from 'react'; import { createGroup, GroupPanelType, t, useAppDispatch, useAsyncRequest, } from 'tailchat-shared'; import type { GroupPanel } from 'tailchat-shared'; import { Avatar } from '../Avatar'; import { closeModal, ModalWrapper } from '../Modal'; import { Slides, SlidesRef } from '../Slides'; import { groupActions } from '../../../../shared/redux/slices'; const panelTemplate: { key: string; label: string; panels: GroupPanel[]; }[] = [ { key: 'default', label: t('默认群组'), panels: [ { id: '00', name: t('文字频道'), type: GroupPanelType.GROUP, }, { id: '01', name: t('大厅'), parentId: '00', type: GroupPanelType.TEXT, }, ], }, { key: 'work', label: t('工作协同'), panels: [ { id: '00', name: t('公共'), type: GroupPanelType.GROUP, }, { id: '01', name: t('全员'), parentId: '00', type: GroupPanelType.TEXT, }, { id: '10', name: t('临时会议'), type: GroupPanelType.GROUP, }, { id: '11', name: t('会议室') + '1', parentId: '10', type: GroupPanelType.TEXT, }, { id: '11', name: t('会议室') + '2', parentId: '10', type: GroupPanelType.TEXT, }, ], }, ]; export const ModalCreateGroup: React.FC = React.memo(() => { const slidesRef = useRef(null); const [panels, setPanels] = useState([]); const [name, setName] = useState(''); const dispatch = useAppDispatch(); const handleSelectTemplate = useCallback((panels: GroupPanel[]) => { setPanels(panels); slidesRef.current?.next(); }, []); const handleBack = useCallback(() => { slidesRef.current?.prev(); }, []); const [{ loading }, handleCreate] = useAsyncRequest(async () => { const data = await createGroup(name, panels); dispatch(groupActions.appendGroups([data])); closeModal(); }, [name, panels]); return (
{t('创建群组')} {t('选择以下模板, 开始创建属于自己的群组吧!')}
{panelTemplate.map((template, index) => ( {/* Hardcode: 将第一个模板与之后的模板区分开 */} {index === 1 && }
handleSelectTemplate(template.panels)} > {template.label}
))}
{t('自定义你的群组')} {t('不要担心, 在此之后你可以随时进行变更')}
{/* TODO: update avatar */}
{t('群组名称')}:
setName(e.target.value)} />
); }); ModalCreateGroup.displayName = 'ModalCreateGroup';