Skip to content

Commit

Permalink
Ticket view todos #288
Browse files Browse the repository at this point in the history
Ticket view todos
  • Loading branch information
connorkm2 authored Nov 22, 2024
2 parents 4cc6bce + 9565a38 commit b00a89b
Showing 1 changed file with 38 additions and 32 deletions.
70 changes: 38 additions & 32 deletions components/admin/ticket.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
'use client'
import useSWR, {mutate} from "swr";
import { useState } from "react";
import { initialSelectedOptions } from "../ticketing/pricingDefaults";
import { format, fromUnixTime } from "date-fns";
import Link from "next/link";
import NameChangeModal from './modals/nameChangeModal';
import TicketTransferModal from './modals/ticketTransferModal';
import { fetcher } from "@lib/fetchers";
import { guaranteeTimestampFromDate } from "@lib/useful";

const accessToThings = (access:number[],) => {
let products = []
let index = 0
Object.keys(initialSelectedOptions).forEach((day) => {
Object.keys(initialSelectedOptions[day]).forEach((pass) => {
if (access[index] === 1) { products.push(`${day} ${pass}`) }
index += 1
})
})
return products
const mapAccessArrayToItems = (accessArray: number[]) => {
const accessOrder = ["Friday Party", "Saturday Classes", "Saturday Dinner", "Saturday Party", "Sunday Classes", "Sunday Party"];
return accessOrder.map((item, index) => (accessArray[index] === 1 ? item : null)).filter(item => item !== null)
}

type infoOptions = {
Expand Down Expand Up @@ -95,8 +87,8 @@ export default function TicketView({ticket_number, email}: {ticket_number: strin
<div className="p-4 flex justify-between">
<div>
<Info label="Ticket" info={ticket_number} options={{size: '3xl'}}/>
<Info label="Passes" info={accessToThings(ticket.access).join(", ")} options={{size: 'lg'}} />
<div>{JSON.stringify(ticket.access)}</div>
<Info label="Access to" info={mapAccessArrayToItems(ticket.access).join(", ")} options={{size: 'lg'}} />
{/* <div>{JSON.stringify(ticket.access)}</div> */}
<Info label="Usage & Elligibility" info={ticketUsage} />
</div>
<img src={`https://quickchart.io/qr?margin=1&text=${ticket.ticket_number}`} alt={ticket.ticket_number} className="w-40 h-40 aspect-square" />
Expand All @@ -115,30 +107,44 @@ export default function TicketView({ticket_number, email}: {ticket_number: strin
</div>
</div>

{ticket.history || ticket.transferred ? <div className="rounded-lg shadow-lg bg-richblack-600 border-gray-500 border my-4">
<h3 className="font-bold uppercase border-b border-gray-500 py-2 px-4">History</h3>
{ticket.transferred ? <div className="rounded-lg shadow-lg bg-richblack-600 border-gray-500 border my-4">
<h3 className="font-bold uppercase border-b border-gray-500 py-2 px-4">Transferred</h3>
<div className="p-4">
{ ticket.transferred ? <div key={`${ticket.transferred.ticket_number}${ticket.transferred.date}`} className="flex gap-3">
<div key={`${ticket.transferred.ticket_number}${ticket.transferred.date}`} className="flex gap-3">
<Link href={`/admin/ticketing/ticket/${ticket.transferred.ticket_number}/${ticket.transferred.email}`}> <Info label="Direction" info="OUT" options={{size: 'md'}}/></Link>
<Info label="Transferred" info={format(fromUnixTime(ticket.transferred.date),'HH:mm do MMMM yyyy ')} options={{size: 'md'}}/>
<Info label="Date" info={format(fromUnixTime(ticket.transferred.date),'HH:mm do MMM yyyy ')} options={{size: 'md'}}/>
<Info label="New Name" info={ticket.transferred.full_name} options={{size: 'md'}}/>
<Info label="New Email" info={ticket.transferred.email} options={{size: 'sm'}}/>
<Info label="Transfer By" info={ticket.transferred.source} options={{size: 'md'}}/>
</div> : null}

{ ticket.history && ticket.history.map((record) => {
const transferred_at = record.date ? typeof record.date == 'string' ? Date.parse(record.date) : fromUnixTime(record.date) : false
console.log("TD:",record.date)
return (
<div key={`${record.ticket_number}${record.date}`} className="flex gap-3 w-full max-w-full justify-between">
<Link href={`/admin/ticketing/ticket/${record.ticket_number}/${record.email}`}> <Info label="Direction" info={ticket.ticket_number == record.ticket_number ? "NAME" : "IN"} options={{size: 'md'}}/></Link>
<Info label="Transferred " info={transferred_at ? format(transferred_at,'HH:mm do MMM yyyy ') : "None"} options={{size: 'md'}}/>
<Info label="Previous Name" info={record.full_name} options={{size: 'md', grow: true}}/>
<Info label="Previous Email" info={record.email} options={{size: 'sm', grow: true}}/>
<Info label="Transfer By" info={record.source} options={{size: 'md'}}/>
</div>
)
})}
</div>
</div>
</div> : null}

{ticket.history ? <div className="rounded-lg shadow-lg bg-richblack-600 border-gray-500 border my-4">
<h3 className="font-bold uppercase border-b border-gray-500 py-2 px-4">History</h3>
<div className="p-4">
{ticket.history.map((record) => (
(!record?.action && record?.ticket_number) ? (
// transfered in record
<div key={`transfer-${record.ticket_number}${record.date}`} className="flex gap-3 w-full max-w-full justify-between">
<Link href={`/admin/ticketing/ticket/${record.ticket_number}/${record.email}`}>
<Info label="Direction" info="IN" options={{size: 'md'}}/>
</Link>
<Info label="Date" info={format(fromUnixTime(record.date), 'HH:mm do MMM yyyy ')} options={{size: 'md'}}/>
<Info label="New Name" info={record.full_name} options={{size: 'md'}}/>
<Info label="New Email" info={record.email} options={{size: 'sm'}}/>
<Info label="Transfer By" info={record.source} options={{size: 'md'}}/>
</div>
) : (
// normal history record
<div key={`history-${record.ticket_number}${record.date}`} className="flex gap-3 w-full max-w-full justify-between">
<Info label="Action" info={record.action.replace("_", " ")} options={{size: 'md'}}/>
<Info label="Description" info={(record.description || record.type || " - ").replace("_", " ")} options={{size: 'md', grow: true}}/>
<Info label="Source" info={record.source || "Unknown"} options={{size: 'md'}}/>
<Info label="Timestamp" info={record.timestamp ? format(fromUnixTime(parseInt(record.timestamp)), 'HH:mm do MMM yyyy') : "Unknown"} options={{size: 'sm'}}/>
</div>
)
))}
</div>
</div> : null }

Expand Down

0 comments on commit b00a89b

Please sign in to comment.