feat(ST-906): redirect to dashboard with toast when active product becomes inaccessible
This commit is contained in:
parent
754d033669
commit
98105fb870
2 changed files with 34 additions and 0 deletions
|
|
@ -8,6 +8,8 @@ import { NavBar } from '@/components/shared/nav-bar'
|
|||
import { MinWidthBanner } from '@/components/shared/min-width-banner'
|
||||
import { StatusBar } from '@/components/shared/status-bar'
|
||||
import { SoloRealtimeBridge } from '@/components/solo/realtime-bridge'
|
||||
import { AlertToast } from '@/components/shared/alert-toast'
|
||||
import { Suspense } from 'react'
|
||||
|
||||
export default async function AppLayout({ children }: { children: React.ReactNode }) {
|
||||
const session = await getIronSession<SessionData>(await cookies(), sessionOptions)
|
||||
|
|
@ -57,6 +59,7 @@ export default async function AppLayout({ children }: { children: React.ReactNod
|
|||
where: { id: session.userId },
|
||||
data: { active_product_id: null },
|
||||
})
|
||||
redirect('/dashboard?alert=product_unavailable')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -81,6 +84,9 @@ export default async function AppLayout({ children }: { children: React.ReactNod
|
|||
</main>
|
||||
<StatusBar />
|
||||
<SoloRealtimeBridge />
|
||||
<Suspense>
|
||||
<AlertToast />
|
||||
</Suspense>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
28
components/shared/alert-toast.tsx
Normal file
28
components/shared/alert-toast.tsx
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
'use client'
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import { useSearchParams, useRouter, usePathname } from 'next/navigation'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
const ALERT_MESSAGES: Record<string, string> = {
|
||||
product_unavailable: 'Je actieve product is niet meer beschikbaar',
|
||||
}
|
||||
|
||||
export function AlertToast() {
|
||||
const searchParams = useSearchParams()
|
||||
const router = useRouter()
|
||||
const pathname = usePathname()
|
||||
const alert = searchParams.get('alert')
|
||||
|
||||
useEffect(() => {
|
||||
if (!alert || !ALERT_MESSAGES[alert]) return
|
||||
toast.error(ALERT_MESSAGES[alert])
|
||||
const params = new URLSearchParams(searchParams.toString())
|
||||
params.delete('alert')
|
||||
const next = params.toString() ? `${pathname}?${params}` : pathname
|
||||
router.replace(next)
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [alert])
|
||||
|
||||
return null
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue