"use client"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { toast } from "sonner"; import { accountingApi } from "@/lib/accounting-api"; import { useTenantId } from "@/hooks/useTenantId"; import { PageHeader, LoadingState, ErrorState, Card, CardContent, CardHeader, CardTitle, Button, Input, FormField, } from "@/components/ds"; type CompanyForm = { legal_name: string; trade_name: string; national_id: string; economic_code: string; registration_number: string; postal_code: string; province: string; city: string; address: string; phone: string; mobile: string; email: string; website: string; ceo_name: string; accountant_name: string; }; const EMPTY: CompanyForm = { legal_name: "", trade_name: "", national_id: "", economic_code: "", registration_number: "", postal_code: "", province: "", city: "", address: "", phone: "", mobile: "", email: "", website: "", ceo_name: "", accountant_name: "", }; export default function CompanySettingsPage() { const { tenantId } = useTenantId(); const qc = useQueryClient(); const form = useForm({ defaultValues: EMPTY }); const profileQ = useQuery({ queryKey: ["accounting", tenantId, "company-profile"], queryFn: () => accountingApi.setup.getCompanyProfile(tenantId!), enabled: !!tenantId, }); useEffect(() => { if (profileQ.data) { form.reset({ ...EMPTY, ...profileQ.data }); } }, [profileQ.data, form]); const saveM = useMutation({ mutationFn: (data: CompanyForm) => accountingApi.setup.updateCompanyProfile(tenantId!, data), onSuccess: async () => { toast.success("اطلاعات شرکت ذخیره شد"); await qc.invalidateQueries({ queryKey: ["accounting", tenantId, "company-profile"] }); }, onError: (e: Error) => toast.error(e.message), }); if (!tenantId || profileQ.isLoading) return ; if (profileQ.error) { return profileQ.refetch()} />; } return (
saveM.mutate(d))}> هویت حقوقی آدرس و تماس
اشخاص مرتبط (اختیاری)
); }