analytics/assets/js/dashboard/user-context.tsx
Artur Pata 039f3baf8e
Add Typescript (#4427)
* Add typescript, rewrite Countries map

* Add back DB IP geolocation notice

* Silence all current eslint warnings: to be removed gradually

* Reconfigure eslint import plugin for typescript

* Insert formatting pragma by default, but ignore files without pragma in CI
2024-08-13 11:39:35 +03:00

36 lines
631 B
TypeScript

/* @format */
import React, { createContext, ReactNode, useContext } from 'react'
export enum Role {
owner = 'owner',
admin = 'admin',
viewer = 'viewer'
}
const userContextDefaultValue = {
role: Role.viewer,
loggedIn: false
}
const UserContext = createContext(userContextDefaultValue)
export const useUserContext = () => {
return useContext(UserContext)
}
export default function UserContextProvider({
role,
loggedIn,
children
}: {
role: Role
loggedIn: boolean
children: ReactNode
}) {
return (
<UserContext.Provider value={{ role, loggedIn }}>
{children}
</UserContext.Provider>
)
}