refactor: use Convex skip sentinel in query args
This commit is contained in:
parent
3de7eccaa8
commit
bd2f22d046
32 changed files with 167 additions and 157 deletions
|
|
@ -167,10 +167,10 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
|||
const updateCategories = useMutation(api.tickets.updateCategories)
|
||||
const agents = (useQuery(api.users.listAgents, { tenantId: ticket.tenantId }) as Doc<"users">[] | undefined) ?? []
|
||||
const queuesEnabled = Boolean(isStaff && convexUserId)
|
||||
const companiesArgs = convexUserId
|
||||
? { tenantId: ticket.tenantId, viewerId: convexUserId as Id<"users"> }
|
||||
: undefined
|
||||
const companiesRemote = useQuery(convexUserId ? api.companies.list : undefined, companiesArgs)
|
||||
const companiesRemote = useQuery(
|
||||
api.companies.list,
|
||||
convexUserId ? { tenantId: ticket.tenantId, viewerId: convexUserId as Id<"users"> } : "skip"
|
||||
)
|
||||
const companies = useMemo(
|
||||
() =>
|
||||
(Array.isArray(companiesRemote) ? companiesRemote : []).map((company) => ({
|
||||
|
|
@ -181,27 +181,26 @@ export function TicketSummaryHeader({ ticket }: TicketHeaderProps) {
|
|||
[companiesRemote]
|
||||
)
|
||||
|
||||
const customersArgs = convexUserId
|
||||
? { tenantId: ticket.tenantId, viewerId: convexUserId as Id<"users"> }
|
||||
: undefined
|
||||
const customersRemote = useQuery(convexUserId ? api.users.listCustomers : undefined, customersArgs)
|
||||
const customersRemote = useQuery(
|
||||
api.users.listCustomers,
|
||||
convexUserId ? { tenantId: ticket.tenantId, viewerId: convexUserId as Id<"users"> } : "skip"
|
||||
)
|
||||
const customers = useMemo(
|
||||
() => (Array.isArray(customersRemote) ? (customersRemote as CustomerOption[]) : []),
|
||||
[customersRemote]
|
||||
)
|
||||
|
||||
const queueArgs = queuesEnabled
|
||||
? { tenantId: ticket.tenantId, viewerId: convexUserId as Id<"users"> }
|
||||
: undefined
|
||||
const queuesResult = useQuery(queuesEnabled ? api.queues.summary : undefined, queueArgs)
|
||||
const queuesResult = useQuery(
|
||||
api.queues.summary,
|
||||
queuesEnabled ? { tenantId: ticket.tenantId, viewerId: convexUserId as Id<"users"> } : "skip"
|
||||
)
|
||||
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 : undefined,
|
||||
workSummaryArgs
|
||||
api.tickets.workSummary,
|
||||
convexUserId
|
||||
? { ticketId: ticket.id as Id<"tickets">, viewerId: convexUserId as Id<"users"> }
|
||||
: "skip"
|
||||
) as
|
||||
| {
|
||||
ticketId: Id<"tickets">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue