import React from 'react'; import { Text, View, TouchableOpacity, ScrollView, Image, } from 'react-native'; import { DrawerContentComponentProps } from '@react-navigation/drawer'; import Icon from 'react-native-vector-icons/Ionicons'; import { menuItems } from '@mock-data'; import { useTheme } from '@theme'; import { DrawerItemProps } from '@interfaces'; import { route } from '@utils'; import { getStyles } from './customDrawerContent.style'; import { useAppDispatch, useAppSelector, logout, RootState } from '@store'; const DrawerItem = ({ label, iconName, focused, onPress }: DrawerItemProps) => { const { theme: colors } = useTheme(); const styles = getStyles(colors); return ( {focused && } {label} ); }; export const CustomDrawerContent = (props: DrawerContentComponentProps) => { const { state, navigation } = props; const { theme: colors } = useTheme(); const styles = getStyles(colors); const dispatch = useAppDispatch(); const userData = useAppSelector((state: RootState) => state.auth.user_data); const handleLogout = async () => { try { dispatch(logout()); } catch (e) { console.error(e); } navigation.reset({ index: 0, routes: [{ name: 'AuthStack' }], }); }; const activeRouteName = state.routeNames[state.index]; // User details const fullName = userData?.full_name || `${userData?.firstname || ''} ${userData?.lastname || ''}`.trim() || 'User'; const email = userData?.email || 'N/A'; const isAdmin = userData?.admin === '1'; const roleText = isAdmin ? 'Administrator' : 'Staff Member'; const isActive = userData?.active === '1'; const hasProfileImage = userData?.profile_image && userData.profile_image.startsWith('http'); const initials = fullName .split(' ') .filter(Boolean) .map(n => n[0]) .join('') .substring(0, 2) .toUpperCase() || 'U'; return ( {/* ── Drawer Header (User Profile) ── */} navigation.navigate('home', { screen: route.profile })}> {hasProfileImage ? ( ) : ( {initials} )} {isActive && } {fullName} {email} {roleText} {/* ── Navigation Menu List ── */} {menuItems.map(item => { const isFocused = activeRouteName === item.route; return ( navigation.navigate(item.route)} /> ); })} {/* ── Drawer Footer (Logout) ── */} Sign Out ); };