mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-25 10:10:08 +02:00
Fixed `isRequired` usages for `ApplicationProvider.value.user` GitOrigin-RevId: 0f3db77fa5da1cb0aec29ef112d1044173df88e0
47 lines
1.0 KiB
JavaScript
47 lines
1.0 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
|
|
}
|