From 0f5a14e6395937fd96ef989444c15e38317ce4c1 Mon Sep 17 00:00:00 2001 From: "Mr.Hope" Date: Wed, 8 Mar 2023 23:28:46 +0800 Subject: [PATCH] refactor(admin): refine CustomPageModal --- .../src/components/CustomPageModal/index.tsx | 195 ++++++++++-------- 1 file changed, 106 insertions(+), 89 deletions(-) diff --git a/packages/admin/src/components/CustomPageModal/index.tsx b/packages/admin/src/components/CustomPageModal/index.tsx index d13f10247..6aac63805 100644 --- a/packages/admin/src/components/CustomPageModal/index.tsx +++ b/packages/admin/src/components/CustomPageModal/index.tsx @@ -1,91 +1,108 @@ -import { createCustomPage, updateCustomPage } from '@/services/van-blog/api'; -import { ModalForm, ProFormSelect, ProFormText } from '@ant-design/pro-components'; -import { Alert, Modal } from 'antd'; +import { + ModalForm, + ProFormSelect, + ProFormText, +} from "@ant-design/pro-components"; +import { Alert, Modal } from "antd"; -export default function (props) { - const { onFinish, trigger, initialValues } = props; - return ( - { - if (location.hostname == 'blog-demo.mereith.com') { - Modal.info({ - title: '演示站不可修改此项!', - }); - return; - } +import { createCustomPage, updateCustomPage } from "@/services/van-blog/api"; - const path = values.path as string; - if (path.substring(0, 1) != '/') { - Modal.info({ - title: '路径必须以反斜杠为开头!', - }); - return false; - } - if (initialValues) { - await updateCustomPage({ ...values }); - } else { - await createCustomPage(values); - } - if (onFinish) { - onFinish(); - } - return true; - }} - layout="horizontal" - labelCol={{ span: 6 }} - > - {!initialValues && ( - <> - - { - return [ - { label: '单文件页面', value: 'file' }, - { label: '多文件页面', value: 'folder' }, - ]; - }} - /> - - )} - - - - ); -} +export default ({ + onFinish, + trigger, + initialValues, +}: { + onFinish: () => void; + // FIXME: Add types + trigger: any; + // FIXME: Add types + initialValues?: any; +}) => ( + { + // FIXME: Should be refactor in to an env variable controlling "A demo state" + if (location.hostname === "blog-demo.mereith.com") { + Modal.info({ + title: "演示站不可修改此项!", + }); + return; + } + + const path = values.path as string; + + if (path.substring(0, 1) != "/") { + Modal.info({ + title: "路径必须以反斜杠为开头!", + }); + return false; + } + + if (initialValues) { + await updateCustomPage({ ...values }); + } else { + await createCustomPage(values); + } + + if (onFinish) { + onFinish(); + } + + return true; + }} + layout="horizontal" + labelCol={{ span: 6 }} + > + {!initialValues && ( + <> + + { + return [ + { label: "单文件页面", value: "file" }, + { label: "多文件页面", value: "folder" }, + ]; + }} + /> + + )} + + + +);