2021-06-25 04:14:07 -04:00
|
|
|
import { createContext, useContext } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2021-10-08 06:09:41 -04:00
|
|
|
import useScopeValue from '../hooks/use-scope-value'
|
2021-06-25 04:14:07 -04:00
|
|
|
|
|
|
|
export const UserContext = createContext()
|
|
|
|
|
|
|
|
UserContext.Provider.propTypes = {
|
|
|
|
value: PropTypes.shape({
|
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string,
|
2021-10-06 04:33:24 -04:00
|
|
|
email: PropTypes.string,
|
2021-06-25 04:14:07 -04:00
|
|
|
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
|
|
|
|
}
|