chore: reorganize project structure and ensure default queues
This commit is contained in:
parent
854887f499
commit
1cccb852a5
201 changed files with 417 additions and 838 deletions
21
src/hooks/use-default-queues.ts
Normal file
21
src/hooks/use-default-queues.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
"use client"
|
||||
|
||||
import { useEffect, useRef } from "react"
|
||||
import { useMutation } from "convex/react"
|
||||
// @ts-expect-error Convex runtime API lacks TypeScript declarations
|
||||
import { api } from "@/convex/_generated/api"
|
||||
|
||||
export function useDefaultQueues(tenantId?: string | null) {
|
||||
const ensureDefaults = useMutation(api.bootstrap.ensureDefaults)
|
||||
const pendingRef = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!tenantId) return
|
||||
if (pendingRef.current) return
|
||||
pendingRef.current = true
|
||||
ensureDefaults({ tenantId })
|
||||
.catch(() => {
|
||||
pendingRef.current = false
|
||||
})
|
||||
}, [ensureDefaults, tenantId])
|
||||
}
|
||||
19
src/hooks/use-mobile.ts
Normal file
19
src/hooks/use-mobile.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import * as React from "react"
|
||||
|
||||
const MOBILE_BREAKPOINT = 768
|
||||
|
||||
export function useIsMobile() {
|
||||
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
|
||||
|
||||
React.useEffect(() => {
|
||||
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
||||
const onChange = () => {
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
}
|
||||
mql.addEventListener("change", onChange)
|
||||
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
|
||||
return () => mql.removeEventListener("change", onChange)
|
||||
}, [])
|
||||
|
||||
return !!isMobile
|
||||
}
|
||||
34
src/hooks/use-ticket-categories.ts
Normal file
34
src/hooks/use-ticket-categories.ts
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
"use client"
|
||||
|
||||
import { useEffect, useMemo, useRef } from "react"
|
||||
import { useMutation, useQuery } from "convex/react"
|
||||
// @ts-expect-error Convex generates runtime API without TS declarations
|
||||
import { api } from "@/convex/_generated/api"
|
||||
import type { TicketCategory } from "@/lib/schemas/category"
|
||||
|
||||
export function useTicketCategories(tenantId: string) {
|
||||
const categories = useQuery(api.categories.list, { tenantId }) as TicketCategory[] | undefined
|
||||
const ensureDefaults = useMutation(api.categories.ensureDefaults)
|
||||
const initializingRef = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!categories) return
|
||||
if (categories.length > 0) {
|
||||
initializingRef.current = false
|
||||
return
|
||||
}
|
||||
if (initializingRef.current) return
|
||||
initializingRef.current = true
|
||||
ensureDefaults({ tenantId }).catch(() => {
|
||||
initializingRef.current = false
|
||||
})
|
||||
}, [categories, ensureDefaults, tenantId])
|
||||
|
||||
return useMemo(
|
||||
() => ({
|
||||
categories: categories ?? [],
|
||||
isLoading: categories === undefined,
|
||||
}),
|
||||
[categories]
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue