Files
maternal-app/maternal-web/components/layouts/TabBar/TabBar.tsx
Andrei 2ab98746da
Some checks failed
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled
fix: Fix 3 critical bugs - voice tracking, session persistence, and status updates
BUG-1: Voice tracking not saving activities
- Fix activity data format to match backend CreateActivityDto
- Change 'timestamp' to 'startedAt' and 'data' to 'metadata'
- Remove duplicate voice button from mobile TabBar

BUG-2: Session persistence after revocation
- Add logout() call when revoking all sessions
- Add logout() call when removing all devices
- Ensures user is logged out after session/device revocation
- Clears tokens and redirects to login

BUG-3: Voice modal status not updating
- Set identifiedActivity before saving to show tracker name
- Display "Adding to [tracker] tracker..." during save
- Improves UX by showing which tracker is being updated

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-04 06:19:09 +00:00

117 lines
3.6 KiB
TypeScript

'use client';
import { usePathname, useRouter } from 'next/navigation';
import { useState } from 'react';
import { BottomNavigation, BottomNavigationAction, Paper, Fab, Box, IconButton } from '@mui/material';
import {
Home,
Timeline,
Insights,
Chat,
Mic,
} from '@mui/icons-material';
import { useTranslation } from '@/hooks/useTranslation';
export const TabBar = () => {
const { t } = useTranslation('common');
const router = useRouter();
const pathname = usePathname();
const [voiceOpen, setVoiceOpen] = useState(false);
const tabs = [
{ label: t('navigation.home'), icon: <Home />, value: '/' },
{ label: t('navigation.track'), icon: <Timeline />, value: '/track' },
{ label: '', icon: null, value: 'voice' }, // Placeholder for center button
{ label: t('navigation.insights'), icon: <Insights />, value: '/insights' },
{ label: t('navigation.aiChat'), icon: <Chat />, value: '/ai-assistant' },
];
return (
<>
<Paper
component="nav"
aria-label="Primary navigation"
sx={{
position: 'fixed',
bottom: { xs: 0, md: 20 },
left: { xs: 0, md: '50%' },
right: { xs: 0, md: 'auto' },
transform: { xs: 'none', md: 'translateX(-50%)' },
width: { xs: '100%', md: '30%' },
zIndex: 1000,
borderRadius: { xs: 0, md: 2 },
}}
elevation={3}
>
<BottomNavigation
value={pathname}
onChange={(event, newValue) => {
if (newValue !== 'voice') {
router.push(newValue);
}
}}
showLabels
sx={{
height: 64,
borderRadius: { xs: 0, md: 2 },
'& .MuiBottomNavigationAction-root': {
minWidth: 60,
'&.Mui-selected': {
color: 'primary.main',
},
},
}}
>
{tabs.map((tab) => {
if (tab.value === 'voice') {
// Center voice button - using BottomNavigationAction as wrapper to avoid prop warnings
return (
<BottomNavigationAction
key="voice-placeholder"
label=""
value="voice"
showLabel={false}
icon={
<IconButton
aria-label="voice command"
onClick={(e) => {
e.stopPropagation();
const voiceButton = document.querySelector('[aria-label="voice input"]') as HTMLButtonElement;
if (voiceButton) {
voiceButton.click();
}
}}
sx={{
bgcolor: '#FF69B4',
color: 'white',
width: 48,
height: 48,
'&:hover': {
bgcolor: '#FF1493',
},
}}
>
<Mic />
</IconButton>
}
sx={{ minWidth: 80 }}
/>
);
}
return (
<BottomNavigationAction
key={tab.value}
label={tab.label}
icon={tab.icon}
value={tab.value}
/>
);
})}
</BottomNavigation>
</Paper>
{/* Voice Command Floating Button is now centralized in layout.tsx - removed duplicate */}
</>
);
};