Fix auth sync and set ticket channel chart default
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
parent
487edd222f
commit
12262e24c8
5 changed files with 62 additions and 8 deletions
46
web/scripts/debug-convex.mjs
Normal file
46
web/scripts/debug-convex.mjs
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
import { ConvexHttpClient } from "convex/browser";
|
||||||
|
|
||||||
|
const url = process.env.NEXT_PUBLIC_CONVEX_URL;
|
||||||
|
|
||||||
|
if (!url) {
|
||||||
|
console.error("Missing NEXT_PUBLIC_CONVEX_URL");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = new ConvexHttpClient(url);
|
||||||
|
|
||||||
|
const tenantId = process.argv[2] ?? "tenant-atlas";
|
||||||
|
|
||||||
|
const ensureAdmin = await client.mutation("users:ensureUser", {
|
||||||
|
tenantId,
|
||||||
|
email: "admin@sistema.dev",
|
||||||
|
name: "Administrador",
|
||||||
|
role: "ADMIN",
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Ensured admin user:", ensureAdmin);
|
||||||
|
|
||||||
|
const agents = await client.query("users:listAgents", { tenantId });
|
||||||
|
console.log("Agents:", agents);
|
||||||
|
|
||||||
|
const viewerId = ensureAdmin?._id ?? agents[0]?._id;
|
||||||
|
|
||||||
|
if (!viewerId) {
|
||||||
|
console.error("Unable to determine viewer id");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tickets = await client.query("tickets:list", {
|
||||||
|
tenantId,
|
||||||
|
viewerId,
|
||||||
|
limit: 10,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Tickets:", tickets);
|
||||||
|
|
||||||
|
const dashboard = await client.query("reports:dashboardOverview", {
|
||||||
|
tenantId,
|
||||||
|
viewerId,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log("Dashboard:", dashboard);
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { PrismaClient } from "@prisma/client"
|
import pkg from "@prisma/client"
|
||||||
import { hashPassword } from "better-auth/crypto"
|
import { hashPassword } from "better-auth/crypto"
|
||||||
|
|
||||||
|
const { PrismaClient } = pkg
|
||||||
const prisma = new PrismaClient()
|
const prisma = new PrismaClient()
|
||||||
|
|
||||||
const email = process.env.SEED_USER_EMAIL ?? "admin@sistema.dev"
|
const email = process.env.SEED_USER_EMAIL ?? "admin@sistema.dev"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useEffect } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import { useRouter, useSearchParams } from "next/navigation"
|
import { useRouter, useSearchParams } from "next/navigation"
|
||||||
import { GalleryVerticalEnd } from "lucide-react"
|
import { GalleryVerticalEnd } from "lucide-react"
|
||||||
|
|
@ -19,6 +19,7 @@ export default function LoginPage() {
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const { data: session, isPending } = useSession()
|
const { data: session, isPending } = useSession()
|
||||||
const callbackUrl = searchParams?.get("callbackUrl") ?? undefined
|
const callbackUrl = searchParams?.get("callbackUrl") ?? undefined
|
||||||
|
const [isHydrated, setIsHydrated] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!session?.user) return
|
if (!session?.user) return
|
||||||
|
|
@ -26,6 +27,12 @@ export default function LoginPage() {
|
||||||
router.replace(destination)
|
router.replace(destination)
|
||||||
}, [callbackUrl, router, session?.user])
|
}, [callbackUrl, router, session?.user])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setIsHydrated(true)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const shouldDisable = !isHydrated || isPending
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid min-h-svh lg:grid-cols-2">
|
<div className="grid min-h-svh lg:grid-cols-2">
|
||||||
<div className="flex flex-col gap-6 p-6 md:p-10">
|
<div className="flex flex-col gap-6 p-6 md:p-10">
|
||||||
|
|
@ -39,7 +46,7 @@ export default function LoginPage() {
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-1 items-center justify-center">
|
<div className="flex flex-1 items-center justify-center">
|
||||||
<div className="w-full max-w-sm rounded-2xl border border-slate-200 bg-white p-6 shadow-sm">
|
<div className="w-full max-w-sm rounded-2xl border border-slate-200 bg-white p-6 shadow-sm">
|
||||||
<LoginForm callbackUrl={callbackUrl} disabled={isPending} />
|
<LoginForm callbackUrl={callbackUrl} disabled={shouldDisable} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ export const description = "Distribuição semanal de tickets por canal"
|
||||||
|
|
||||||
export function ChartAreaInteractive() {
|
export function ChartAreaInteractive() {
|
||||||
const isMobile = useIsMobile()
|
const isMobile = useIsMobile()
|
||||||
const [timeRange, setTimeRange] = React.useState("90d")
|
const [timeRange, setTimeRange] = React.useState("7d")
|
||||||
const { session, convexUserId } = useAuth()
|
const { session, convexUserId } = useAuth()
|
||||||
const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID
|
const tenantId = session?.user.tenantId ?? DEFAULT_TENANT_ID
|
||||||
|
|
||||||
|
|
@ -124,7 +124,7 @@ export function ChartAreaInteractive() {
|
||||||
size="sm"
|
size="sm"
|
||||||
aria-label="Selecionar período"
|
aria-label="Selecionar período"
|
||||||
>
|
>
|
||||||
<SelectValue placeholder="Últimos 90 dias" />
|
<SelectValue placeholder="Selecionar período" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent className="rounded-xl">
|
<SelectContent className="rounded-xl">
|
||||||
<SelectItem value="90d" className="rounded-lg">
|
<SelectItem value="90d" className="rounded-lg">
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||||
}, [session?.user])
|
}, [session?.user])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!session?.user || !process.env.NEXT_PUBLIC_CONVEX_URL || convexUserId) return
|
if (!session?.user || convexUserId) return
|
||||||
|
|
||||||
const controller = new AbortController()
|
const controller = new AbortController()
|
||||||
|
|
||||||
|
|
@ -97,7 +97,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||||
controller.abort()
|
controller.abort()
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [ensureUser, session?.user?.email, convexUserId])
|
}, [ensureUser, session?.user?.email, session?.user?.tenantId, session?.user?.role, convexUserId])
|
||||||
|
|
||||||
const normalizedRole = session?.user?.role ? session.user.role.toLowerCase() : null
|
const normalizedRole = session?.user?.role ? session.user.role.toLowerCase() : null
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue