mirror of
https://github.com/plausible/analytics.git
synced 2024-12-29 20:42:01 +03:00
039f3baf8e
* 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
36 lines
631 B
TypeScript
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>
|
|
)
|
|
}
|