mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
24261ac617
Add Writeful to user settings GitOrigin-RevId: 15b3dd47b96cdc8bf8002afe3ddc570b03a6065f
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
import { createContext, useContext } from 'react'
|
|
import PropTypes from 'prop-types'
|
|
import getMeta from '../../utils/meta'
|
|
|
|
export const UserContext = createContext()
|
|
|
|
UserContext.Provider.propTypes = {
|
|
value: PropTypes.shape({
|
|
user: PropTypes.shape({
|
|
id: PropTypes.string,
|
|
isAdmin: PropTypes.boolean,
|
|
email: PropTypes.string,
|
|
allowedFreeTrial: PropTypes.boolean,
|
|
first_name: PropTypes.string,
|
|
last_name: PropTypes.string,
|
|
alphaProgram: PropTypes.boolean,
|
|
betaProgram: PropTypes.boolean,
|
|
labsProgram: PropTypes.boolean,
|
|
signUpDate: PropTypes.string,
|
|
features: PropTypes.shape({
|
|
dropbox: PropTypes.boolean,
|
|
github: PropTypes.boolean,
|
|
mendeley: PropTypes.boolean,
|
|
zotero: PropTypes.boolean,
|
|
references: PropTypes.boolean,
|
|
compileTimeout: PropTypes.number,
|
|
gitBridge: PropTypes.boolean,
|
|
}),
|
|
refProviders: PropTypes.shape({
|
|
mendeley: PropTypes.boolean,
|
|
zotero: PropTypes.boolean,
|
|
}),
|
|
writefull: PropTypes.shape({
|
|
enabled: PropTypes.boolean,
|
|
}),
|
|
}),
|
|
}),
|
|
}
|
|
|
|
export function UserProvider({ children }) {
|
|
const user = getMeta('ol-user')
|
|
|
|
return <UserContext.Provider value={user}>{children}</UserContext.Provider>
|
|
}
|
|
|
|
UserProvider.propTypes = {
|
|
children: PropTypes.any,
|
|
}
|
|
|
|
export function useUserContext(propTypes) {
|
|
const data = useContext(UserContext)
|
|
if (!data) {
|
|
throw new Error(
|
|
'useUserContext is only available inside UserContext, or `ol-user` meta is not defined'
|
|
)
|
|
}
|
|
|
|
PropTypes.checkPropTypes(propTypes, data, 'data', 'UserContext.Provider')
|
|
return data
|
|
}
|