import { Drawer } from "expo-router/drawer"; import { DrawerContentScrollView, DrawerItem } from "@react-navigation/drawer"; import { useRouter, Redirect } from "expo-router"; import { TouchableOpacity, DeviceEventEmitter, View, ActivityIndicator, } from "react-native"; import MaterialIcons from "@expo/vector-icons/MaterialIcons"; import { REFRESH_EVENT } from "common-ui/src/lib/const-strs"; import { useStaffAuth } from "@/components/context/staff-auth-context"; import { tw, MyText, theme } from "common-ui"; const SCREEN_TITLES: Record = { index: "Dashboard", products: "Products", "prices-overview": "Prices Overview", "product-groupings": "Product Groupings", "dashboard-banners": "Dashboard Banners", slots: "Slots", complaints: "Complaints", "manage-orders": "Manage Orders", coupons: "Coupons", "vendor-snippets": "Vendor Snippets", stores: "Stores", "user-management": "User Management", "send-notifications": "Send Notifications", "product-tags": "Product Tags", "rebalance-orders": "Rebalance Orders", "customize-app": "Customize App", }; function CustomDrawerContent() { const router = useRouter(); const { logout, staff } = useStaffAuth(); return ( {staff && ( {staff.name} Staff Member )} router.dismissTo("/(drawer)/dashboard" as any)} icon={({ color, size }) => ( )} /> router.push("/(drawer)/dashboard/products" as any)} icon={({ color, size }) => ( )} /> router.push("/(drawer)/dashboard/prices-overview" as any)} icon={({ color, size }) => ( )} /> router.push("/(drawer)/dashboard/product-groupings" as any)} icon={({ color, size }) => ( )} /> router.push("/(drawer)/dashboard/dashboard-banners" as any)} icon={({ color, size }) => ( )} /> router.push("/(drawer)/dashboard/slots" as any)} icon={({ color, size }) => ( )} /> router.push("/(drawer)/dashboard/complaints" as any)} icon={({ color, size }) => ( )} /> router.push("/(drawer)/dashboard/manage-orders" as any)} icon={({ color, size }) => ( )} /> router.push("/(drawer)/dashboard/coupons" as any)} icon={({ color, size }) => ( )} /> router.push("/(drawer)/dashboard/vendor-snippets" as any)} icon={({ color, size }) => ( )} /> router.push("/(drawer)/dashboard/stores" as any)} icon={({ color, size }) => ( )} /> router.push("/(drawer)/dashboard/user-management" as any)} icon={({ color, size }) => ( )} /> router.push("/(drawer)/dashboard/send-notifications" as any)} icon={({ color, size }) => ( )} /> logout()} icon={({ color, size }) => ( )} /> ); } export default function Layout() { const router = useRouter(); const { isLoggedIn, isLoading } = useStaffAuth(); if (isLoading) { return ( ); } if (!isLoggedIn) { return ; } return ( { const state = navigation.getState(); const focusedRoute = state?.routes?.[state?.index ?? 0]; const dashboardStack = (focusedRoute as any)?.state; const nestedIndex = dashboardStack?.index ?? 0; const canGoBack = nestedIndex > 0; const nestedRoute = dashboardStack?.routes?.[nestedIndex]; const title = SCREEN_TITLES[nestedRoute?.name ?? ""] ?? "Dashboard"; return { swipeEnabled: false, headerShown: true, headerStyle: { backgroundColor: theme.colors.gray1, shadowOpacity: 0, shadowRadius: 0, shadowOffset: { height: 0, width: 0 }, elevation: 0, }, headerTitle: title, headerTitleAlign: "center", headerLeft: () => ( canGoBack ? router.back() : (navigation as any).openDrawer() } style={{ marginLeft: 15, width: 40, height: 40, borderRadius: 20, backgroundColor: "#f2f2f2", justifyContent: "center", alignItems: "center", }} > ), headerRight: () => ( { DeviceEventEmitter.emit(REFRESH_EVENT); }} > ), }; }} > ); }