diff --git a/native/root.react.js b/native/root.react.js --- a/native/root.react.js +++ b/native/root.react.js @@ -43,6 +43,7 @@ import { useSelector } from './redux/redux-utils'; import { RootContext } from './root-context'; import Socket from './socket.react'; +import { StaffContextProvider } from './staff/staff-context.provider.react'; import { DarkTheme, LightTheme } from './themes/navigation'; import ThemeHandler from './themes/theme-handler.react'; import './themes/fonts'; @@ -241,33 +242,35 @@ } return ( - - - - - - - - - - {gated} - - - - - {navigation} - - - - - - - - + + + + + + + + + + + {gated} + + + + + {navigation} + + + + + + + + + ); } diff --git a/native/staff/staff-context.provider.react.js b/native/staff/staff-context.provider.react.js new file mode 100644 --- /dev/null +++ b/native/staff/staff-context.provider.react.js @@ -0,0 +1,44 @@ +// @flow + +import * as React from 'react'; +import { useSelector } from 'react-redux'; + +import { isStaff } from 'lib/shared/user-utils'; + +import { StaffContext, type StaffContextType } from './staff-context'; + +type Props = { + +children: React.Node, +}; +function StaffContextProvider(props: Props): React.Node { + const [ + staffUserHasBeenLoggedIn, + setStaffUserHasBeenLoggedIn, + ] = React.useState(false); + + const isCurrentUserStaff = useSelector( + state => + state.currentUserInfo && + state.currentUserInfo.id && + isStaff(state.currentUserInfo.id), + ); + + React.useEffect(() => { + if (isCurrentUserStaff) { + setStaffUserHasBeenLoggedIn(true); + } + }, [isCurrentUserStaff]); + + const staffContextValue: StaffContextType = React.useMemo( + () => ({ staffUserHasBeenLoggedIn }), + [staffUserHasBeenLoggedIn], + ); + + return ( + + {props.children} + + ); +} + +export { StaffContextProvider };