feat: melhorias no vínculo de tickets e exportação
This commit is contained in:
parent
1b32638eb5
commit
9495b54a28
7 changed files with 226 additions and 16 deletions
|
|
@ -44,7 +44,8 @@ const NO_REQUESTER_VALUE = "__no_requester__"
|
|||
|
||||
export default function NewTicketPage() {
|
||||
const router = useRouter()
|
||||
const { convexUserId, isStaff, role } = useAuth()
|
||||
const { convexUserId, isStaff, role, session, machineContext } = useAuth()
|
||||
const sessionUser = session?.user ?? null
|
||||
const queuesEnabled = Boolean(isStaff && convexUserId)
|
||||
const queuesRemote = useQuery(
|
||||
api.queues.summary,
|
||||
|
|
@ -81,10 +82,28 @@ export default function NewTicketPage() {
|
|||
api.users.listCustomers,
|
||||
directoryQueryEnabled ? { tenantId: DEFAULT_TENANT_ID, viewerId: convexUserId as Id<"users"> } : "skip"
|
||||
)
|
||||
const customers = useMemo(
|
||||
const rawCustomers = useMemo(
|
||||
() => (Array.isArray(customersRemote) ? (customersRemote as CustomerOption[]) : []),
|
||||
[customersRemote]
|
||||
)
|
||||
const viewerCustomer = useMemo<CustomerOption | null>(() => {
|
||||
if (!convexUserId || !sessionUser) return null
|
||||
return {
|
||||
id: convexUserId,
|
||||
name: sessionUser.name ?? sessionUser.email,
|
||||
email: sessionUser.email,
|
||||
role: sessionUser.role ?? "customer",
|
||||
companyId: machineContext?.companyId ?? null,
|
||||
companyName: null,
|
||||
companyIsAvulso: false,
|
||||
avatarUrl: sessionUser.avatarUrl,
|
||||
}
|
||||
}, [convexUserId, sessionUser, machineContext?.companyId])
|
||||
const customers = useMemo(() => {
|
||||
if (!viewerCustomer) return rawCustomers
|
||||
const exists = rawCustomers.some((customer) => customer.id === viewerCustomer.id)
|
||||
return exists ? rawCustomers : [...rawCustomers, viewerCustomer]
|
||||
}, [rawCustomers, viewerCustomer])
|
||||
|
||||
const [subject, setSubject] = useState("")
|
||||
const [summary, setSummary] = useState("")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue