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 };