Wire quick actions to reopen admin modals in-place
This commit is contained in:
parent
8db3b20a40
commit
6a75a0a9ed
4 changed files with 47 additions and 2 deletions
|
|
@ -436,6 +436,15 @@ export function AdminCompaniesManager({ initialCompanies, tenantId, autoOpenCrea
|
||||||
}
|
}
|
||||||
}, [autoOpenCreate, openCreate])
|
}, [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 () => {
|
const handleDelete = useCallback(async () => {
|
||||||
if (!isDeleting) return
|
if (!isDeleting) return
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1569,6 +1569,15 @@ export function AdminDevicesOverview({
|
||||||
}
|
}
|
||||||
}, [autoOpenCreateDevice, handleOpenCreateDevice])
|
}, [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 () => {
|
const handleCreateDevice = useCallback(async () => {
|
||||||
if (!convexUserId) {
|
if (!convexUserId) {
|
||||||
toast.error("Sincronize a sessão antes de criar dispositivos.")
|
toast.error("Sincronize a sessão antes de criar dispositivos.")
|
||||||
|
|
|
||||||
|
|
@ -416,6 +416,15 @@ function AccountsTable({
|
||||||
setCreateDialogOpen(true)
|
setCreateDialogOpen(true)
|
||||||
}, [autoOpenCreate])
|
}, [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(() => {
|
useEffect(() => {
|
||||||
if (editAccount) {
|
if (editAccount) {
|
||||||
setEditForm({
|
setEditForm({
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useId, useMemo } from "react"
|
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 { MonitorSmartphone, Building, UserPlus, ChevronRight } from "lucide-react"
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
|
|
@ -22,6 +22,7 @@ type QuickLink = {
|
||||||
export function GlobalQuickActions() {
|
export function GlobalQuickActions() {
|
||||||
const { convexUserId, isAdmin, isStaff, isLoading } = useAuth()
|
const { convexUserId, isAdmin, isStaff, isLoading } = useAuth()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const pathname = usePathname()
|
||||||
const actionId = useId()
|
const actionId = useId()
|
||||||
|
|
||||||
const links = useMemo<QuickLink[]>(() => {
|
const links = useMemo<QuickLink[]>(() => {
|
||||||
|
|
@ -81,7 +82,24 @@ export function GlobalQuickActions() {
|
||||||
<button
|
<button
|
||||||
key={link.id}
|
key={link.id}
|
||||||
type="button"
|
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]"
|
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">
|
<div className="flex items-center justify-between gap-3">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue