mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
f5942f1a7b
Fixed `isRequired` usages for `ApplicationProvider.value.user` GitOrigin-RevId: 0f3db77fa5da1cb0aec29ef112d1044173df88e0
46 lines
1 KiB
JavaScript
46 lines
1 KiB
JavaScript
import React, { createContext, useContext } from 'react'
|
|
import PropTypes from 'prop-types'
|
|
|
|
export const ApplicationContext = createContext()
|
|
|
|
ApplicationContext.Provider.propTypes = {
|
|
value: PropTypes.shape({
|
|
user: PropTypes.shape({
|
|
id: PropTypes.string.isRequired,
|
|
firstName: PropTypes.string,
|
|
lastName: PropTypes.string,
|
|
}),
|
|
gitBridgePublicBaseUrl: PropTypes.string.isRequired,
|
|
}),
|
|
}
|
|
|
|
export function ApplicationProvider({ children }) {
|
|
const applicationContextValue = {
|
|
gitBridgePublicBaseUrl: window.gitBridgePublicBaseUrl,
|
|
}
|
|
|
|
if (window.user.id) {
|
|
applicationContextValue.user = window.user
|
|
}
|
|
|
|
return (
|
|
<ApplicationContext.Provider value={applicationContextValue}>
|
|
{children}
|
|
</ApplicationContext.Provider>
|
|
)
|
|
}
|
|
|
|
ApplicationProvider.propTypes = {
|
|
children: PropTypes.any,
|
|
}
|
|
|
|
export function useApplicationContext(propTypes) {
|
|
const data = useContext(ApplicationContext)
|
|
PropTypes.checkPropTypes(
|
|
propTypes,
|
|
data,
|
|
'data',
|
|
'ApplicationContext.Provider'
|
|
)
|
|
return data
|
|
}
|