@@ -2,6 +2,8 @@ import { useContext } from 'react';
22import { Dialog } from '@headlessui/react' ;
33import { Club } from '@watt/shared/data/clubs' ;
44
5+ import { toCanvas , toDataURL , type QRCodeRenderersOptions } from 'qrcode' ;
6+
57// Components
68import CenteredModal from '../layout/CenteredModal' ;
79import OutlineButton , { DangerOutlineButton } from '../layout/OutlineButton' ;
@@ -39,28 +41,12 @@ export default function ClubComponentModal(props: ClubComponentModalProps) {
3941 await updateUserData ( 'clubs' , userData . clubs . filter ( clubID => clubID !== id ) , auth , firestore ) ;
4042 }
4143
42- const clubInputId = {
43- 'Monday' : '1696394268' ,
44- 'Tuesday' : '1286398699' ,
45- 'Wednesday' : '1790776594' ,
46- 'Thursday' : '438816767' ,
47- 'Friday' : '834410885'
48- } [ day . split ( ',' ) [ 0 ] ] ;
49-
50- // Prefill the form link from club and user name, if it exists
51- const prefilledData = {
52- ...( clubInputId && {
53- [ `entry.${ clubInputId } ` ] : name
54- } ) ,
55- ...( user && {
56- [ 'entry.2019720537' ] : `950${ user . email ?. match ( / \d + / ) } ` ,
57- [ 'entry.245716957' ] : day . split ( ',' ) [ 0 ] ,
58- [ 'emailAddress' ] : user . email ,
59- [ 'entry.878125936' ] : user . displayName
60- } )
61- } as Record < string , string > ;
62-
63- const prefilledLink = `https://docs.google.com/forms/d/e/1FAIpQLSf_K0HpLJBe6SlmX8feUc_xCb2_bs75MLyzf8p2N3G1QcDA8Q/viewform?${ new URLSearchParams ( prefilledData ) } ` ;
44+ const prefillId = Number ( id ) . toString ( 36 ) ;
45+ const qrData = `https://gunn.app/prefill/${ prefillId } ` ;
46+ const qrConfig : QRCodeRenderersOptions = {
47+ errorCorrectionLevel : "L" ,
48+ margin : 3
49+ } ;
6450
6551 return (
6652 < CenteredModal className = "relative flex flex-col bg-content rounded-md max-w-md max-h-[90%] mx-2 p-6 shadow-xl" isOpen = { isOpen } setIsOpen = { setIsOpen } >
@@ -81,11 +67,51 @@ export default function ClubComponentModal(props: ClubComponentModalProps) {
8167 </ section >
8268 < hr className = "my-3" />
8369
84- < section className = "mb-4 overflow-scroll scroll-smooth scrollbar-none" >
70+ < section className = "overflow-scroll scroll-smooth scrollbar-none" >
8571 < Dialog . Description > { desc } </ Dialog . Description >
8672 </ section >
8773
88- < section className = "flex gap-3 flex-wrap justify-end" >
74+ < div className = "hidden md:block outline outline-2 outline-tertiary rounded-md mt-4" >
75+ < section className = "flex h-full" >
76+ < canvas
77+ className = "rounded-sm rounded-r-none rounded-l-md"
78+ style = { { imageRendering : 'pixelated' } }
79+ ref = { canvas => canvas && toCanvas ( canvas , qrData , qrConfig ) }
80+ />
81+ < div className = "flex flex-col grow m-auto text-secondary text-center" >
82+ < p className = "font-semibold" > Club Attendance</ p >
83+ < a
84+ href = { qrData }
85+ target = "_blank"
86+ rel = "noopener noreferrer"
87+ className = "rounded-sm m-auto px-4 py-1 bg-tertiary text-secondary font-bold"
88+ >
89+ { qrData . replace ( 'https://' , '' ) }
90+ </ a >
91+ < div className = "text-xs text-secondary mt-0.5" >
92+ Copy{ ' ' }
93+ < strong
94+ onClick = { ( ) => navigator . clipboard . writeText ( qrData ) }
95+ className = "hover:cursor-pointer hover:underline"
96+ >
97+ Link
98+ </ strong >
99+ < span > · </ span >
100+ < strong
101+ onClick = { async ( ) => {
102+ const qr = await fetch ( await toDataURL ( qrData , qrConfig ) )
103+ navigator . clipboard . write ( [ new ClipboardItem ( { "image/png" : await qr . blob ( ) } ) ] ) ;
104+ } }
105+ className = "hover:cursor-pointer hover:underline"
106+ >
107+ QR Code
108+ </ strong >
109+ </ div >
110+ </ div >
111+ </ section >
112+ </ div >
113+
114+ < section className = "flex gap-3 mt-4 flex-wrap justify-end" >
89115 { pinned ? (
90116 < OutlineButton onClick = { removeFromPinned } >
91117 Remove from my list
@@ -95,9 +121,6 @@ export default function ClubComponentModal(props: ClubComponentModalProps) {
95121 Add to my list
96122 </ OutlineButton >
97123 ) }
98- < a href = { prefilledLink } tabIndex = { - 1 } target = "_blank" rel = "noopener noreferrer" >
99- < OutlineButton > Check In</ OutlineButton >
100- </ a >
101124 < DangerOutlineButton onClick = { ( ) => setIsOpen ( false ) } >
102125 Close
103126 </ DangerOutlineButton >
0 commit comments