import Head from 'next/head'; import Link from 'next/link'; import prisma from '../lib/prisma'; import {useEffect, useState} from "react"; import { useRouter } from 'next/router'; import { CheckIcon } from '@heroicons/react/outline'; import { ClockIcon, CalendarIcon, LocationMarkerIcon } from '@heroicons/react/solid'; import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; import toArray from 'dayjs/plugin/toArray'; import timezone from 'dayjs/plugin/timezone'; import { createEvent } from 'ics'; dayjs.extend(utc); dayjs.extend(toArray); dayjs.extend(timezone); export default function Success(props) { const router = useRouter(); const { location } = router.query; const [ is24h, setIs24h ] = useState(false); const [ date, setDate ] = useState(dayjs.utc(router.query.date)); useEffect( () => { setDate(date.tz(localStorage.getItem('timeOption.preferredTimeZone') || dayjs.tz.guess())); setIs24h(!!localStorage.getItem('timeOption.is24hClock')); }, []); function eventLink(): string { let optional = {}; if (location) { optional['location'] = location; } const event = createEvent({ start: date.utc().toArray().slice(0, 6), startInputType: 'utc', title: props.eventType.title + ' with ' + props.user.name, description: props.eventType.description, duration: { minutes: props.eventType.length }, ...optional }); if (event.error) { throw event.error; } return encodeURIComponent(event.value); } return(