Skip to content

Commit

Permalink
add mock scan qr button
Browse files Browse the repository at this point in the history
  • Loading branch information
imajindev committed Aug 11, 2024
1 parent 1598f88 commit c0c88cf
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/haus/src/components/confirm-ticket/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function ConfirmTicket({ setStep }: { setStep: (step: number) => void }) {
id: event?.id || '',
eventId: event?.id || '',
worldProof: item.proof,
holderName: ensName || address || '',
holderName: ensName || 'Anonymous',
type: event?.tickets[0].type || '',
seatNumber: generateSeatNumber(),
entryFor: 1,
Expand Down
61 changes: 49 additions & 12 deletions apps/haus/src/components/tickets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,61 @@ import Container from '@mui/material/Container'
import Typography from '@mui/material/Typography'
import LocationOnIcon from '@mui/icons-material/LocationOn'
import CalendarTodayIcon from '@mui/icons-material/CalendarToday'
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, Grid } from '@mui/material'
import React from 'react'
import {
Button,
CircularProgress,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
Grid,
} from '@mui/material'
import React, { useState } from 'react'
import QRCode from 'react-qr-code'
import { EVENTS } from '@/config/events'

const DialogTicket = ({ handleClose, open }: { handleClose: () => void; open: boolean }) => {
const DialogTicket = ({ handleClose, selected }: { handleClose: () => void; selected: any }) => {
const [loading, setLoading] = useState(false)
const [data, setData] = useState<any>(null)

const handleScan = async () => {
if (!selected || !selected.attestation) return
try {
setLoading(true)
const response = await fetch(`/api/attestation/${selected.attestation.id}`)
const result = await response.json()
setData(result)
console.log(result)
} catch (error) {
console.error('Error verifying attestations:', error)
} finally {
setLoading(false)
}
}

return (
<Dialog
open={open}
open={!!selected}
onClose={handleClose}
>
<DialogTitle>Drive In Senja: Back to the Future</DialogTitle>
<DialogTitle>{selected && selected.event ? selected.event.name : '-'}</DialogTitle>
<DialogContent>
<Stack
alignItems="center"
spacing={1}
>
<QRCode value="hey" />
{selected && selected.attestation && (
<>
{loading ? (
<CircularProgress />
) : (
<QRCode
value={`http://localhost:3000/api/attestation/${selected.attestation.id}`}
/>
)}
<Button onClick={handleScan}>Scan</Button>
</>
)}
</Stack>
</DialogContent>
<DialogActions>
Expand Down Expand Up @@ -97,7 +134,7 @@ const Ticket = ({ attestation, handleClickOpen }: any) => {
variant="contained"
sx={styles.buttonTicket}
onClick={() => {
handleClickOpen(attestation)
handleClickOpen({ attestation, event })
}}
>
Ticket
Expand All @@ -109,15 +146,15 @@ const Ticket = ({ attestation, handleClickOpen }: any) => {
}

function Tickets({ attestations }: any) {
const [open, setOpen] = React.useState(false)
const [selected, setSelected] = React.useState(null)
console.log('attestations', attestations)

const handleClickOpen = () => {
setOpen(true)
const handleClickOpen = (attestation: any) => {
setSelected(attestation)
}

const handleClose = () => {
setOpen(false)
setSelected(null)
}

return (
Expand Down Expand Up @@ -146,7 +183,7 @@ function Tickets({ attestations }: any) {
))}
</Grid>
<DialogTicket
open={open}
selected={selected}
handleClose={handleClose}
/>
</Container>
Expand Down

0 comments on commit c0c88cf

Please sign in to comment.