import { useEffect, useRef, useState } from 'react' import { codeBlock } from 'common-tags' import { CodeBlock } from 'ui' import { range } from 'lodash' import { Pencil, X } from 'lucide-react' import Tilt from 'vanilla-tilt' import { useParams } from 'common' import Panel from '~/components/Panel' import useConfData from '~/components/LaunchWeek/hooks/use-conf-data' import TicketCustomizationForm from './TicketCustomizationForm' import { themes as ticketThemes } from './ticketThemes' export default function Ticket() { const ticketRef = useRef(null) const { userData: user, showCustomizationForm, setShowCustomizationForm } = useConfData() const { platinum = false, secret: hasSecretTicket, ticket_number: ticketNumber, username } = user const params = useParams() const [responseTime, setResponseTime] = useState<{ start: number; end: number | undefined }>({ start: performance.now(), end: undefined, }) const sharePage = !!params.username const ticketType = hasSecretTicket ? 'secret' : platinum ? 'platinum' : 'regular' const TICKET_THEME = ticketThemes[ticketType] function handleCustomizeTicket() { setShowCustomizationForm && setShowCustomizationForm(!showCustomizationForm) } useEffect(() => { user && setResponseTime((prev) => ({ ...prev, end: performance.now() })) }, [user.id]) useEffect(() => { if (ticketRef.current && !window.matchMedia('(pointer: coarse)').matches) { Tilt.init(ticketRef.current, { glare: true, max: 3, gyroscope: true, 'max-glare': 0.1, 'full-page-listening': true, }) } }, [ticketRef]) const code = codeBlock`await supabase .from('tickets') .select('*') .eq('launch_week', 'lw12') .eq('username', '${username}') .single() ` const HAS_ROLE = true // user.role const HAS_COMPANY = true // user.company const HAS_LOCATION = true // user.location // Keep following indentation for proper json layout with conditionals const responseJson = codeBlock` { "data": { "name": "${user.name}", "username": "${username}", "ticket_number": "${ticketNumber}", "role": ${user.role ? `"${user.role}"` : 'null'}, "company": ${user.company ? `"${user.company}"` : 'null'}, "location": ${user.location ? `"${user.location}"` : 'null'}, }, "error": null } ` function getLinesToHighlight() { let arr: any[] = range(0, 3) const STARTING_LINE = 3 if (HAS_ROLE) arr.push(null) if (HAS_COMPANY) arr.push(null) if (HAS_LOCATION) arr.push(null) return arr.map((_, i) => i + STARTING_LINE) } const LINES_TO_HIGHLIGHT = getLinesToHighlight() const resTime = (responseTime.end! - responseTime.start).toFixed() return (
Launch Week 12 Ticket {code}
TICKET RESPONSE {user && ( {responseJson} )} {/* {resTime}ms Response time */}
{/* Edit hover button */} {!sharePage && ( <>
) }