|
1 | 1 | import { Tabs } from "expo-router"; |
2 | | -import React, { FunctionComponent } from "react"; |
| 2 | +import React, { FunctionComponent, useEffect, useState } from "react"; |
3 | 3 | import { Platform, View } from "react-native"; |
| 4 | +import useAuthStore from "@/auth/store"; |
4 | 5 |
|
5 | 6 | import { HapticTab } from "@/components/HapticTab"; |
6 | 7 | import TabBarBackground from "@/components/ui/TabBarBackground"; |
@@ -32,6 +33,16 @@ const TabIcon = ({ IconComponent, color, focused }: TabIconProps) => ( |
32 | 33 | ); |
33 | 34 |
|
34 | 35 | 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 | + |
35 | 46 | return ( |
36 | 47 | <Tabs |
37 | 48 | screenOptions={{ |
@@ -89,14 +100,17 @@ export default function TabLayout() { |
89 | 100 | ), |
90 | 101 | }} |
91 | 102 | /> |
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 | + )} |
100 | 114 | <Tabs.Screen |
101 | 115 | name="profile" |
102 | 116 | options={{ |
|
0 commit comments