feat: static applications dashboard

This commit is contained in:
2024-02-16 13:06:56 -06:00
parent ddeed0a6ef
commit ff0d24bbb6
17 changed files with 753 additions and 97 deletions
+9 -4
View File
@@ -1,21 +1,26 @@
import { type SessionState } from '@/state/sessionSlice'
import { useRouter } from 'next/navigation'
import { useEffect } from 'react'
import { useCallback, useEffect } from 'react'
import { useAppSelector } from './useAppSelector'
type UseSession = (redirect?: string) => SessionState
type UseSession = (redirect?: string) => SessionState & { belongToClan: (clanId: string) => boolean }
const useSession: UseSession = (redirect?: string) => {
const { status, session, user } = useAppSelector((state) => state.session)
const { status, session, user, clanes } = useAppSelector((state) => state.session)
const router = useRouter()
const belongToClan = useCallback((clanId: string): boolean => {
if (session === undefined || clanes === undefined || clanes.total === 0) return false
return clanes.teams.some((team) => team.$id === clanId) ?? false
}, [clanes])
useEffect(() => {
if (status === 'idle' && session === undefined) {
router.push(redirect ?? '/')
}
}, [status, session])
return { status, session, user }
return { status, session, user, clanes, belongToClan }
}
export default useSession