import React, { FC, Fragment, useState } from 'react' import { useHistory, useLocation } from 'react-router'; import { Menu, Transition } from '@headlessui/react' import { ChartBarIcon, ClipboardListIcon } from '@heroicons/react/outline' import { Dialog } from '../Dialog' import { useDispatch, useSelector } from 'react-redux'; import { useCurrentUser } from '../../contexts'; import { RootState } from '../../services/store'; import { classNames } from '../../utils'; import { DashboardRoutePaths, QuestionRoutePaths, SessionRoutePaths } from '../../routes' import { turnOff } from '../../services/store/unsavedChanges'; import { CurrentUserAvatar } from "../CurrentUserAvatar"; import { localFetch } from '../../utils/localFetch'; const UserMenu: FC = () => { const { user } = useCurrentUser(); const history = useHistory(); const [confirmLogout, setConfirmLogout] = useState(false) const unsavedChanges = useSelector((state: RootState) => state.unsavedChanges) const dispatch = useDispatch() const doLogout = () => { setConfirmLogout(false) dispatch(turnOff()) localFetch('/users/sign_out', { method: 'DELETE' }).then(() => { window.location.href = '/' }) } const handleLogout = () => { if (unsavedChanges && !confirmLogout) { setConfirmLogout(true) } else { doLogout() } } const [newPath, setNewPath] = useState() const handleForcedRedirect = () => { if (!newPath) return dispatch(turnOff()) setNewPath(undefined) history.push(newPath) } const handleLinkClick = (pathname: string) => { if (unsavedChanges) { setNewPath(pathname) } else { history.push(pathname) } } const menuItems = [ { onClick: () => { handleLinkClick(SessionRoutePaths.show) }, label: 'Perfil' }, { onClick: handleLogout, label: 'Sair' } ] return ( <> setNewPath(value ? newPath : undefined)} onConfirmation={handleForcedRedirect} title="Modificações não Salvas" text="Todas as alterações serão descartadas. Deseja continuar?" /> {({ open }) => ( <> {user?.name}
{menuItems.map((item) => ( {({ active }) => ( {item.label} )} ))} )}
) } const Links: FC = () => { const unsavedChanges = useSelector((state: RootState) => state.unsavedChanges) const dispatch = useDispatch() const location = useLocation() const history = useHistory() const [newPath, setNewPath] = useState() const handleForcedRedirect = () => { if (!newPath) return dispatch(turnOff()) setNewPath(undefined) history.push(newPath) } const handleLinkClick = (pathname: string) => { if (unsavedChanges) { setNewPath(pathname) } else { history.push(pathname) } } const links = [{ icon: , tabel: 'Painel', pathname: DashboardRoutePaths.index, isCurrent: location.pathname.includes('dashboard'), }, { icon: , tabel: 'Edição', pathname: QuestionRoutePaths.index, isCurrent: location.pathname.includes('question'), }] return ( <> setNewPath(value ? newPath : undefined)} onConfirmation={handleForcedRedirect} title="Modificações não Salvas" text="Todas as alterações serão descartadas. Deseja continuar?" />
{links.map((link) => ( ))}
) } const Logo: FC = () => (
Símbolo do Unifeso Logotipo do Unifeso
) export const Appbar = () => { return (
) }