refactor: 面板modal与表单校验

pull/13/head
moonrailgun 4 years ago
parent 6495c1980d
commit 7d42525241

@ -21,6 +21,10 @@ export type {
FastFormFieldMeta, FastFormFieldMeta,
FastFormContainerComponent, FastFormContainerComponent,
} from './components/FastForm/index'; } from './components/FastForm/index';
export {
createFastFormSchema,
fieldSchema,
} from './components/FastForm/schema';
export { buildPortal, DefaultEventEmitter } from './components/Portal'; export { buildPortal, DefaultEventEmitter } from './components/Portal';
export { TcProvider } from './components/Provider'; export { TcProvider } from './components/Provider';

@ -95,7 +95,7 @@ export const ModalCreateGroup: React.FC = React.memo(() => {
}, [name, panels]); }, [name, panels]);
return ( return (
<ModalWrapper> <ModalWrapper style={{ maxWidth: 440 }}>
<Slides ref={slidesRef}> <Slides ref={slidesRef}>
<div> <div>
<Typography.Title level={4} className="text-center mb-4"> <Typography.Title level={4} className="text-center mb-4">

@ -1,4 +1,4 @@
import { PluginGroupPanel, pluginGroupPanel } from '@/plugin/common'; import { pluginGroupPanel } from '@/plugin/common';
import { findPluginPanelInfoByName } from '@/utils/plugin-helper'; import { findPluginPanelInfoByName } from '@/utils/plugin-helper';
import React, { useMemo, useState } from 'react'; import React, { useMemo, useState } from 'react';
import { import {
@ -7,6 +7,8 @@ import {
t, t,
useAsyncRequest, useAsyncRequest,
createGroupPanel, createGroupPanel,
createFastFormSchema,
fieldSchema,
} from 'tailchat-shared'; } from 'tailchat-shared';
import { ModalWrapper } from '../Modal'; import { ModalWrapper } from '../Modal';
import { WebFastForm } from '../WebFastForm'; import { WebFastForm } from '../WebFastForm';
@ -40,6 +42,14 @@ const baseFields: FastFormFieldMeta[] = [
}, },
]; ];
const schema = createFastFormSchema({
name: fieldSchema
.string()
.required(t('面板名不能为空'))
.max(20, t('面板名过长')),
type: fieldSchema.string().required(t('面板类型不能为空')),
});
/** /**
* *
*/ */
@ -95,8 +105,9 @@ export const ModalCreateGroupPanel: React.FC<{
}, [currentValues]); }, [currentValues]);
return ( return (
<ModalWrapper title={t('创建群组面板')} style={{ width: 440 }}> <ModalWrapper title={t('创建群组面板')} style={{ maxWidth: 440 }}>
<WebFastForm <WebFastForm
schema={schema}
fields={field} fields={field}
onChange={setValues} onChange={setValues}
onSubmit={handleSubmit} onSubmit={handleSubmit}

@ -49,6 +49,14 @@
color: white; color: white;
} }
// 表单错误
.ant-form-item-has-error {
.ant-input:not(.ant-input-disabled) {
background-color: transparent;
border-color: var(--antd-primary-dangerous-color);
}
}
// 分割线 // 分割线
.ant-divider { .ant-divider {
border-top-color: rgba(255,255,255,0.12); border-top-color: rgba(255,255,255,0.12);

Loading…
Cancel
Save