From f5151aa2a4185714f1f988a2bad336b90f410b69 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Mon, 16 Sep 2024 00:18:28 +0800 Subject: [PATCH] refactor: remove unused code and improve display view in status page --- .../monitor/StatusPage/EditForm.tsx | 73 ++++++++----------- .../components/monitor/StatusPage/index.tsx | 47 ++++++++---- src/client/components/ui/form.tsx | 9 ++- 3 files changed, 70 insertions(+), 59 deletions(-) diff --git a/src/client/components/monitor/StatusPage/EditForm.tsx b/src/client/components/monitor/StatusPage/EditForm.tsx index 265c233..5212a70 100644 --- a/src/client/components/monitor/StatusPage/EditForm.tsx +++ b/src/client/components/monitor/StatusPage/EditForm.tsx @@ -2,12 +2,12 @@ import React from 'react'; import { MonitorPicker } from '../MonitorPicker'; import { useTranslation } from '@i18next-toolkit/react'; import { Button } from '@/components/ui/button'; -import { LuMinus, LuMinusCircle, LuPlus } from 'react-icons/lu'; +import { LuMinusCircle, LuPlus } from 'react-icons/lu'; import { MarkdownEditor } from '@/components/MarkdownEditor'; import { z } from 'zod'; import { zodResolver } from '@hookform/resolvers/zod'; import { useEventWithLoading } from '@/hooks/useEvent'; -import { Input as AntdInput, Divider, Typography } from 'antd'; +import { Input as AntdInput, Typography } from 'antd'; import { Form, FormControl, @@ -22,6 +22,7 @@ import { Controller, useFieldArray, useForm } from 'react-hook-form'; import { domainRegex, slugRegex } from '@tianji/shared'; import { useElementSize } from '@/hooks/useResizeObserver'; import { Switch } from '@/components/ui/switch'; +import { Separator } from '@/components/ui/separator'; const Text = Typography.Text; @@ -140,7 +141,7 @@ export const MonitorStatusPageEditForm: React.FC name="description" render={({ field }) => ( - {t('Description')} + {t('Description')} @@ -155,7 +156,7 @@ export const MonitorStatusPageEditForm: React.FC name="domain" render={({ field }) => ( - {t('Custom Domain')} + {t('Custom Domain')} @@ -178,51 +179,41 @@ export const MonitorStatusPageEditForm: React.FC render={() => ( {t('Monitor List')} - {fields.map((field, i) => { - const { onChange: onMonitorChange, ...monitorProps } = - form.register(`monitorList.${i}.id`, { - onChange: (e) => console.log(e.target.value), - }); - const { onChange: onShowCurrentChange, ...showCurrentProps } = - form.register(`monitorList.${i}.showCurrent`); + {fields.map((field, i) => ( + <> + {i !== 0 && } - return ( - <> - {i !== 0 && } +
+ } + /> -
+
} + name={`monitorList.${i}.showCurrent`} + render={({ field }) => ( + + )} /> -
- ( - - )} - /> + + {t('Show Latest Value')} + - - {t('Show Latest Value')} - - - remove(i)} - /> -
+ remove(i)} + />
- - ); - })} +
+ + ))} + + + {t('Modify Status Page Info')} + + + + setEditMode(false)} + /> + + + ); + return (
@@ -92,21 +119,9 @@ export const MonitorStatusPage: React.FC = React.memo( - {editMode && ( -
- setEditMode(false)} - /> -
- )} -
@@ -115,11 +130,11 @@ export const MonitorStatusPage: React.FC = React.memo(
- {allowEdit && !editMode && ( + {allowEdit && (
- + {editBtn} - {showBackBtn && ( + {showBackBtn && !editMode && ( diff --git a/src/client/components/ui/form.tsx b/src/client/components/ui/form.tsx index b0986d1..0ba4189 100644 --- a/src/client/components/ui/form.tsx +++ b/src/client/components/ui/form.tsx @@ -12,6 +12,7 @@ import { import { cn } from "@/utils/style" import { Label } from "@/components/ui/label" +import { useTranslation } from "@i18next-toolkit/react" const Form = FormProvider @@ -86,9 +87,10 @@ FormItem.displayName = "FormItem" const FormLabel = React.forwardRef< React.ElementRef, - React.ComponentPropsWithoutRef + React.ComponentPropsWithoutRef & {optional?: boolean} >(({ className, ...props }, ref) => { const { error, formItemId } = useFormField() + const { t } = useTranslation() return ( ) }) FormLabel.displayName = "FormLabel"