@@ -21,7 +21,8 @@ import {
|
|||||||
import { Link as RouterLink, NavLink, Outlet, useNavigate } from 'react-router-dom'
|
import { Link as RouterLink, NavLink, Outlet, useNavigate } from 'react-router-dom'
|
||||||
import { useAuth } from '../lib/auth'
|
import { useAuth } from '../lib/auth'
|
||||||
import { ColorModeToggle } from './ColorModeToggle'
|
import { ColorModeToggle } from './ColorModeToggle'
|
||||||
|
import { useState, useCallback, useEffect } from 'react'
|
||||||
|
import { api, ApiError } from '../lib/api'
|
||||||
const HamburgerIcon = () => (
|
const HamburgerIcon = () => (
|
||||||
<Box as="svg" w="20px" h="20px" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
<Box as="svg" w="20px" h="20px" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
|
||||||
<Box as="path" d="M3 12h18M3 6h18M3 18h18" />
|
<Box as="path" d="M3 12h18M3 6h18M3 18h18" />
|
||||||
@@ -31,9 +32,26 @@ const HamburgerIcon = () => (
|
|||||||
const SUPPORT_TELEGRAM_URL = 'https://t.me/OMNEX_CORP'
|
const SUPPORT_TELEGRAM_URL = 'https://t.me/OMNEX_CORP'
|
||||||
|
|
||||||
export function BackofficeLayout() {
|
export function BackofficeLayout() {
|
||||||
|
const [typeAbo, setTypeAbo] = useState<string | null>(null)
|
||||||
|
|
||||||
const { logout, isAdmin, isClient } = useAuth()
|
const { logout, isAdmin, isClient } = useAuth()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { isOpen, onOpen, onClose } = useDisclosure()
|
const { isOpen, onOpen, onClose } = useDisclosure()
|
||||||
|
const isPremium = typeAbo === 'premium'
|
||||||
|
|
||||||
|
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const me = await api.me()
|
||||||
|
setTypeAbo(me.type_abonnement ?? null)
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof ApiError && err.status === 401) navigate('/login')
|
||||||
|
}
|
||||||
|
}, [navigate])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
void load()
|
||||||
|
}, [load])
|
||||||
|
|
||||||
const onLogout = async () => {
|
const onLogout = async () => {
|
||||||
const loginPath = isAdmin ? '/admin/login' : '/login'
|
const loginPath = isAdmin ? '/admin/login' : '/login'
|
||||||
@@ -57,6 +75,7 @@ export function BackofficeLayout() {
|
|||||||
{isClient && <NavItem to="/app/subscription">Abonnement</NavItem>}
|
{isClient && <NavItem to="/app/subscription">Abonnement</NavItem>}
|
||||||
{isClient && <NavItem to="/app/downloads">Applications</NavItem>}
|
{isClient && <NavItem to="/app/downloads">Applications</NavItem>}
|
||||||
{(isAdmin || isClient) && <NavItem to="/app/profile">Profile</NavItem>}
|
{(isAdmin || isClient) && <NavItem to="/app/profile">Profile</NavItem>}
|
||||||
|
{isClient && <NavItem to="/app/myservices">{isPremium ? 'Ma plateforme' : 'Ma démo'}</NavItem>}
|
||||||
{isAdmin && <NavItem to="/app/demos">Démos</NavItem>}
|
{isAdmin && <NavItem to="/app/demos">Démos</NavItem>}
|
||||||
{isAdmin && <NavItem to="/app/premium">Premium</NavItem>}
|
{isAdmin && <NavItem to="/app/premium">Premium</NavItem>}
|
||||||
{isAdmin && <NavItem to="/app/codes">Codes</NavItem>}
|
{isAdmin && <NavItem to="/app/codes">Codes</NavItem>}
|
||||||
|
|||||||
Reference in New Issue
Block a user