'use client'; import { useEffect } from 'react'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { Loader2 } from 'lucide-react'; import { toast } from 'sonner'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@/components/ui/card'; import { type PagesProject, PagesService } from '@/lib/services/openflare'; import { projectQueryKey, projectsQueryKey, sourceQueryKey, } from '../../components/pages-utils'; import { buildProjectPayload, ProjectFormFields, toFormValues, usePagesProjectForm, } from '../../components/project-form'; interface ProjectSettingsCardProps { project: PagesProject; } export function ProjectSettingsCard({ project }: ProjectSettingsCardProps) { const queryClient = useQueryClient(); const form = usePagesProjectForm(project); useEffect(() => { form.reset(toFormValues(project)); }, [form, project]); const mutation = useMutation({ mutationFn: async (values: Parameters[0]) => { const payload = buildProjectPayload(values, project); return PagesService.updateProject(project.id, payload); }, onSuccess: async () => { toast.success('项目已更新'); await Promise.all([ queryClient.invalidateQueries({ queryKey: projectsQueryKey }), queryClient.invalidateQueries({ queryKey: projectQueryKey(project.id), }), queryClient.invalidateQueries({ queryKey: sourceQueryKey(project.id), }), ]); }, onError: (error) => { toast.error(error instanceof Error ? error.message : '保存失败'); }, }); return (
编辑 Pages 项目 配置静态站点托管参数,保存后会同步到项目详情与代理引用。
mutation.mutate(values))} >
); }