import React, { useState } from "react"; import logo from "../../static/header-logo.svg"; import AppsIcon from "@mui/icons-material/Apps"; import RefreshIcon from "@mui/icons-material/Refresh"; import ChevronLeftIcon from "@mui/icons-material/ChevronLeft"; import ChevronRightIcon from "@mui/icons-material/ChevronRight"; import "./Menubar.styl"; import { useAppDispatch, useAppSelector } from "../../app/hooks"; import { stringToColor } from "../Event/utils/eventUtils"; import { Avatar, IconButton, Popover, ButtonGroup, Button, Select, MenuItem, FormControl, Typography, } from "@mui/material"; import { push } from "redux-first-history"; import { CalendarApi } from "@fullcalendar/core"; import { useI18n } from "cozy-ui/transpiled/react/providers/I18n"; import { setLanguage } from "../../features/Settings/SettingsSlice"; export type AppIconProps = { name: string; link: string; icon: string; }; export type MenubarProps = { calendarRef: React.RefObject; onRefresh: () => void; currentDate: Date; onDateChange?: (date: Date) => void; currentView: string; onViewChange?: (view: string) => void; }; export function Menubar({ calendarRef, onRefresh, currentDate, onDateChange, currentView, onViewChange, }: MenubarProps) { const { t, f, lang } = useI18n(); const user = useAppSelector((state) => state.user.userData); const applist: AppIconProps[] = (window as any).appList ?? []; const [anchorEl, setAnchorEl] = useState(null); const [langAnchorEl, setLangAnchorEl] = useState(null); const dispatch = useAppDispatch(); if (!user) { dispatch(push("/")); } const handleOpen = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); }; const handleNavigation = (action: "prev" | "next" | "today") => { if (!calendarRef.current) return; switch (action) { case "prev": calendarRef.current.prev(); break; case "next": calendarRef.current.next(); break; case "today": calendarRef.current.today(); break; } // Notify parent about date change after navigation if (onDateChange) { const newDate = calendarRef.current.getDate(); onDateChange(newDate); } }; const handleViewChange = (view: string) => { if (!calendarRef.current) return; calendarRef.current.changeView(view); // Notify parent about view change if (onViewChange) { onViewChange(view); } // Notify parent about date change after view change if (onDateChange) { const newDate = calendarRef.current.getDate(); onDateChange(newDate); } }; const open = Boolean(anchorEl); const langOpen = Boolean(langAnchorEl); const handleLangClick = (event: React.MouseEvent) => { setLangAnchorEl(event.currentTarget); }; const handleLangClose = () => setLangAnchorEl(null); const availableLangs = [ { code: "en", label: "English" }, { code: "fr", label: "Français" }, ]; return ( <>
{f(currentDate, "MMMM yyyy")}
{applist.length > 0 && ( )}
{user?.name && user?.family_name ? `${user.name[0]}${user.family_name[0]}` : (user?.email?.[0] ?? "")}
{applist.map((prop: AppIconProps) => ( ))}
); } export function MainTitle() { const { t } = useI18n(); return (
{t("menubar.logoAlt")}
); } function AppIcon({ prop }: { prop: AppIconProps }) { return (
{prop.name}

{prop.name}

); }