feat: enforce visit scheduling ux

This commit is contained in:
Esdras Renan 2025-11-18 19:59:27 -03:00
parent 6473e8d40f
commit 72a4748a81
6 changed files with 160 additions and 36 deletions

View file

@ -3501,6 +3501,8 @@ export const updateVisitSchedule = mutation({
throw new ConvexError("Somente tickets da fila de visitas possuem data de visita")
}
const now = Date.now()
const previousVisitDate = typeof ticketDoc.dueAt === "number" ? ticketDoc.dueAt : null
const actor = viewer.user
await ctx.db.patch(ticketId, {
dueAt: visitDate,
updatedAt: now,
@ -3510,7 +3512,10 @@ export const updateVisitSchedule = mutation({
type: "VISIT_SCHEDULE_CHANGED",
payload: {
visitDate,
previousVisitDate,
actorId,
actorName: actor.name,
actorAvatar: actor.avatarUrl ?? undefined,
},
createdAt: now,
})
@ -3534,15 +3539,21 @@ export const changeQueue = mutation({
if (!queue || queue.tenantId !== ticketDoc.tenantId) {
throw new ConvexError("Fila inválida")
}
const now = Date.now();
await ctx.db.patch(ticketId, { queueId, updatedAt: now });
const queueName = normalizeQueueName(queue);
const now = Date.now()
const queueName = normalizeQueueName(queue)
const normalizedQueueLabel = (queueName ?? queue.name ?? "").toLowerCase()
const isVisitQueueTarget = VISIT_QUEUE_KEYWORDS.some((keyword) => normalizedQueueLabel.includes(keyword))
const patch: Partial<Doc<"tickets">> = { queueId, updatedAt: now }
if (!isVisitQueueTarget) {
patch.dueAt = ticketDoc.slaSolutionDueAt ?? undefined
}
await ctx.db.patch(ticketId, patch)
await ctx.db.insert("ticketEvents", {
ticketId,
type: "QUEUE_CHANGED",
payload: { queueId, queueName, actorId },
createdAt: now,
});
})
},
});