Added ics library, added icon to download .ics on the success page.
This commit is contained in:
		
							parent
							
								
									0d35bcfe38
								
							
						
					
					
						commit
						90ebf8a97e
					
				
					 2 changed files with 32 additions and 2 deletions
				
			
		|  | @ -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", | ||||
|  |  | |||
|  | @ -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( | ||||
|         <div> | ||||
|             <Head> | ||||
|  | @ -18,7 +40,7 @@ export default function Success(props) { | |||
|             <main className="max-w-3xl mx-auto my-24"> | ||||
|                 <div className="fixed z-10 inset-0 overflow-y-auto"> | ||||
|                     <div className="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0"> | ||||
|                         <div className="fixed inset-0 transition-opacity" aria-hidden="true"> | ||||
|                         <div className="fixed inset-0 my-4 sm:my-0 transition-opacity" aria-hidden="true"> | ||||
|                             <span className="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">​</span> | ||||
|                             <div className="inline-block align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-sm sm:w-full sm:p-6" role="dialog" aria-modal="true" aria-labelledby="modal-headline"> | ||||
|                                 <div> | ||||
|  | @ -46,7 +68,7 @@ export default function Success(props) { | |||
|                                         </p> | ||||
|                                         <p className="text-gray-500"> | ||||
|                                             <svg className="inline-block w-4 h-4 mr-1 -mt-1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"> | ||||
|                                                 <path fill-rule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" clip-rule="evenodd" /> | ||||
|                                                 <path fillRule="evenodd" d="M6 2a1 1 0 00-1 1v1H4a2 2 0 00-2 2v10a2 2 0 002 2h12a2 2 0 002-2V6a2 2 0 00-2-2h-1V3a1 1 0 10-2 0v1H7V3a1 1 0 00-1-1zm0 5a1 1 0 000 2h8a1 1 0 100-2H6z" clipRule="evenodd" /> | ||||
|                                             </svg> | ||||
|                                             {dayjs(date).format("hh:mma, dddd DD MMMM YYYY")} | ||||
|                                         </p> | ||||
|  | @ -71,6 +93,13 @@ export default function Success(props) { | |||
|                                         <svg className="inline-block w-4 h-4 mr-1 -mt-1" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Microsoft Office icon</title><path d="M21.53 4.306v15.363q0 .807-.472 1.433-.472.627-1.253.85l-6.888 1.974q-.136.037-.29.055-.156.019-.293.019-.396 0-.72-.105-.321-.106-.656-.292l-4.505-2.544q-.248-.137-.391-.366-.143-.23-.143-.515 0-.434.304-.738.304-.305.739-.305h5.831V4.964l-4.38 1.563q-.533.187-.856.658-.322.472-.322 1.03v8.078q0 .496-.248.912-.25.416-.683.651l-2.072 1.13q-.286.148-.571.148-.497 0-.844-.347-.348-.347-.348-.844V6.563q0-.62.33-1.19.328-.571.874-.881L11.07.285q.248-.136.534-.21.285-.075.57-.075.211 0 .38.031.166.031.364.093l6.888 1.899q.384.11.7.329.317.217.547.52.23.305.353.67.125.367.125.764zm-1.588 15.363V4.306q0-.273-.16-.478-.163-.204-.423-.28l-3.388-.93q-.397-.111-.794-.23-.397-.117-.794-.216v19.68l4.976-1.427q.26-.074.422-.28.161-.204.161-.477z"/></svg> | ||||
|                                         </a> | ||||
|                                     </Link> | ||||
|                                     <Link href={"data:text/calendar," + eventLink()}> | ||||
|                                         <a className="mx-2 btn-wide btn-white" download={props.eventType.title + '.ics'}> | ||||
|                                             <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000" width="19" height="19" className="ml-2"> | ||||
| <path d="M971.3,154.9c0-34.7-28.2-62.9-62.9-62.9H611.7c-1.3,0-2.6,0.1-3.9,0.2V10L28.7,87.3v823.4L607.8,990v-84.6c1.3,0.1,2.6,0.2,3.9,0.2h296.7c34.7,0,62.9-28.2,62.9-62.9V154.9z M607.8,636.1h44.6v-50.6h-44.6v-21.9h44.6v-50.6h-44.6v-92h277.9v230.2c0,3.8-3.1,7-7,7H607.8V636.1z M117.9,644.7l-50.6-2.4V397.5l50.6-2.2V644.7z M288.6,607.3c17.6,0.6,37.3-2.8,49.1-7.2l9.1,48c-11,5.1-35.6,9.9-66.9,8.3c-85.4-4.3-127.5-60.7-127.5-132.6c0-86.2,57.8-136.7,133.2-140.1c30.3-1.3,53.7,4,64.3,9.2l-12.2,48.9c-12.1-4.9-28.8-9.2-49.5-8.6c-45.3,1.2-79.5,30.1-79.5,87.4C208.8,572.2,237.8,605.7,288.6,607.3z M455.5,665.2c-32.4-1.6-63.7-11.3-79.1-20.5l12.6-50.7c16.8,9.1,42.9,18.5,70.4,19.4c30.1,1,46.3-10.7,46.3-29.3c0-17.8-14-28.1-48.8-40.6c-46.9-16.4-76.8-41.7-76.8-81.5c0-46.6,39.3-84.1,106.8-87.1c33.3-1.5,58.3,4.2,76.5,11.2l-15.4,53.3c-12.1-5.3-33.5-12.8-62.3-12c-28.3,0.8-41.9,13.6-41.9,28.1c0,17.8,16.1,25.5,53.6,39c52.9,18.5,78.4,45.3,78.4,86.4C575.6,629.7,536.2,669.2,455.5,665.2z M935.3,842.7c0,14.9-12.1,27-27,27H611.7c-1.3,0-2.6-0.2-3.9-0.4V686.2h270.9c19.2,0,34.9-15.6,34.9-34.9V398.4c0-19.2-15.6-34.9-34.9-34.9h-47.1v-32.3H808v32.3h-44.8v-32.3h-22.7v32.3h-43.3v-32.3h-22.7v32.3H628v-32.3h-20.2v-203c1.31.2,2.6-0.4,3.9-0.4h296.7c14.9,0,27,12.1,27,27L935.3,842.7L935.3,842.7z"/> | ||||
| </svg> | ||||
|                                         </a> | ||||
|                                     </Link> | ||||
|                                 </div> | ||||
|                             </div> | ||||
|                         </div> | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Alex van Andel
						Alex van Andel