import React, {useState, useReducer, useEffect} from 'react';
import {useTranslation} from 'react-i18next';
import {useAuth} from 'strapi-react-context';
import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import Container from '@material-ui/core/Container';
import Typography from '@material-ui/core/Typography';
import IconButton from '@material-ui/core/IconButton';
import Icon from '@material-ui/core/Icon';
import {makeStyles} from '@material-ui/core/styles';
import {useEvent, EventProvider} from '../contexts/Event';
import {useToast} from '../contexts/Toast';
import Layout from '../layouts/Default';
import Loading from './Loading';
import EventMenu from '../containers/EventMenu';
import EventDetails from '../containers/EventDetails';
import Fab from '../containers/Fab';
import CarColumns from '../containers/CarColumns';
import NewCarDialog from '../containers/NewCarDialog';
import AddToMyEventDialog from '../containers/AddToMyEventDialog';
import {useHistory} from 'react-router-dom';
const Event = () => {
const {t} = useTranslation();
const history = useHistory();
const {addToast} = useToast();
const [anchorEl, setAnchorEl] = useState(null);
const [isAddToMyEvent, setIsAddToMyEvent] = useState(false);
const [detailsOpen, toggleDetails] = useReducer(i => !i, false);
const classes = useStyles({detailsOpen});
const [openNewCar, toggleNewCar] = useReducer(i => !i, false);
const {event, isEditing, setIsEditing, updateEvent} = useEvent();
const {token} = useAuth();
useEffect(() => {
if (!detailsOpen) setIsEditing(false);
}, [detailsOpen]); // eslint-disable-line react-hooks/exhaustive-deps
const onEventSave = async e => {
try {
await updateEvent();
setIsEditing(false);
} catch (error) {
console.error(error);
addToast(t('event.errors.cant_update'));
}
};
const onShare = async () => {
if (!event) return null;
// If navigator as share capability
if (!!navigator.share)
return await navigator.share({
title: `Caroster ${event.name}`,
url: `${window.location.href}`,
});
// Else copy URL in clipboard
else if (!!navigator.clipboard) {
await navigator.clipboard.writeText(window.location.href);
addToast(t('event.actions.copied'));
return true;
}
};
const addToMyEvents = () => {
setIsAddToMyEvent(true);
};
const signUp = () =>
history.push({
pathname: '/register',
state: {event: event?.id},
});
const signIn = history.push.bind(undefined, '/login');
const goToDashboard = history.push.bind(undefined, '/dashboard');
const goProfile = history.push.bind(undefined, '/profile');
if (!event) return ;
return (
{detailsOpen && (
)}
{detailsOpen ? (
{
setIsEditing(false);
toggleDetails();
}}
>
close
) : (
<>
share
>
)}
{detailsOpen && (
)}
setIsAddToMyEvent(false)}
event={event}
/>
);
};
const useStyles = makeStyles(theme => ({
container: {
padding: theme.spacing(2),
},
appbar: ({detailsOpen}) => ({
overflow: 'hidden',
height: detailsOpen ? '100vh' : theme.mixins.toolbar.minHeight,
overflowY: detailsOpen ? 'scroll' : 'hidden',
transition: 'height 0.3s ease',
zIndex: theme.zIndex.appBar,
position: 'fixed',
top: 0,
}),
name: {
flexGrow: 1,
display: 'flex',
alignItems: 'center',
},
shareIcon: {
marginRight: theme.spacing(0),
},
}));
const EventWithContext = props => (
);
export default EventWithContext;