import { FC, useCallback } from 'react'; import { Col, Container, Row } from 'components/layout'; import { Profile as ProfileIcon, OrganizationAdmin, Logout, Check } from 'icons'; import { TouchableTile } from 'components/touchable-tile'; import { ColorName } from '@emotion/react'; import { Divider } from 'components/divider'; import { NavigationRoutes } from 'navigation/enum'; import { useProfile, useResponsiveLayout, useRouting } from 'hooks'; import { isProfileActionOpenVar, isProfileOpenVar } from 'state-management/dialogs'; import { logout } from 'utils/auth'; import { Avatar, Text, Visible } from 'components'; export const Content: FC = ({ closeSheet }) => { const { navigateTo } = useRouting(); const { profile } = useProfile(); const { isMobile, isTabletSM } = useResponsiveLayout(); const isSmall = isMobile || isTabletSM; const doNavigateTo = useCallback( ({ actionType, nav }: NavigateToType) => { isProfileActionOpenVar(false); closeSheet(); if (actionType === 'profile' && !isSmall) { isProfileOpenVar(true); } else if (actionType === 'logout') { logout(); } else { navigateTo(nav); } }, [closeSheet, isSmall, navigateTo] ); const primaryActions: ActionType[] = [ { id: '1', title: 'Profile', onPress: () => doNavigateTo({ actionType: 'profile', nav: NavigationRoutes.Profile }), leftElement: () => , }, { id: '2', title: 'Organization Admin', onPress: () => doNavigateTo({ actionType: 'orgAdmin', nav: NavigationRoutes.AdminProfile }), leftElement: () => , }, ]; const logoutActions: ActionType[] = [ { id: '3', title: 'Log Out', titleColor: 'body', onPress: () => doNavigateTo({ actionType: 'logout', nav: NavigationRoutes.Profile }), leftElement: () => , }, ]; return ( <> } variant="text" sizeVariant="medium" mx="2xs" px="2xs" shapeVariant="round" centerElement={ {profile?.name.first} {profile?.preferredEmail} } rightElement={ } /> {primaryActions.map(({ id, title, titleColor, leftElement, onPress }) => { return ( {leftElement && leftElement()} {title} } /> ); })} {logoutActions.map(({ id, title, titleColor, leftElement, onPress }) => { return ( {leftElement && leftElement()} {title} } /> ); })} ); }; interface NavigateToType { actionType: 'profile' | 'orgAdmin' | 'logout'; nav: any; } interface ActionType { id: string; title?: string; caption?: string; titleColor?: ColorName; onPress?: () => void; leftElement?: () => JSX.Element; } interface ContentProps { closeSheet: () => void; }