Wire quick actions to reopen admin modals in-place

This commit is contained in:
Esdras Renan 2025-11-13 21:55:56 -03:00
parent 8db3b20a40
commit 6a75a0a9ed
4 changed files with 47 additions and 2 deletions

View file

@ -436,6 +436,15 @@ export function AdminCompaniesManager({ initialCompanies, tenantId, autoOpenCrea
}
}, [autoOpenCreate, openCreate])
useEffect(() => {
if (typeof window === "undefined") return
const handler = () => {
openCreate()
}
window.addEventListener("quick-open-company", handler)
return () => window.removeEventListener("quick-open-company", handler)
}, [openCreate])
const handleDelete = useCallback(async () => {
if (!isDeleting) return
try {

View file

@ -1569,6 +1569,15 @@ export function AdminDevicesOverview({
}
}, [autoOpenCreateDevice, handleOpenCreateDevice])
useEffect(() => {
if (typeof window === "undefined") return
const handler = () => {
handleOpenCreateDevice()
}
window.addEventListener("quick-open-device", handler)
return () => window.removeEventListener("quick-open-device", handler)
}, [handleOpenCreateDevice])
const handleCreateDevice = useCallback(async () => {
if (!convexUserId) {
toast.error("Sincronize a sessão antes de criar dispositivos.")

View file

@ -416,6 +416,15 @@ function AccountsTable({
setCreateDialogOpen(true)
}, [autoOpenCreate])
useEffect(() => {
if (typeof window === "undefined") return
const handler = () => {
handleOpenCreateDialog()
}
window.addEventListener("quick-open-user", handler)
return () => window.removeEventListener("quick-open-user", handler)
}, [handleOpenCreateDialog])
useEffect(() => {
if (editAccount) {
setEditForm({

View file

@ -1,7 +1,7 @@
"use client"
import { useId, useMemo } from "react"
import { useRouter } from "next/navigation"
import { usePathname, useRouter } from "next/navigation"
import { MonitorSmartphone, Building, UserPlus, ChevronRight } from "lucide-react"
import { Button } from "@/components/ui/button"
@ -22,6 +22,7 @@ type QuickLink = {
export function GlobalQuickActions() {
const { convexUserId, isAdmin, isStaff, isLoading } = useAuth()
const router = useRouter()
const pathname = usePathname()
const actionId = useId()
const links = useMemo<QuickLink[]>(() => {
@ -81,7 +82,24 @@ export function GlobalQuickActions() {
<button
key={link.id}
type="button"
onClick={() => router.push(link.href)}
onClick={() => {
const targetPath = link.href.split("?")[0]
if (pathname === targetPath && typeof window !== "undefined") {
const eventName =
link.id === "device"
? "quick-open-device"
: link.id === "company"
? "quick-open-company"
: link.id === "user"
? "quick-open-user"
: null
if (eventName) {
window.dispatchEvent(new CustomEvent(eventName))
return
}
}
router.push(link.href)
}}
className="group inline-flex h-auto min-w-[200px] flex-1 flex-col items-start justify-start rounded-2xl border border-border/60 bg-card px-4 py-3 text-left shadow-sm transition hover:-translate-y-0.5 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 md:min-w-[220px]"
>
<div className="flex items-center justify-between gap-3">