fix(web): gate staff-only Convex queries to avoid RBAC errors on dashboard and tickets; docs: add desktop agent history and troubleshooting
This commit is contained in:
parent
7685370c05
commit
ab820ddeca
11 changed files with 144 additions and 33 deletions
|
|
@ -25,12 +25,13 @@ const chartConfig = {
|
|||
export function ChartOpenedResolved() {
|
||||
const [timeRange, setTimeRange] = React.useState("30d")
|
||||
const [companyId, setCompanyId] = usePersistentCompanyFilter("all")
|
||||
const { session, convexUserId } = useAuth()
|
||||
const { session, convexUserId, isStaff } = useAuth()
|
||||
const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
|
||||
const reportsEnabled = Boolean(isStaff && convexUserId)
|
||||
const data = useQuery(
|
||||
api.reports.openedResolvedByDay,
|
||||
convexUserId
|
||||
reportsEnabled
|
||||
? ({
|
||||
tenantId,
|
||||
viewerId: convexUserId as Id<"users">,
|
||||
|
|
@ -40,7 +41,10 @@ export function ChartOpenedResolved() {
|
|||
: "skip"
|
||||
) as { rangeDays: number; series: SeriesPoint[] } | undefined
|
||||
|
||||
const companies = useQuery(api.companies.list, convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as Array<{ id: Id<"companies">; name: string }> | undefined
|
||||
const companies = useQuery(
|
||||
api.companies.list,
|
||||
reportsEnabled ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip"
|
||||
) as Array<{ id: Id<"companies">; name: string }> | undefined
|
||||
|
||||
if (!data) {
|
||||
return <Skeleton className="h-[300px] w-full" />
|
||||
|
|
@ -109,4 +113,3 @@ export function ChartOpenedResolved() {
|
|||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,15 +26,15 @@ export function ViewsCharts() {
|
|||
function BacklogPriorityPie() {
|
||||
const [companyId, setCompanyId] = usePersistentCompanyFilter("all")
|
||||
const [timeRange, setTimeRange] = React.useState("30d")
|
||||
const { session, convexUserId } = useAuth()
|
||||
const { session, convexUserId, isStaff } = useAuth()
|
||||
const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
const data = useQuery(
|
||||
api.reports.backlogOverview,
|
||||
convexUserId
|
||||
isStaff && convexUserId
|
||||
? ({ tenantId, viewerId: convexUserId as Id<"users">, range: timeRange, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">) })
|
||||
: "skip"
|
||||
) as { priorityCounts: Record<string, number> } | undefined
|
||||
const companies = useQuery(api.companies.list, convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as Array<{ id: Id<"companies">; name: string }> | undefined
|
||||
const companies = useQuery(api.companies.list, isStaff && convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as Array<{ id: Id<"companies">; name: string }> | undefined
|
||||
|
||||
if (!data) return <Skeleton className="h-[300px] w-full" />
|
||||
const PRIORITY_LABELS: Record<string, string> = { LOW: "Baixa", MEDIUM: "Média", HIGH: "Alta", URGENT: "Crítica" }
|
||||
|
|
@ -106,15 +106,15 @@ function BacklogPriorityPie() {
|
|||
|
||||
function QueuesOpenBar() {
|
||||
const [companyId, setCompanyId] = usePersistentCompanyFilter("all")
|
||||
const { session, convexUserId } = useAuth()
|
||||
const { session, convexUserId, isStaff } = useAuth()
|
||||
const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID
|
||||
const data = useQuery(
|
||||
api.reports.slaOverview,
|
||||
convexUserId
|
||||
isStaff && convexUserId
|
||||
? ({ tenantId, viewerId: convexUserId as Id<"users">, companyId: companyId === "all" ? undefined : (companyId as Id<"companies">) })
|
||||
: "skip"
|
||||
) as { queueBreakdown: { id: string; name: string; open: number }[] } | undefined
|
||||
const companies = useQuery(api.companies.list, convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as Array<{ id: Id<"companies">; name: string }> | undefined
|
||||
const companies = useQuery(api.companies.list, isStaff && convexUserId ? { tenantId, viewerId: convexUserId as Id<"users"> } : "skip") as Array<{ id: Id<"companies">; name: string }> | undefined
|
||||
|
||||
if (!data) return <Skeleton className="h-[300px] w-full" />
|
||||
const chartData = (data.queueBreakdown ?? []).map((q) => ({ queue: q.name, open: q.open }))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue