import React from 'react' import { useRouter } from 'next/router' import { useCookies } from 'react-cookie' import { useSnapshot } from 'valtio' import clonedeep from 'lodash.clonedeep' import * as Scroll from 'react-scroll' import * as AlertDialog from '@radix-ui/react-alert-dialog' import Header from '~components/Header' import Button from '~components/Button' import api from '~utils/api' import { accountState } from '~utils/accountState' import { appState, initialAppState } from '~utils/appState' import { ButtonType } from '~utils/enums' import CrossIcon from '~public/icons/Cross.svg' import { route } from 'next/dist/server/router' const BottomHeader = () => { const account = useSnapshot(accountState) const app = useSnapshot(appState) const router = useRouter() const scroll = Scroll.animateScroll; // Cookies const [cookies] = useCookies(['account']) const headers = (cookies.account != null) ? { headers: { 'Authorization': `Bearer ${cookies.account.access_token}` } } : {} function toggleDetails() { appState.party.detailsVisible = !appState.party.detailsVisible if (appState.party.detailsVisible) scroll.scrollToBottom() else scroll.scrollToTop() } function deleteTeam(event: React.MouseEvent) { if (appState.party.editable && appState.party.id) { api.endpoints.parties.destroy({ id: appState.party.id, params: headers }) .then(() => { // Push to route router.push('/') // Clean state const resetState = clonedeep(initialAppState) Object.keys(resetState).forEach((key) => { appState[key] = resetState[key] }) // Set party to be editable appState.party.editable = true }) .catch((error) => { console.error(error) }) } } const leftNav = () => { if (router.pathname === '/p/[party]' || router.pathname === '/new') { if (app.party.detailsVisible) { return () } else { return () } } else { return (
) } } const rightNav = () => { if (app.party.editable && router.route === '/p/[party]') { return ( Delete team Delete team Are you sure you want to permanently delete this team?
Nevermind deleteTeam(e)}>Yes, delete
) } else { return (
) } } return (
) } export default BottomHeader