Skip to content

Commit

Permalink
update store and discord regex
Browse files Browse the repository at this point in the history
  • Loading branch information
EwanLyon committed Jun 12, 2023
1 parent 8016cbd commit 068d35c
Show file tree
Hide file tree
Showing 19 changed files with 255 additions and 186 deletions.
14 changes: 5 additions & 9 deletions apps/keystone/keystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,19 @@ export default withAuth(
type: base.object('Ticket'),
args: {
stripeID: graphql.arg({ type: graphql.nonNull(graphql.String) }),
numberOfTickets: graphql.arg({ type: graphql.nonNull(graphql.Int) }),
apiKey: graphql.arg({ type: graphql.nonNull(graphql.String) }),
},
resolve(source, { apiKey, numberOfTickets, stripeID }, context: Context) {
resolve(source, { apiKey, stripeID }, context: Context) {
if (apiKey !== process.env.API_KEY) throw new Error("Incorrect API Key");
// if (apiKey !== process.env.API_KEY) {
// // Debug only
// console.log(`Tried to confirm stripe but had an API key error. Got ${apiKey}, expected ${process.env.API_KEY}`);
// return;
// }

console.log('bruh');
return context.sudo().db.Ticket.updateOne({
where: { stripeID },
data: { paid: true, numberOfTickets }
data: { paid: true }
});
}
}),
Expand Down Expand Up @@ -160,17 +159,14 @@ export default withAuth(
type: base.object('ShirtOrder'),
args: {
stripeID: graphql.arg({ type: graphql.nonNull(graphql.String) }),
numberOfShirts: graphql.arg({ type: graphql.nonNull(graphql.Int) }),
apiKey: graphql.arg({ type: graphql.nonNull(graphql.String) }),
},
async resolve(source, { apiKey, stripeID, numberOfShirts }, context: Context) {
async resolve(source, { apiKey, stripeID }, context: Context) {
if (apiKey !== process.env.API_KEY) throw new Error("Incorrect API Key");

const notes = numberOfShirts > 0 ? `#${numberOfShirts}` : '';

return context.sudo().db.ShirtOrder.updateOne({
where: { stripeID },
data: { paid: true, notes }
data: { paid: true }
});
},
}),
Expand Down
4 changes: 2 additions & 2 deletions apps/keystone/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1648,9 +1648,9 @@ type Mutation {
createInitialUser(data: CreateInitialUserInput!): UserAuthenticationWithPasswordSuccess!
sendUserPasswordResetLink(email: String!): Boolean!
redeemUserPasswordResetToken(email: String!, token: String!, password: String!): RedeemUserPasswordResetTokenResult
confirmStripe(stripeID: String!, numberOfTickets: Int!, apiKey: String!): Ticket
confirmStripe(stripeID: String!, apiKey: String!): Ticket
generateTicket(userID: ID!, numberOfTickets: Int!, method: TicketMethodType!, event: String!, stripeID: String, apiKey: String!): Ticket
confirmShirtStripe(stripeID: String!, numberOfShirts: Int!, apiKey: String!): ShirtOrder
confirmShirtStripe(stripeID: String!, apiKey: String!): ShirtOrder
updateShirtSize(shirtID: String!, size: ShirtOrderSizeType!, apiKey: String!): ShirtOrder
generateShirt(userID: ID!, method: ShirtOrderMethodType!, size: ShirtOrderSizeType!, stripeID: String, apiKey: String!, notes: String): ShirtOrder
}
Expand Down
2 changes: 1 addition & 1 deletion apps/keystone/src/schema/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const User: Lists.User = list({
validation: {
isRequired: false,
match: {
regex: /(^.{3,32}#[0-9]{4}$)?/,
regex: /^(.{3,32}#[0-9]{4}|[a-z0-9._]{2,32})?$/,
explanation: `Discord user ID is invalid. Make sure its like "Clubwho#1337".`
}
}
Expand Down
53 changes: 26 additions & 27 deletions apps/nextjs/components/Ticket/BundleSale.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, useEffect } from "react";
import styles from "./TicketSale.module.scss";
import Image from "next/image";
import { Box, Button, Skeleton, TextField } from "@mui/material";
import { Box, Button, Skeleton, ToggleButton, ToggleButtonGroup } from "@mui/material";
import { UseMutationResponse, useQuery, gql, useMutation } from "urql";
import { useAuth } from "../auth";

Expand Down Expand Up @@ -29,7 +29,7 @@ const TICKET_PRICE = 50;

export function BundleProduct() {
const auth = useAuth();
const [noOfTickets, setNoOfTickets] = useState(1);
const [shirtSize, setShirtSize] = useState("m");
const [deletedTicket, setDeletedTicket] = useState(false);
const [genTicketLoading, setGenTicketLoading] = useState(false);
const [waitForTicket, setWaitForTicket] = useState(false);
Expand Down Expand Up @@ -60,7 +60,7 @@ export function BundleProduct() {
(auth.ready && !auth.sessionData) ||
!profileQueryRes.data?.user?.verified ||
!profileQueryRes.data.event.acceptingTickets;
const disableBank = disableBuying || isNaN(noOfTickets) || noOfTickets <= 0 || genTicketLoading || successfulTicket;
const disableBank = disableBuying || genTicketLoading || successfulTicket;

const [, deleteStripeTicket] = useMutation(gql`
mutation ($sessionID: String) {
Expand Down Expand Up @@ -119,9 +119,7 @@ export function BundleProduct() {
if (disableBuying) return;

setGenTicketLoading(true);
const res = await fetch(
`/api/create_bank_bundle?account=${auth.ready ? auth?.sessionData?.id : ""}&bundles=${noOfTickets}`,
);
const res = await fetch(`/api/create_bank_bundle?account=${auth.ready ? auth?.sessionData?.id : ""}&size=${shirtSize}`);

if (res.status === 200) {
setBankTicketsData(await res.json());
Expand Down Expand Up @@ -151,13 +149,26 @@ export function BundleProduct() {
All attendees, including runners and staff must purchase tickets to attend the event. Volunteers
will receive a $15 rebate administered on site at ASM2023.
</p>
<p>
We will have personalised tickets if you purchase before
<b> June 2</b>.
</p>
</section>
<hr />
<p className={styles.shirtWarning}>SHIRT SIZES WILL BE DETERMINED AT A LATER DATE</p>
<h2>Size</h2>
<div className={styles.preferences}>
<ToggleButtonGroup
fullWidth
size="small"
exclusive
value={shirtSize}
onChange={(e, value) => (value !== null ? setShirtSize(value) : undefined)}>
<ToggleButton value="m">M</ToggleButton>
<ToggleButton value="l">L</ToggleButton>
<ToggleButton value="xl">XL</ToggleButton>
<ToggleButton value="xl2">2XL</ToggleButton>
<ToggleButton value="xl3">3XL</ToggleButton>
<ToggleButton value="xl4">4XL</ToggleButton>
</ToggleButtonGroup>
<br />
<br />
</div>
<hr />
{auth.ready && !auth?.sessionData && (
<section className={styles.loginError}>
Expand All @@ -170,47 +181,35 @@ export function BundleProduct() {
<section className={styles.paymentMethod}>
<h2>Stripe</h2>
<p>Clicking on checkout will redirect you to the stripe checkout. </p>
<form action={`/api/checkout_bundle?account=${accId}&username=${accUsername}`} method="POST">
<form action={`/api/checkout_bundle?account=${accId}&username=${accUsername}&size=${shirtSize}`} method="POST">
<Button
type="submit"
role="link"
variant="contained"
color="primary"
fullWidth
disabled={disableBuying}>
Checkout ${TICKET_PRICE} each
Checkout ${TICKET_PRICE}
</Button>
</form>
</section>
<section className={styles.paymentMethod}>
<h2>Bank Transfer (Australia Only)</h2>
<div className={styles.bankTransferButton}>
<TextField
type="number"
inputProps={{ min: 1 }}
value={noOfTickets}
onChange={(e) => setNoOfTickets(parseInt(e.target.value))}
size="small"
color="secondary"
label="Number of bundles"
disabled={genTicketLoading || successfulTicket}
/>
<Button
variant="contained"
color="primary"
fullWidth
disabled={disableBank}
onClick={generateTickets}>
Generate {noOfTickets > 1 && noOfTickets} Bundle
{noOfTickets > 1 && "s"} $
{isNaN(noOfTickets) || noOfTickets <= 0 ? "∞" : noOfTickets * TICKET_PRICE}
Generate Bundle ${TICKET_PRICE}
</Button>
</div>
{bankTicketsData?.error && (
<p>It seems like there was an error. Please try again or let Clubwho know on Discord!</p>
)}
{successfulTicket && !genTicketLoading && bankTicketsData?.data && (
<ASMTicket ticketData={bankTicketsData.data.generateTicket} extraCost={noOfTickets * 25} />
<ASMTicket ticketData={bankTicketsData.data.generateTicket} extraCost={25} />
)}
{genTicketLoading && !bankTicketsData?.error && <ASMTicketSkeleton />}
</section>
Expand Down
38 changes: 38 additions & 0 deletions apps/nextjs/components/Ticket/TicketSale.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,44 @@
margin-bottom: 1rem;
}
}

.sizing {
display: flex;
gap: 1rem;

@include breakpoint($sm-zero-only) {
flex-direction: column-reverse;
width: 100%;
justify-content: center;
}

.image {
// height: 5rem;
width: 22rem;
// padding: 3rem;

@include breakpoint($sm-zero-only) {
width: 100%;
}
}


table,
th,
td {
border: 1px solid $primary;
border-collapse: collapse;
padding: 0.5rem;
// border-radius: 5px;
text-align: center;

th > span {
display: block;
font-style: italic;
font-weight: lighter;
}
}
}
}

.shirtWarning {
Expand Down
26 changes: 5 additions & 21 deletions apps/nextjs/components/Ticket/TicketSale.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const TICKET_PRICE = 25;

export function TicketProduct() {
const auth = useAuth();
const [noOfTickets, setNoOfTickets] = useState(1);
const [deletedTicket, setDeletedTicket] = useState(false);
const [genTicketLoading, setGenTicketLoading] = useState(false);
const [waitForTicket, setWaitForTicket] = useState(false);
Expand Down Expand Up @@ -60,7 +59,7 @@ export function TicketProduct() {
(auth.ready && !auth.sessionData) ||
!profileQueryRes.data?.user?.verified ||
!profileQueryRes.data.event.acceptingTickets;
const disableBank = disableBuying || isNaN(noOfTickets) || noOfTickets <= 0 || genTicketLoading || successfulTicket;
const disableBank = disableBuying || genTicketLoading || successfulTicket;

const [, deleteStripeTicket] = useMutation(gql`
mutation ($sessionID: String) {
Expand Down Expand Up @@ -122,7 +121,7 @@ export function TicketProduct() {
const res = await fetch(
`/api/create_bank_ticket?account=${
auth.ready ? auth?.sessionData?.id : ""
}&tickets=${noOfTickets}&event=ASM2023`,
}&tickets=1&event=ASM2023`,
);

if (res.status === 200) {
Expand Down Expand Up @@ -153,10 +152,6 @@ export function TicketProduct() {
All attendees, including runners and staff must purchase tickets to attend the event. Volunteers
will receive a $15 rebate administered on site at ASM2023.
</p>
<p>
We will have personalised tickets if you purchase before
<b> June 2</b>.
</p>
</section>
<hr />
{auth.ready && !auth?.sessionData && (
Expand All @@ -180,32 +175,21 @@ export function TicketProduct() {
color="primary"
fullWidth
disabled={disableBuying}>
Checkout ${TICKET_PRICE} each
Checkout ${TICKET_PRICE}
</Button>
</form>
</section>
<section className={styles.paymentMethod}>
<h2>Bank Transfer (Australia Only)</h2>
<div className={styles.bankTransferButton}>
<TextField
type="number"
inputProps={{ min: 1 }}
value={noOfTickets}
onChange={(e) => setNoOfTickets(parseInt(e.target.value))}
size="small"
color="secondary"
label="Number of tickets"
disabled={genTicketLoading || successfulTicket}
/>
<Button
variant="contained"
color="primary"
fullWidth
disabled={disableBank}
onClick={generateTickets}>
Generate {noOfTickets > 1 && noOfTickets} Ticket
{noOfTickets > 1 && "s"} $
{isNaN(noOfTickets) || noOfTickets <= 0 ? "∞" : noOfTickets * TICKET_PRICE}
Generate Ticket $
{TICKET_PRICE}
</Button>
</div>
{bankTicketsData?.error && (
Expand Down
Loading

0 comments on commit 068d35c

Please sign in to comment.