mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
9b59c0813c
* Replaced `application-context` with `user-context` * deleted `user` initialization with `window.user` * fixed tests and storybook GitOrigin-RevId: 0ed4b9070d7c6d370fee2112f310c4bcfea519e7
32 lines
835 B
JavaScript
32 lines
835 B
JavaScript
import { createContext, useContext } from 'react'
|
|
import PropTypes from 'prop-types'
|
|
import useScopeValue from './util/scope-value-hook'
|
|
|
|
export const UserContext = createContext()
|
|
|
|
UserContext.Provider.propTypes = {
|
|
value: PropTypes.shape({
|
|
user: PropTypes.shape({
|
|
id: PropTypes.string,
|
|
allowedFreeTrial: PropTypes.boolean,
|
|
first_name: PropTypes.string,
|
|
last_name: PropTypes.string,
|
|
}),
|
|
}),
|
|
}
|
|
|
|
export function UserProvider({ children }) {
|
|
const [user] = useScopeValue('user', true)
|
|
|
|
return <UserContext.Provider value={user}>{children}</UserContext.Provider>
|
|
}
|
|
|
|
UserProvider.propTypes = {
|
|
children: PropTypes.any,
|
|
}
|
|
|
|
export function useUserContext(propTypes) {
|
|
const data = useContext(UserContext)
|
|
PropTypes.checkPropTypes(propTypes, data, 'data', 'UserContext.Provider')
|
|
return data
|
|
}
|