Skip to content

Commit 6de654d

Browse files
committed
modified tab layout to render analytics page conditionally
1 parent 15659eb commit 6de654d

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

frontend/app/(tabs)/_layout.tsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Tabs } from "expo-router";
2-
import React, { FunctionComponent } from "react";
2+
import React, { FunctionComponent, useEffect, useState } from "react";
33
import { Platform, View } from "react-native";
4+
import useAuthStore from "@/auth/store";
45

56
import { HapticTab } from "@/components/HapticTab";
67
import TabBarBackground from "@/components/ui/TabBarBackground";
@@ -32,6 +33,16 @@ const TabIcon = ({ IconComponent, color, focused }: TabIconProps) => (
3233
);
3334

3435
export default function TabLayout() {
36+
// Get authentication state and restaurant owner status
37+
const { isAuthenticated, isRestaurantOwner, ownedRestaurantId } = useAuthStore();
38+
const [showRestaurantAnalyticsTab, setShowRestaurantAnalyticsTab] = useState(false);
39+
40+
// Update tab visibility when auth state changes
41+
useEffect(() => {
42+
// Show the restaurant analytics tab only if the user is authenticated and is a restaurant owner
43+
setShowRestaurantAnalyticsTab(isAuthenticated && isRestaurantOwner && !!ownedRestaurantId);
44+
}, [isAuthenticated, isRestaurantOwner, ownedRestaurantId]);
45+
3546
return (
3647
<Tabs
3748
screenOptions={{
@@ -89,14 +100,17 @@ export default function TabLayout() {
89100
),
90101
}}
91102
/>
92-
<Tabs.Screen
93-
name="restaurantAnalytics"
94-
options={{
95-
tabBarIcon: ({ color, focused }) => (
96-
<TabIcon IconComponent={RestaurantAnalyticsNavIcon} color={color} focused={focused} />
97-
),
98-
}}
99-
/>
103+
{/* Conditionally render the restaurant analytics tab */}
104+
{showRestaurantAnalyticsTab && (
105+
<Tabs.Screen
106+
name="restaurantAnalytics"
107+
options={{
108+
tabBarIcon: ({ color, focused }) => (
109+
<TabIcon IconComponent={RestaurantAnalyticsNavIcon} color={color} focused={focused} />
110+
),
111+
}}
112+
/>
113+
)}
100114
<Tabs.Screen
101115
name="profile"
102116
options={{

0 commit comments

Comments
 (0)