From 90ebf8a97e8e289ebfda9c8b3430252888a927ed Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Sat, 17 Apr 2021 20:18:51 +0000 Subject: [PATCH] Added ics library, added icon to download .ics on the success page. --- package.json | 1 + pages/success.tsx | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4e6ecc5f27..a677f7b6ed 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "bcryptjs": "^2.4.3", "dayjs": "^1.10.4", "googleapis": "^67.1.1", + "ics": "^2.27.0", "next": "10.0.8", "next-auth": "^3.13.2", "react": "17.0.1", diff --git a/pages/success.tsx b/pages/success.tsx index aeb16f0850..72cf08be23 100644 --- a/pages/success.tsx +++ b/pages/success.tsx @@ -3,11 +3,33 @@ import Link from 'next/link'; import prisma from '../lib/prisma'; import { useRouter } from 'next/router'; const dayjs = require('dayjs'); +const ics = require('ics'); export default function Success(props) { const router = useRouter(); const { date } = router.query; + function eventLink(): string { + + const start = Array.prototype.concat(...date.split('T').map( + (parts) => parts.split('-').length > 1 ? parts.split('-').map( (n) => parseInt(n, 10) ) : parts.split(':').map( (n) => parseInt(n, 10) ) + )); + + const event = ics.createEvent({ + start, + startInputType: 'utc', + title: props.eventType.title + ' with ' + props.user.name, + description: props.eventType.description, + duration: { minutes: props.eventType.length } + }); + + if (event.error) { + throw event.error; + } + + return encodeURIComponent(event.value); + } + return(
@@ -18,7 +40,7 @@ export default function Success(props) {
-