feat: add admin and dashboard layouts with context for improved structure and functionality
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
createContext,
|
||||
useState,
|
||||
useContext,
|
||||
type PropsWithChildren,
|
||||
type SetStateAction,
|
||||
type Dispatch,
|
||||
} from 'react'
|
||||
|
||||
type AdminProfile = {
|
||||
name: string
|
||||
}
|
||||
|
||||
type AdminContextProperties = {
|
||||
adminProfile: AdminProfile
|
||||
setAdminProfile: Dispatch<SetStateAction<AdminProfile>>
|
||||
}
|
||||
|
||||
const AdminContext = createContext<AdminContextProperties | undefined>(
|
||||
undefined,
|
||||
)
|
||||
|
||||
export const AdminProvider = ({ children }: PropsWithChildren) => {
|
||||
const [adminProfile, setAdminProfile] = useState<AdminProfile>({
|
||||
name: '',
|
||||
})
|
||||
|
||||
return (
|
||||
<AdminContext.Provider value={{ adminProfile, setAdminProfile }}>
|
||||
{children}
|
||||
</AdminContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const useAdminContext = (): AdminContextProperties => {
|
||||
const context = useContext(AdminContext)
|
||||
if (!context) {
|
||||
throw new Error('useAdminContext must be used within a AdminProvider')
|
||||
}
|
||||
return context
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
import React, {
|
||||
import {
|
||||
createContext,
|
||||
useState,
|
||||
useContext,
|
||||
type PropsWithChildren,
|
||||
type Dispatch,
|
||||
type SetStateAction,
|
||||
} from 'react'
|
||||
|
||||
type NewsContextProperties = {
|
||||
isLoginOpen: boolean
|
||||
setIsLoginOpen: React.Dispatch<React.SetStateAction<boolean>>
|
||||
setIsLoginOpen: Dispatch<SetStateAction<boolean>>
|
||||
isRegisterOpen: boolean
|
||||
setIsRegisterOpen: React.Dispatch<React.SetStateAction<boolean>>
|
||||
setIsRegisterOpen: Dispatch<SetStateAction<boolean>>
|
||||
}
|
||||
|
||||
const NewsContext = createContext<NewsContextProperties | undefined>(undefined)
|
||||
|
||||
Reference in New Issue
Block a user