From 297186d1eaf2bcb3c2e42489cfcc174630fc13bb Mon Sep 17 00:00:00 2001 From: robin Date: Thu, 10 Nov 2022 16:06:56 +0800 Subject: [PATCH] feat(ui): add timezone,upload type --- ui/src/components/SchemaForm/index.tsx | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/ui/src/components/SchemaForm/index.tsx b/ui/src/components/SchemaForm/index.tsx index 4c7a01d0..becf5fbf 100644 --- a/ui/src/components/SchemaForm/index.tsx +++ b/ui/src/components/SchemaForm/index.tsx @@ -2,6 +2,8 @@ import { FC } from 'react'; import { Form, Button, Stack } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; +import BrandUpload from '../BrandUpload'; +import TimeZonePicker from '../TimeZonePicker'; import type * as Type from '@/common/interface'; export interface JSONSchema { @@ -27,6 +29,8 @@ export interface UISchema { | 'checkbox' | 'radio' | 'select' + | 'upload' + | 'timezone' | 'switch'; 'ui:options'?: { rows?: number; @@ -49,6 +53,8 @@ export interface UISchema { empty?: string; invalid?: string; validator?: (value) => boolean; + textRender?: () => React.ReactElement; + imageType?: 'avatar' | 'logo'; }; }; } @@ -61,6 +67,14 @@ interface IProps { onSubmit: (e: React.FormEvent) => void; } +/** + * json schema form + * @param schema json schema + * @param uiSchema ui schema + * @param formData form data + * @param onChange change event + * @param onSubmit submit event + */ const SchemaForm: FC = ({ schema, uiSchema = {}, @@ -81,6 +95,7 @@ const SchemaForm: FC = ({ onChange(data); } }; + const requiredValidator = () => { const required = schema.required || []; const errors: string[] = []; @@ -91,6 +106,7 @@ const SchemaForm: FC = ({ }); return errors; }; + const syncValidator = () => { const errors: string[] = []; keys.forEach((key) => { @@ -104,6 +120,7 @@ const SchemaForm: FC = ({ }); return errors; }; + const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); const errors = requiredValidator(); @@ -149,6 +166,14 @@ const SchemaForm: FC = ({ } onSubmit(e); }; + + const handleUploadChange = (name: string, value: string) => { + const data = { ...formData, [name]: { ...formData[name], value } }; + if (onChange instanceof Function) { + onChange(data); + } + }; + return (
{keys.map((key) => { @@ -222,6 +247,32 @@ const SchemaForm: FC = ({ ); } + if (widget === 'timezone') { + return ( + + {title} + + {description} + + ); + } + + if (widget === 'upload') { + return ( + + {title} + handleUploadChange(key, value)} + /> + {description} + + ); + } const as = widget === 'textarea' ? 'textarea' : 'input'; return (