"use client";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { toast } from "sonner";
import {
Button,
Dialog,
FormField,
Input,
Select,
Textarea,
PageHeader,
EmptyState,
} from "@/components/ds";
import { crmApi } from "@/modules/crm/services/crm-api";
import { useTenantId } from "@/hooks/useTenantId";
import { CrmPageLoader, CrmPageError } from "@/modules/crm/pages/shared";
import { CrmBreadcrumbs } from "@/modules/crm/components/CrmBreadcrumbs";
export default function NotesPage() {
const { tenantId } = useTenantId();
const qc = useQueryClient();
const [open, setOpen] = useState(false);
const [entityType, setEntityType] = useState("lead");
const [entityId, setEntityId] = useState("");
const notesQ = useQuery({
queryKey: ["crm", tenantId, "notes", entityType, entityId],
queryFn: () => crmApi.notes.list(tenantId!, entityType, entityId),
enabled: !!tenantId && !!entityId,
});
const form = useForm({ defaultValues: { body: "" } });
const createM = useMutation({
mutationFn: (body: string) =>
crmApi.notes.create(tenantId!, { entity_type: entityType, entity_id: entityId, body }),
onSuccess: async () => {
toast.success("یادداشت ثبت شد");
setOpen(false);
form.reset();
await qc.invalidateQueries({ queryKey: ["crm", tenantId, "notes"] });
},
onError: (e: Error) => toast.error(e.message),
});
if (!tenantId) return
{n.body}
v{n.version}