overleaf/services/web/frontend/js/shared/context/user-context.tsx
Antoine Clausse 5462fcd128 [web] Set layout-react in Subscription pages (#21529)
* Update `User` type

* Set `layout-react`: `subscriptions/successful-subscription-react`

* Set `layout-react`: `subscriptions/canceled-subscription-react`

* Set `layout-react`: `subscriptions/dashboard-react`

* Set `layout-react`: `subscriptions/team/invite-managed`, `subscriptions/team/invite`, `subscriptions/team/invite_logged_out`

* Set `layout-react`: `subscriptions/team/group-invites`

* Add `header-footer-react` to subscription/base.js

* Fix: Replace `date-type` by `data-type`

* Fix SubscriptionControllerTests

GitOrigin-RevId: b9049a9093a700b3be1bf33809e3a1494022350a
2024-11-11 09:04:32 +00:00

25 lines
683 B
TypeScript

import { createContext, FC, useContext, useMemo } from 'react'
import getMeta from '../../utils/meta'
import { LoggedOutUser, User } from '../../../../types/user'
export const UserContext = createContext<User | LoggedOutUser | undefined>(
undefined
)
export const UserProvider: FC = ({ children }) => {
const user = useMemo(() => getMeta('ol-user'), [])
return <UserContext.Provider value={user}>{children}</UserContext.Provider>
}
export function useUserContext() {
const context = useContext(UserContext)
if (!context) {
throw new Error(
'useUserContext is only available inside UserContext, or `ol-user` meta is not defined'
)
}
return context
}