diff --git a/src/app/tickets/new/page.tsx b/src/app/tickets/new/page.tsx index 1efa7fa..b0fc556 100644 --- a/src/app/tickets/new/page.tsx +++ b/src/app/tickets/new/page.tsx @@ -49,7 +49,7 @@ export default function NewTicketPage() { const queueArgs = queuesEnabled ? { tenantId: DEFAULT_TENANT_ID, viewerId: convexUserId as Id<"users"> } : undefined - const queuesRemote = useQuery(queuesEnabled ? api.queues.summary : "skip", queueArgs) + const queuesRemote = useQuery(queuesEnabled ? api.queues.summary : undefined, queueArgs) const queues = useMemo( () => (Array.isArray(queuesRemote) ? (queuesRemote as TicketQueueSummary[]) : []), [queuesRemote] @@ -66,10 +66,7 @@ export default function NewTicketPage() { const companiesArgs = directoryQueryEnabled ? { tenantId: DEFAULT_TENANT_ID, viewerId: convexUserId as Id<"users"> } : undefined - const companiesRemote = useQuery( - directoryQueryEnabled ? api.companies.list : "skip", - companiesArgs - ) + const companiesRemote = useQuery(directoryQueryEnabled ? api.companies.list : undefined, companiesArgs) const companies = useMemo( () => (Array.isArray(companiesRemote) ? companiesRemote : []).map((company) => ({ @@ -83,10 +80,7 @@ export default function NewTicketPage() { const customersArgs = directoryQueryEnabled ? { tenantId: DEFAULT_TENANT_ID, viewerId: convexUserId as Id<"users"> } : undefined - const customersRemote = useQuery( - directoryQueryEnabled ? api.users.listCustomers : "skip", - customersArgs - ) + const customersRemote = useQuery(directoryQueryEnabled ? api.users.listCustomers : undefined, customersArgs) const customers = useMemo( () => (Array.isArray(customersRemote) ? (customersRemote as CustomerOption[]) : []), [customersRemote] diff --git a/src/components/admin/admin-users-manager.tsx b/src/components/admin/admin-users-manager.tsx index 41c3fbc..26b33d9 100644 --- a/src/components/admin/admin-users-manager.tsx +++ b/src/components/admin/admin-users-manager.tsx @@ -375,8 +375,8 @@ export function AdminUsersManager({ linkedUsers?: Array<{ id: string; email: string; name: string }> } const machinesList = useQuery( - convexUserId ? api.machines.listByTenant : "skip", - convexUserId ? { tenantId: defaultTenantId, includeMetadata: true } : ("skip" as const) + convexUserId ? api.machines.listByTenant : undefined, + convexUserId ? { tenantId: defaultTenantId, includeMetadata: true } : undefined ) as MachinesListItem[] | undefined const machinesByUserEmail = useMemo(() => { diff --git a/src/components/admin/alerts/admin-alerts-manager.tsx b/src/components/admin/alerts/admin-alerts-manager.tsx index a443a8d..c6d0bf6 100644 --- a/src/components/admin/alerts/admin-alerts-manager.tsx +++ b/src/components/admin/alerts/admin-alerts-manager.tsx @@ -25,7 +25,7 @@ export function AdminAlertsManager() { }, [range]) const alertsRaw = useQuery( - api.alerts.list, + convexUserId ? api.alerts.list : undefined, convexUserId ? ({ tenantId, @@ -34,7 +34,7 @@ export function AdminAlertsManager() { end, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">), }) - : "skip" + : undefined ) as Doc<"alerts">[] | undefined const alerts = useMemo(() => { @@ -43,8 +43,8 @@ export function AdminAlertsManager() { }, [alertsRaw]) const companies = useQuery( - api.companies.list, - convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip" + convexUserId ? api.companies.list : undefined, + convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined ) as Array<{ id: Id<"companies">; name: string }> | undefined return ( diff --git a/src/components/admin/fields/fields-manager.tsx b/src/components/admin/fields/fields-manager.tsx index b46faf0..a79930a 100644 --- a/src/components/admin/fields/fields-manager.tsx +++ b/src/components/admin/fields/fields-manager.tsx @@ -44,8 +44,8 @@ export function FieldsManager() { const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID const fields = useQuery( - api.fields.list, - convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip" + convexUserId ? api.fields.list : undefined, + convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined ) as Field[] | undefined const createField = useMutation(api.fields.create) diff --git a/src/components/admin/machines/admin-machine-details.client.tsx b/src/components/admin/machines/admin-machine-details.client.tsx index 5d72995..d3397b6 100644 --- a/src/components/admin/machines/admin-machine-details.client.tsx +++ b/src/components/admin/machines/admin-machine-details.client.tsx @@ -21,11 +21,12 @@ export function AdminMachineDetailsClient({ tenantId: _tenantId, machineId }: { const routeMachineId = Array.isArray(params?.id) ? params?.id[0] : params?.id const effectiveMachineId = machineId ?? routeMachineId ?? "" - const queryArgs = effectiveMachineId + const canLoadMachine = Boolean(effectiveMachineId) + const queryArgs = canLoadMachine ? ({ id: effectiveMachineId as Id<"machines">, includeMetadata: true } as const) - : "skip" + : undefined - const single = useQuery(api.machines.getById, queryArgs) + const single = useQuery(canLoadMachine ? api.machines.getById : undefined, queryArgs) // Fallback via HTTP in caso de o Convex React demorar/ficar preso em loading const [fallback, setFallback] = useState | null | undefined>(undefined) diff --git a/src/components/admin/machines/admin-machines-overview.tsx b/src/components/admin/machines/admin-machines-overview.tsx index 5cef84e..44af4e9 100644 --- a/src/components/admin/machines/admin-machines-overview.tsx +++ b/src/components/admin/machines/admin-machines-overview.tsx @@ -1206,8 +1206,8 @@ export function AdminMachinesOverview({ tenantId, initialCompanyFilterSlug = "al const [exportError, setExportError] = useState(null) const { convexUserId } = useAuth() const companies = useQuery( - convexUserId ? api.companies.list : "skip", - convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : ("skip" as const) + convexUserId ? api.companies.list : undefined, + convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined ) as Array<{ id: string; name: string; slug?: string }> | undefined const companyNameBySlug = useMemo(() => { const map = new Map() @@ -1698,13 +1698,13 @@ export function MachineDetails({ machine }: MachineDetailsProps) { const [isActiveLocal, setIsActiveLocal] = useState(machine?.isActive ?? true) const isDeactivated = !isActiveLocal || effectiveStatus === "deactivated" const alertsHistory = useQuery( - machine ? api.machines.listAlerts : "skip", - machine ? { machineId: machine.id as Id<"machines">, limit: 50 } : ("skip" as const) + machine ? api.machines.listAlerts : undefined, + machine ? { machineId: machine.id as Id<"machines">, limit: 50 } : undefined ) as MachineAlertEntry[] | undefined const machineAlertsHistory = alertsHistory ?? [] const openTickets = useQuery( - machine ? api.machines.listOpenTickets : "skip", - machine ? { machineId: machine.id as Id<"machines">, limit: 6 } : ("skip" as const) + machine ? api.machines.listOpenTickets : undefined, + machine ? { machineId: machine.id as Id<"machines">, limit: 6 } : undefined ) as MachineOpenTicketsSummary | undefined const machineTickets = openTickets?.tickets ?? [] const totalOpenTickets = openTickets?.totalOpen ?? machineTickets.length diff --git a/src/components/admin/machines/machine-breadcrumbs.client.tsx b/src/components/admin/machines/machine-breadcrumbs.client.tsx index 6666681..cbd8e59 100644 --- a/src/components/admin/machines/machine-breadcrumbs.client.tsx +++ b/src/components/admin/machines/machine-breadcrumbs.client.tsx @@ -21,11 +21,12 @@ type MachineBreadcrumbsProps = { export function MachineBreadcrumbs({ tenantId: _tenantId, machineId, machineHref, extra }: MachineBreadcrumbsProps) { const { convexUserId } = useAuth() - const queryArgs = machineId && convexUserId + const canLoadMachine = Boolean(machineId && convexUserId) + const queryArgs = canLoadMachine ? ({ id: machineId as Id<"machines">, includeMetadata: false } as const) - : "skip" + : undefined - const item = useQuery(api.machines.getById, queryArgs) + const item = useQuery(canLoadMachine ? api.machines.getById : undefined, queryArgs) const hostname = useMemo(() => item?.hostname ?? "Detalhe", [item]) const segments = useMemo(() => { const trail: BreadcrumbSegment[] = [ diff --git a/src/components/admin/queues/queues-manager.tsx b/src/components/admin/queues/queues-manager.tsx index 05777c3..39bbb1f 100644 --- a/src/components/admin/queues/queues-manager.tsx +++ b/src/components/admin/queues/queues-manager.tsx @@ -38,12 +38,12 @@ export function QueuesManager() { const NO_TEAM_VALUE = "__none__" const queues = useQuery( - api.queues.list, - convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip" + convexUserId ? api.queues.list : undefined, + convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined ) as Queue[] | undefined const teams = useQuery( - api.teams.list, - convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip" + convexUserId ? api.teams.list : undefined, + convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined ) as TeamOption[] | undefined const createQueue = useMutation(api.queues.create) diff --git a/src/components/admin/slas/slas-manager.tsx b/src/components/admin/slas/slas-manager.tsx index 268ba4f..89d2a97 100644 --- a/src/components/admin/slas/slas-manager.tsx +++ b/src/components/admin/slas/slas-manager.tsx @@ -37,8 +37,8 @@ export function SlasManager() { const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID const slas = useQuery( - api.slas.list, - convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip" + convexUserId ? api.slas.list : undefined, + convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined ) as SlaPolicy[] | undefined const createSla = useMutation(api.slas.create) diff --git a/src/components/admin/teams/teams-manager.tsx b/src/components/admin/teams/teams-manager.tsx index b554ac0..ec24af0 100644 --- a/src/components/admin/teams/teams-manager.tsx +++ b/src/components/admin/teams/teams-manager.tsx @@ -39,12 +39,12 @@ export function TeamsManager() { const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID const teams = useQuery( - api.teams.list, - convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip" + convexUserId ? api.teams.list : undefined, + convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined ) as Team[] | undefined const directory = useQuery( - api.teams.directory, - convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip" + convexUserId ? api.teams.directory : undefined, + convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined ) as DirectoryUser[] | undefined const createTeam = useMutation(api.teams.create) diff --git a/src/components/chart-area-interactive.tsx b/src/components/chart-area-interactive.tsx index b84af72..22f771d 100644 --- a/src/components/chart-area-interactive.tsx +++ b/src/components/chart-area-interactive.tsx @@ -64,12 +64,15 @@ export function ChartAreaInteractive() { const reportsEnabled = Boolean(isStaff && convexUserId) const report = useQuery( - api.reports.ticketsByChannel, + reportsEnabled ? api.reports.ticketsByChannel : undefined, reportsEnabled ? ({ tenantId, viewerId: convexUserId as Id<"users">, range: timeRange, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">) }) - : "skip" + : undefined ) - const companies = useQuery(api.companies.list, reportsEnabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as Array<{ id: Id<"companies">; name: string }> | undefined + const companies = useQuery( + reportsEnabled ? api.companies.list : undefined, + reportsEnabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined + ) as Array<{ id: Id<"companies">; name: string }> | undefined const filteredCompanies = React.useMemo(() => { const q = companyQuery.trim().toLowerCase() if (!q) return companies ?? [] diff --git a/src/components/charts/chart-open-priority.tsx b/src/components/charts/chart-open-priority.tsx index a7039c1..e1859a3 100644 --- a/src/components/charts/chart-open-priority.tsx +++ b/src/components/charts/chart-open-priority.tsx @@ -47,7 +47,7 @@ export function ChartOpenByPriority() { const enabled = Boolean(isStaff && convexUserId) const report = useQuery( - api.reports.backlogOverview, + enabled ? api.reports.backlogOverview : undefined, enabled ? ({ tenantId, @@ -55,12 +55,12 @@ export function ChartOpenByPriority() { range: timeRange, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">), }) - : "skip" + : undefined ) as { priorityCounts: Record } | undefined const companies = useQuery( - api.companies.list, - enabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip" + enabled ? api.companies.list : undefined, + enabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined ) as Array<{ id: Id<"companies">; name: string }> | undefined if (!report) { diff --git a/src/components/charts/chart-opened-resolved.tsx b/src/components/charts/chart-opened-resolved.tsx index 417c761..a4f8ddf 100644 --- a/src/components/charts/chart-opened-resolved.tsx +++ b/src/components/charts/chart-opened-resolved.tsx @@ -31,7 +31,7 @@ export function ChartOpenedResolved() { const reportsEnabled = Boolean(isStaff && convexUserId) const data = useQuery( - api.reports.openedResolvedByDay, + reportsEnabled ? api.reports.openedResolvedByDay : undefined, reportsEnabled ? ({ tenantId, @@ -39,12 +39,12 @@ export function ChartOpenedResolved() { range: timeRange, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">), }) - : "skip" + : undefined ) as { rangeDays: number; series: SeriesPoint[] } | undefined const companies = useQuery( - api.companies.list, - reportsEnabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip" + reportsEnabled ? api.companies.list : undefined, + reportsEnabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined ) as Array<{ id: Id<"companies">; name: string }> | undefined if (!data) { diff --git a/src/components/charts/views-charts.tsx b/src/components/charts/views-charts.tsx index 156cf7e..c6bdc44 100644 --- a/src/components/charts/views-charts.tsx +++ b/src/components/charts/views-charts.tsx @@ -29,12 +29,15 @@ function BacklogPriorityPie() { const { session, convexUserId, isStaff } = useAuth() const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID const data = useQuery( - api.reports.backlogOverview, + isStaff && convexUserId ? api.reports.backlogOverview : undefined, isStaff && convexUserId ? ({ tenantId, viewerId: convexUserId as Id<"users">, range: timeRange, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">) }) - : "skip" + : undefined ) as { priorityCounts: Record } | undefined - const companies = useQuery(api.companies.list, isStaff && convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as Array<{ id: Id<"companies">; name: string }> | undefined + const companies = useQuery( + isStaff && convexUserId ? api.companies.list : undefined, + isStaff && convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined + ) as Array<{ id: Id<"companies">; name: string }> | undefined if (!data) return const PRIORITY_LABELS: Record = { LOW: "Baixa", MEDIUM: "Média", HIGH: "Alta", URGENT: "Crítica" } @@ -109,12 +112,15 @@ function QueuesOpenBar() { const { session, convexUserId, isStaff } = useAuth() const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID const data = useQuery( - api.reports.slaOverview, + isStaff && convexUserId ? api.reports.slaOverview : undefined, isStaff && convexUserId ? ({ tenantId, viewerId: convexUserId as Id<"users">, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">) }) - : "skip" + : undefined ) as { queueBreakdown: { id: string; name: string; open: number }[] } | undefined - const companies = useQuery(api.companies.list, isStaff && convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as Array<{ id: Id<"companies">; name: string }> | undefined + const companies = useQuery( + isStaff && convexUserId ? api.companies.list : undefined, + isStaff && convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined + ) as Array<{ id: Id<"companies">; name: string }> | undefined if (!data) return const chartData = (data.queueBreakdown ?? []).map((q) => ({ queue: q.name, open: q.open })) diff --git a/src/components/portal/portal-ticket-detail.tsx b/src/components/portal/portal-ticket-detail.tsx index 54c5740..50249ec 100644 --- a/src/components/portal/portal-ticket-detail.tsx +++ b/src/components/portal/portal-ticket-detail.tsx @@ -73,14 +73,14 @@ export function PortalTicketDetail({ ticketId }: PortalTicketDetailProps) { const machineInactive = machineContext?.isActive === false const ticketRaw = useQuery( - api.tickets.getById, + convexUserId ? api.tickets.getById : undefined, convexUserId ? { tenantId: session?.user.tenantId ?? DEFAULT_TENANT_ID, id: ticketId as Id<"tickets">, viewerId: convexUserId as Id<"users">, } - : "skip" + : undefined ) const ticket = useMemo(() => { diff --git a/src/components/portal/portal-ticket-list.tsx b/src/components/portal/portal-ticket-list.tsx index 3ae286c..4b9271d 100644 --- a/src/components/portal/portal-ticket-list.tsx +++ b/src/components/portal/portal-ticket-list.tsx @@ -21,14 +21,14 @@ export function PortalTicketList() { const viewerId = (convexUserId ?? machineContext?.assignedUserId ?? null) as Id<"users"> | null const ticketsRaw = useQuery( - api.tickets.list, + viewerId ? api.tickets.list : undefined, viewerId ? { tenantId: session?.user.tenantId ?? DEFAULT_TENANT_ID, viewerId, limit: 100, } - : "skip" + : undefined ) const tickets = useMemo(() => { diff --git a/src/components/reports/backlog-report.tsx b/src/components/reports/backlog-report.tsx index 32a2618..b62a4cd 100644 --- a/src/components/reports/backlog-report.tsx +++ b/src/components/reports/backlog-report.tsx @@ -44,10 +44,13 @@ export function BacklogReport() { const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID const enabled = Boolean(isStaff && convexUserId) const data = useQuery( - api.reports.backlogOverview, - enabled ? { tenantId, viewerId: convexUserId as Id<"users">, range: timeRange, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">) } : "skip" + enabled ? api.reports.backlogOverview : undefined, + enabled ? { tenantId, viewerId: convexUserId as Id<"users">, range: timeRange, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">) } : undefined ) - const companies = useQuery(api.companies.list, enabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as Array<{ id: Id<"companies">; name: string }> | undefined + const companies = useQuery( + enabled ? api.companies.list : undefined, + enabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined + ) as Array<{ id: Id<"companies">; name: string }> | undefined const mostCriticalPriority = useMemo(() => { if (!data) return null diff --git a/src/components/reports/company-report.tsx b/src/components/reports/company-report.tsx index 3caad49..4b4a775 100644 --- a/src/components/reports/company-report.tsx +++ b/src/components/reports/company-report.tsx @@ -62,7 +62,10 @@ export function CompanyReport() { const [selectedCompany, setSelectedCompany] = useState("") const [timeRange, setTimeRange] = useState<"7d" | "30d" | "90d">("30d") - const companies = useQuery(api.companies.list, isStaff && convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as CompanyRecord[] | undefined + const companies = useQuery( + isStaff && convexUserId ? api.companies.list : undefined, + isStaff && convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined + ) as CompanyRecord[] | undefined useEffect(() => { if (!selectedCompany && companies && companies.length > 0) { @@ -71,7 +74,7 @@ export function CompanyReport() { }, [companies, selectedCompany]) const report = useQuery( - api.reports.companyOverview, + selectedCompany && convexUserId && isStaff ? api.reports.companyOverview : undefined, selectedCompany && convexUserId && isStaff ? { tenantId, @@ -79,7 +82,7 @@ export function CompanyReport() { companyId: selectedCompany as Id<"companies">, range: timeRange, } - : "skip" + : undefined ) const isLoading = selectedCompany !== "" && report === undefined diff --git a/src/components/reports/csat-report.tsx b/src/components/reports/csat-report.tsx index 311df87..cda5de6 100644 --- a/src/components/reports/csat-report.tsx +++ b/src/components/reports/csat-report.tsx @@ -29,12 +29,15 @@ export function CsatReport() { const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID const enabled = Boolean(isStaff && convexUserId) const data = useQuery( - api.reports.csatOverview, + enabled ? api.reports.csatOverview : undefined, enabled ? ({ tenantId, viewerId: convexUserId as Id<"users">, range: timeRange, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">) }) - : "skip" + : undefined ) - const companies = useQuery(api.companies.list, enabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as Array<{ id: Id<"companies">; name: string }> | undefined + const companies = useQuery( + enabled ? api.companies.list : undefined, + enabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined + ) as Array<{ id: Id<"companies">; name: string }> | undefined if (!data) { return ( diff --git a/src/components/reports/hours-report.tsx b/src/components/reports/hours-report.tsx index 0ba27c7..bcb8f59 100644 --- a/src/components/reports/hours-report.tsx +++ b/src/components/reports/hours-report.tsx @@ -50,11 +50,14 @@ export function HoursReport() { const enabled = Boolean(isStaff && convexUserId) const data = useQuery( - api.reports.hoursByClient, - enabled ? { tenantId, viewerId: convexUserId as Id<"users">, range: timeRange } : "skip" + enabled ? api.reports.hoursByClient : undefined, + enabled ? { tenantId, viewerId: convexUserId as Id<"users">, range: timeRange } : undefined ) as { rangeDays: number; items: HoursItem[] } | undefined - const companies = useQuery(api.companies.list, enabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as Array<{ id: Id<"companies">; name: string }> | undefined + const companies = useQuery( + enabled ? api.companies.list : undefined, + enabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined + ) as Array<{ id: Id<"companies">; name: string }> | undefined const filtered = useMemo(() => { const items = data?.items ?? [] const q = query.trim().toLowerCase() diff --git a/src/components/reports/sla-report.tsx b/src/components/reports/sla-report.tsx index 51b54f3..c6c7f8d 100644 --- a/src/components/reports/sla-report.tsx +++ b/src/components/reports/sla-report.tsx @@ -41,32 +41,35 @@ export function SlaReport() { const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID const enabled = Boolean(isStaff && convexUserId) const data = useQuery( - api.reports.slaOverview, + enabled ? api.reports.slaOverview : undefined, enabled ? ({ tenantId, viewerId: convexUserId as Id<"users">, range: timeRange, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">) }) - : "skip" + : undefined ) const agents = useQuery( - api.reports.agentProductivity, + enabled ? api.reports.agentProductivity : undefined, enabled ? ({ tenantId, viewerId: convexUserId as Id<"users">, range: timeRange, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">) }) - : "skip" + : undefined ) as { rangeDays: number; items: Array<{ agentId: string; name: string | null; email: string | null; open: number; resolved: number; avgFirstResponseMinutes: number | null; avgResolutionMinutes: number | null; workedHours: number }> } | undefined const openedResolved = useQuery( - api.reports.openedResolvedByDay, + enabled ? api.reports.openedResolvedByDay : undefined, enabled ? ({ tenantId, viewerId: convexUserId as Id<"users">, range: timeRange, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">) }) - : "skip" + : undefined ) as { rangeDays: number; series: Array<{ date: string; opened: number; resolved: number }> } | undefined const channelsSeries = useQuery( - api.reports.ticketsByChannel, + enabled ? api.reports.ticketsByChannel : undefined, enabled ? ({ tenantId, viewerId: convexUserId as Id<"users">, range: timeRange, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">) }) - : "skip" + : undefined ) as { rangeDays: number; channels: string[]; points: Array<{ date: string; values: Record }> } | undefined - const companies = useQuery(api.companies.list, enabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as Array<{ id: Id<"companies">; name: string }> | undefined + const companies = useQuery( + enabled ? api.companies.list : undefined, + enabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined + ) as Array<{ id: Id<"companies">; name: string }> | undefined const queueTotal = useMemo( () => data?.queueBreakdown.reduce((acc: number, queue: { open: number }) => acc + queue.open, 0) ?? 0, diff --git a/src/components/section-cards.tsx b/src/components/section-cards.tsx index 596c1d1..f69b7b6 100644 --- a/src/components/section-cards.tsx +++ b/src/components/section-cards.tsx @@ -34,8 +34,8 @@ export function SectionCards() { const dashboardEnabled = Boolean(isStaff && convexUserId) const dashboard = useQuery( - api.reports.dashboardOverview, - dashboardEnabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip" + dashboardEnabled ? api.reports.dashboardOverview : undefined, + dashboardEnabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined ) const inProgressSummary = useMemo(() => { diff --git a/src/components/settings/comment-templates-manager.tsx b/src/components/settings/comment-templates-manager.tsx index 7f6c912..0ca44ec 100644 --- a/src/components/settings/comment-templates-manager.tsx +++ b/src/components/settings/comment-templates-manager.tsx @@ -24,8 +24,8 @@ export function CommentTemplatesManager() { const [activeKind, setActiveKind] = useState<"comment" | "closing">("comment") const templates = useQuery( - viewerId ? api.commentTemplates.list : "skip", - viewerId ? { tenantId, viewerId, kind: activeKind } : "skip" + viewerId ? api.commentTemplates.list : undefined, + viewerId ? { tenantId, viewerId, kind: activeKind } : undefined ) as | { id: Id<"commentTemplates"> diff --git a/src/components/tickets/close-ticket-dialog.tsx b/src/components/tickets/close-ticket-dialog.tsx index 2b7003a..f0eb83c 100644 --- a/src/components/tickets/close-ticket-dialog.tsx +++ b/src/components/tickets/close-ticket-dialog.tsx @@ -135,7 +135,7 @@ export function CloseTicketDialog({ const closingTemplateArgs = actorId && open ? { tenantId, viewerId: actorId, kind: "closing" as const } : undefined const closingTemplatesRemote = useQuery( - actorId && open ? api.commentTemplates.list : "skip", + actorId && open ? api.commentTemplates.list : undefined, closingTemplateArgs ) const closingTemplates = Array.isArray(closingTemplatesRemote) diff --git a/src/components/tickets/new-ticket-dialog.tsx b/src/components/tickets/new-ticket-dialog.tsx index c9a7495..d0733ff 100644 --- a/src/components/tickets/new-ticket-dialog.tsx +++ b/src/components/tickets/new-ticket-dialog.tsx @@ -131,7 +131,7 @@ export function NewTicketDialog({ triggerClassName }: { triggerClassName?: strin : undefined useDefaultQueues(DEFAULT_TENANT_ID) - const queuesRemote = useQuery(queuesEnabled ? api.queues.summary : "skip", queueArgs) + const queuesRemote = useQuery(queuesEnabled ? api.queues.summary : undefined, queueArgs) const queues = useMemo( () => (Array.isArray(queuesRemote) ? (queuesRemote as TicketQueueSummary[]) : []), [queuesRemote] @@ -148,10 +148,7 @@ export function NewTicketDialog({ triggerClassName }: { triggerClassName?: strin const companiesArgs = directoryQueryEnabled ? { tenantId: DEFAULT_TENANT_ID, viewerId: convexUserId as Id<"users"> } : undefined - const companiesRemote = useQuery( - directoryQueryEnabled ? api.companies.list : "skip", - companiesArgs - ) + const companiesRemote = useQuery(directoryQueryEnabled ? api.companies.list : undefined, companiesArgs) const companies = useMemo( () => (Array.isArray(companiesRemote) ? companiesRemote : []).map((company) => ({ @@ -165,10 +162,7 @@ export function NewTicketDialog({ triggerClassName }: { triggerClassName?: strin const customersArgs = directoryQueryEnabled ? { tenantId: DEFAULT_TENANT_ID, viewerId: convexUserId as Id<"users"> } : undefined - const customersRemote = useQuery( - directoryQueryEnabled ? api.users.listCustomers : "skip", - customersArgs - ) + const customersRemote = useQuery(directoryQueryEnabled ? api.users.listCustomers : undefined, customersArgs) const customers = useMemo( () => (Array.isArray(customersRemote) ? (customersRemote as CustomerOption[]) : []), [customersRemote] diff --git a/src/components/tickets/play-next-ticket-card.tsx b/src/components/tickets/play-next-ticket-card.tsx index 105c317..63203f8 100644 --- a/src/components/tickets/play-next-ticket-card.tsx +++ b/src/components/tickets/play-next-ticket-card.tsx @@ -33,13 +33,13 @@ export function PlayNextTicketCard({ context }: PlayNextTicketCardProps) { const { convexUserId, isStaff } = useAuth() const queuesEnabled = Boolean(isStaff && convexUserId) const queueArgs = queuesEnabled ? { tenantId: DEFAULT_TENANT_ID, viewerId: convexUserId as Id<"users"> } : undefined - const queueSummaryResult = useQuery(queuesEnabled ? api.queues.summary : "skip", queueArgs) + const queueSummaryResult = useQuery(queuesEnabled ? api.queues.summary : undefined, queueArgs) const queueSummary: TicketQueueSummary[] = Array.isArray(queueSummaryResult) ? queueSummaryResult : [] const playNext = useMutation(api.tickets.playNext) const [selectedQueueId, setSelectedQueueId] = useState(undefined) const nextTicketFromServer = useQuery( - api.tickets.list, + convexUserId ? api.tickets.list : undefined, convexUserId ? { tenantId: DEFAULT_TENANT_ID, @@ -50,7 +50,7 @@ export function PlayNextTicketCard({ context }: PlayNextTicketCardProps) { queueId: (selectedQueueId as Id<"queues">) || undefined, limit: 1, } - : "skip" + : undefined )?.[0] const nextTicketUi = nextTicketFromServer ? mapTicketFromServer(nextTicketFromServer as unknown) : null diff --git a/src/components/tickets/recent-tickets-panel.tsx b/src/components/tickets/recent-tickets-panel.tsx index 33a1b47..184247a 100644 --- a/src/components/tickets/recent-tickets-panel.tsx +++ b/src/components/tickets/recent-tickets-panel.tsx @@ -77,7 +77,7 @@ export function RecentTicketsPanel() { const ticketsArgs = convexUserId ? { tenantId: DEFAULT_TENANT_ID, viewerId: convexUserId as Id<"users">, limit: 12 } : undefined - const ticketsResult = useQuery(convexUserId ? api.tickets.list : "skip", ticketsArgs) + const ticketsResult = useQuery(convexUserId ? api.tickets.list : undefined, ticketsArgs) const [enteringId, setEnteringId] = useState(null) const previousIdsRef = useRef([]) diff --git a/src/components/tickets/ticket-comments.rich.tsx b/src/components/tickets/ticket-comments.rich.tsx index 2c257e5..e742a98 100644 --- a/src/components/tickets/ticket-comments.rich.tsx +++ b/src/components/tickets/ticket-comments.rich.tsx @@ -74,7 +74,7 @@ export function TicketComments({ ticket }: TicketCommentsProps) { convexUserId && isStaff ? { tenantId: ticket.tenantId, viewerId: convexUserId as Id<"users">, kind: "comment" as const } : undefined - const templatesResult = useQuery(convexUserId && isStaff ? api.commentTemplates.list : "skip", templateArgs) + const templatesResult = useQuery(convexUserId && isStaff ? api.commentTemplates.list : undefined, templateArgs) const templates = Array.isArray(templatesResult) ? (templatesResult as { id: string; title: string; body: string }[]) : [] diff --git a/src/components/tickets/ticket-detail-view.tsx b/src/components/tickets/ticket-detail-view.tsx index ec2a46b..8ed2258 100644 --- a/src/components/tickets/ticket-detail-view.tsx +++ b/src/components/tickets/ticket-detail-view.tsx @@ -16,18 +16,16 @@ import { useAuth } from "@/lib/auth-client"; export function TicketDetailView({ id }: { id: string }) { const { convexUserId } = useAuth(); - const shouldSkip = !convexUserId; - const t = useQuery( - api.tickets.getById, - shouldSkip - ? "skip" - : { - tenantId: DEFAULT_TENANT_ID, - id: id as Id<"tickets">, - viewerId: convexUserId as Id<"users">, - } - ); - const isLoading = shouldSkip || t === undefined; + const canLoadTicket = Boolean(convexUserId); + const queryArgs = canLoadTicket + ? { + tenantId: DEFAULT_TENANT_ID, + id: id as Id<"tickets">, + viewerId: convexUserId as Id<"users">, + } + : undefined; + const t = useQuery(canLoadTicket ? api.tickets.getById : undefined, queryArgs); + const isLoading = !convexUserId || t === undefined; if (isLoading) { return ( diff --git a/src/components/tickets/ticket-queue-summary.tsx b/src/components/tickets/ticket-queue-summary.tsx index ef3b8c5..baa8869 100644 --- a/src/components/tickets/ticket-queue-summary.tsx +++ b/src/components/tickets/ticket-queue-summary.tsx @@ -17,7 +17,7 @@ export function TicketQueueSummaryCards({ queues }: TicketQueueSummaryProps) { const { convexUserId, isStaff } = useAuth() const enabled = Boolean(isStaff && convexUserId) const queueArgs = enabled ? { tenantId: DEFAULT_TENANT_ID, viewerId: convexUserId as Id<"users"> } : undefined - const fromServer = useQuery(enabled ? api.queues.summary : "skip", queueArgs) + const fromServer = useQuery(enabled ? api.queues.summary : undefined, queueArgs) const serverData = Array.isArray(fromServer) ? fromServer : undefined const data: TicketQueueSummary[] = queues ?? serverData ?? [] diff --git a/src/components/tickets/ticket-summary-header.tsx b/src/components/tickets/ticket-summary-header.tsx index fe8aab1..f98d030 100644 --- a/src/components/tickets/ticket-summary-header.tsx +++ b/src/components/tickets/ticket-summary-header.tsx @@ -170,10 +170,7 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) { const companiesArgs = convexUserId ? { tenantId: ticket.tenantId, viewerId: convexUserId as Id<"users"> } : undefined - const companiesRemote = useQuery( - convexUserId ? api.companies.list : "skip", - companiesArgs - ) + const companiesRemote = useQuery(convexUserId ? api.companies.list : undefined, companiesArgs) const companies = useMemo( () => (Array.isArray(companiesRemote) ? companiesRemote : []).map((company) => ({ @@ -187,10 +184,7 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) { const customersArgs = convexUserId ? { tenantId: ticket.tenantId, viewerId: convexUserId as Id<"users"> } : undefined - const customersRemote = useQuery( - convexUserId ? api.users.listCustomers : "skip", - customersArgs - ) + const customersRemote = useQuery(convexUserId ? api.users.listCustomers : undefined, customersArgs) const customers = useMemo( () => (Array.isArray(customersRemote) ? (customersRemote as CustomerOption[]) : []), [customersRemote] @@ -199,14 +193,14 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) { const queueArgs = queuesEnabled ? { tenantId: ticket.tenantId, viewerId: convexUserId as Id<"users"> } : undefined - const queuesResult = useQuery(queuesEnabled ? api.queues.summary : "skip", queueArgs) + const queuesResult = useQuery(queuesEnabled ? api.queues.summary : undefined, queueArgs) const queues: TicketQueueSummary[] = Array.isArray(queuesResult) ? queuesResult : [] const { categories, isLoading: categoriesLoading } = useTicketCategories(ticket.tenantId) const workSummaryArgs = convexUserId ? { ticketId: ticket.id as Id<"tickets">, viewerId: convexUserId as Id<"users"> } : undefined const workSummaryRemote = useQuery( - convexUserId ? api.tickets.workSummary : "skip", + convexUserId ? api.tickets.workSummary : undefined, workSummaryArgs ) as | { diff --git a/src/components/tickets/tickets-view.tsx b/src/components/tickets/tickets-view.tsx index 01830b0..3946c99 100644 --- a/src/components/tickets/tickets-view.tsx +++ b/src/components/tickets/tickets-view.tsx @@ -66,7 +66,7 @@ export function TicketsView({ initialFilters }: TicketsViewProps = {}) { const queuesEnabled = Boolean(isStaff && convexUserId) const queueArgs = queuesEnabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : undefined - const queuesResult = useQuery(queuesEnabled ? api.queues.summary : "skip", queueArgs) + const queuesResult = useQuery(queuesEnabled ? api.queues.summary : undefined, queueArgs) const queues: TicketQueueSummary[] = Array.isArray(queuesResult) ? queuesResult : [] const agents = useQuery(api.users.listAgents, { tenantId }) as { _id: string; name: string }[] | undefined const ticketsArgs = convexUserId @@ -81,7 +81,7 @@ export function TicketsView({ initialFilters }: TicketsViewProps = {}) { search: filters.search || undefined, } : undefined - const ticketsRaw = useQuery(convexUserId ? api.tickets.list : "skip", ticketsArgs) + const ticketsRaw = useQuery(convexUserId ? api.tickets.list : undefined, ticketsArgs) const tickets = useMemo( () => mapTicketsFromServerList(Array.isArray(ticketsRaw) ? (ticketsRaw as unknown[]) : []),