bzp2010 commented on code in PR #3009: URL: https://github.com/apache/apisix-dashboard/pull/3009#discussion_r2068391434
########## src/routes/routes/detail.$id.tsx: ########## @@ -0,0 +1,116 @@ +import { createFileRoute, useParams } from '@tanstack/react-router'; +import { useTranslation } from 'react-i18next'; +import { useMutation, useQuery } from '@tanstack/react-query'; +import PageHeader from '@/components/page/PageHeader'; +import { FormProvider, useForm } from 'react-hook-form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { FormSubmitBtn } from '@/components/form/Btn'; +import { notifications } from '@mantine/notifications'; +import { FormTOCBox } from '@/components/form-slice/FormSection'; +import { Skeleton, Button, Group } from '@mantine/core'; +import { useBoolean } from 'react-use'; +import { useEffect } from 'react'; +import { APISIX } from '@/types/schema/apisix'; +import { getRouteQueryOptions, putRouteReq } from '@/apis/routes'; +import { FormPartRoute } from '@/components/form-slice/FormPartRoute'; +import { pipeProduce } from '@/utils/producer'; +import { FormSectionGeneral } from '@/components/form-slice/FormSectionGeneral'; + +type Props = { + readOnly: boolean; + setReadOnly: (v: boolean) => void; +}; + +const RouteDetailForm = (props: Props) => { + const { readOnly, setReadOnly } = props; + const { t } = useTranslation(); + const { id } = useParams({ from: '/routes/detail/$id' }); + + const routeQuery = useQuery(getRouteQueryOptions(id)); + const { data: routeData, isLoading, refetch } = routeQuery; + + const form = useForm({ + resolver: zodResolver(APISIX.Route), + shouldUnregister: true, + shouldFocusError: true, + mode: 'all', + disabled: readOnly, + }); + + // 将API数据加载到表单中 + useEffect(() => { + if (routeData?.value && !isLoading) { + form.reset(routeData.value); + } + }, [routeData, form, isLoading]); + + // 处理表单提交和路由更新 Review Comment: ditto ########## src/routes/routes/detail.$id.tsx: ########## @@ -0,0 +1,116 @@ +import { createFileRoute, useParams } from '@tanstack/react-router'; +import { useTranslation } from 'react-i18next'; +import { useMutation, useQuery } from '@tanstack/react-query'; +import PageHeader from '@/components/page/PageHeader'; +import { FormProvider, useForm } from 'react-hook-form'; +import { zodResolver } from '@hookform/resolvers/zod'; +import { FormSubmitBtn } from '@/components/form/Btn'; +import { notifications } from '@mantine/notifications'; +import { FormTOCBox } from '@/components/form-slice/FormSection'; +import { Skeleton, Button, Group } from '@mantine/core'; +import { useBoolean } from 'react-use'; +import { useEffect } from 'react'; +import { APISIX } from '@/types/schema/apisix'; +import { getRouteQueryOptions, putRouteReq } from '@/apis/routes'; +import { FormPartRoute } from '@/components/form-slice/FormPartRoute'; +import { pipeProduce } from '@/utils/producer'; +import { FormSectionGeneral } from '@/components/form-slice/FormSectionGeneral'; + +type Props = { + readOnly: boolean; + setReadOnly: (v: boolean) => void; +}; + +const RouteDetailForm = (props: Props) => { + const { readOnly, setReadOnly } = props; + const { t } = useTranslation(); + const { id } = useParams({ from: '/routes/detail/$id' }); + + const routeQuery = useQuery(getRouteQueryOptions(id)); + const { data: routeData, isLoading, refetch } = routeQuery; + + const form = useForm({ + resolver: zodResolver(APISIX.Route), + shouldUnregister: true, + shouldFocusError: true, + mode: 'all', + disabled: readOnly, + }); + + // 将API数据加载到表单中 Review Comment: remove comments in chinese -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org