From 53c0fd563d535c4ccfd7f0dd4f1e016e60ff2599 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Wed, 27 Sep 2023 16:57:46 +0800 Subject: [PATCH] feat: notification form and modal and global scrollbar --- .../modals/NotificationInfo/index.tsx | 110 +++++++++++++----- .../NotificationInfo/strategies/smtp.tsx | 22 ++-- src/client/index.css | 32 +++++ .../pages/Settings/NotificationList.tsx | 11 +- 4 files changed, 135 insertions(+), 40 deletions(-) diff --git a/src/client/components/modals/NotificationInfo/index.tsx b/src/client/components/modals/NotificationInfo/index.tsx index 42d6ad5..c598a71 100644 --- a/src/client/components/modals/NotificationInfo/index.tsx +++ b/src/client/components/modals/NotificationInfo/index.tsx @@ -1,19 +1,40 @@ -import { Form, Input, Modal, ModalProps, Select } from 'antd'; +import { + Button, + Form, + FormProps, + Input, + Modal, + ModalProps, + Select, +} from 'antd'; import React, { useMemo, useState } from 'react'; +import { request } from '../../../api/request'; +import { useEvent } from '../../../hooks/useEvent'; import { notificationStrategies } from './strategies'; +export interface NotificationFormValues { + name: string; + type: string; + payload: Record; +} + +const defaultValues: Omit = { + name: 'New Notification', + type: notificationStrategies[0].name, +}; + interface NotificationInfoModalProps - extends Pick {} + extends Pick, + Pick { + onSubmit: (values: NotificationFormValues) => void; +} export const NotificationInfoModal: React.FC = React.memo((props) => { - const [notificationType, setNotificationType] = useState( - notificationStrategies[0].name - ); + const [form] = Form.useForm(); + const typeValue = Form.useWatch('type', form); - const form = useMemo(() => { - const strategy = notificationStrategies.find( - (s) => s.name === notificationType - ); + const formEl = useMemo(() => { + const strategy = notificationStrategies.find((s) => s.name === typeValue); if (!strategy) { return null; @@ -22,33 +43,68 @@ export const NotificationInfoModal: React.FC = const Component = strategy.form; return ; - }, [notificationType]); + }, [typeValue]); + + const handleSave = useEvent(async () => { + await form.validateFields(); + const values = form.getFieldsValue(); + const { name, type, ...payload } = values; + + props.onSubmit({ + name, + type, + payload, + }); + }); + + const handleTest = useEvent(async () => { + await form.validateFields(); + const values = form.getFieldsValue(); + const { name, type, ...payload } = values; + + console.log('TODO', { name, type, payload }); + }); return ( + + + + } > -
- - - +
+ + + + - - - + + + - {form} - + {formEl} + +
); }); diff --git a/src/client/components/modals/NotificationInfo/strategies/smtp.tsx b/src/client/components/modals/NotificationInfo/strategies/smtp.tsx index 67fb8b8..759552f 100644 --- a/src/client/components/modals/NotificationInfo/strategies/smtp.tsx +++ b/src/client/components/modals/NotificationInfo/strategies/smtp.tsx @@ -4,31 +4,35 @@ import React from 'react'; export const NotificationSMTP: React.FC = React.memo(() => { return ( <> - + - + - + -
+ Ignore TLS Error - - + + - + - + - + diff --git a/src/client/index.css b/src/client/index.css index e8b05f5..04d0a7f 100644 --- a/src/client/index.css +++ b/src/client/index.css @@ -23,6 +23,38 @@ a { height: 100%; } +/* 滚动条 */ +::-webkit-scrollbar { + width: 8px; + height: 8px; +} + +::-webkit-scrollbar-corner { + background-color: transparent; +} + +::-webkit-scrollbar-thumb { + @apply bg-black bg-opacity-10; + border-color: transparent; + background-clip: padding-box; + border-width: 2px; + border-style: solid; + border-radius: 4px; +} + +::-webkit-scrollbar-thumb:hover { + @apply bg-black bg-opacity-20; +} + +::-webkit-scrollbar-track { + @apply bg-black bg-opacity-5; + border-color: transparent; + background-clip: padding-box; + border-width: 2px; + border-style: solid; + border-radius: 4px; +} + @tailwind base; @tailwind components; @tailwind utilities; diff --git a/src/client/pages/Settings/NotificationList.tsx b/src/client/pages/Settings/NotificationList.tsx index 0b6481c..426668b 100644 --- a/src/client/pages/Settings/NotificationList.tsx +++ b/src/client/pages/Settings/NotificationList.tsx @@ -1,15 +1,18 @@ import { PlusOutlined } from '@ant-design/icons'; import { Button, List } from 'antd'; import React, { useState } from 'react'; -import { NotificationInfoModal } from '../../components/modals/NotificationInfo'; +import { + NotificationFormValues, + NotificationInfoModal, +} from '../../components/modals/NotificationInfo'; import { PageHeader } from '../../components/PageHeader'; import { useEvent } from '../../hooks/useEvent'; export const NotificationList: React.FC = React.memo(() => { const [open, setOpen] = useState(false); - const handleOk = useEvent(() => { - console.log('ok'); + const handleSubmit = useEvent((values: NotificationFormValues) => { + console.log('ok', values); setOpen(false); }); @@ -47,7 +50,7 @@ export const NotificationList: React.FC = React.memo(() => { setOpen(false)} />