Skip to content

Commit

Permalink
Multiple tickets (#149)
Browse files Browse the repository at this point in the history
### Short description of changes:

allow multiple tickets to be bought
  • Loading branch information
elliotsaha authored Mar 23, 2024
2 parents bd7c0fe + b68b356 commit 4b907e5
Show file tree
Hide file tree
Showing 20 changed files with 653 additions and 297 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@stripe/stripe-js": "^3.0.10",
"@tanstack/react-query": "^5.8.3",
"@uploadthing/react": "^6.2.3",
"@upstash/redis": "^1.29.0",
"axios": "^1.6.2",
"broadcast-channel": "^5.3.0",
"cf-content-types-generator": "^2.13.1",
Expand Down
51 changes: 25 additions & 26 deletions src/app/(pages)/contact/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use client';
"use client";
import {
Container,
VStack,
Expand All @@ -14,19 +14,19 @@ import {
useToast,
Textarea,
Text,
} from '@chakra-ui/react';
import {FiArrowRight} from 'react-icons/fi';
import {z} from 'zod';
import {ZOD_ERR, DEFAULT_SERVER_ERR} from '@constants/error-messages';
import {zodResolver} from '@hookform/resolvers/zod';
import {useForm} from 'react-hook-form';
import axios from 'axios';
} from "@chakra-ui/react";
import { FiArrowRight } from "react-icons/fi";
import { z } from "zod";
import { ZOD_ERR, DEFAULT_SERVER_ERR } from "@constants/error-messages";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import axios from "axios";

const schema = z.object({
name: z.string().min(1, ZOD_ERR.REQ_FIELD),
email_address: z.string().email(ZOD_ERR.INVALID_EMAIL),
message: z.string().min(1, ZOD_ERR.REQ_FIELD).max(700, {
message: 'Your message is too long',
message: "Your message is too long",
}),
});

Expand All @@ -38,32 +38,32 @@ const Contact = () => {
const {
handleSubmit,
register,
formState: {errors, isSubmitting},
formState: { errors, isSubmitting },
watch,
} = useForm<Form>({resolver: zodResolver(schema)});
} = useForm<Form>({ resolver: zodResolver(schema) });

const onSubmit = async ({name, email_address, message}: Form) => {
const onSubmit = async ({ name, email_address, message }: Form) => {
try {
const res = await axios.post(
`${process.env.NEXT_PUBLIC_HOSTNAME}/api/contact`,
{
name,
email_address,
message,
}
},
);

if (res.data) {
statusToast({
title: res.data.message,
status: 'success',
status: "success",
});
}
} catch (e) {
if (axios.isAxiosError(e)) {
statusToast({
title: e?.response?.data?.message || DEFAULT_SERVER_ERR,
status: 'error',
status: "error",
});
}
}
Expand All @@ -72,20 +72,20 @@ const Contact = () => {
const watched = watch();

return (
<Container maxW="container.xl" py={{base: '32', lg: '20'}}>
<Container maxW="container.xl" py={{ base: "32", lg: "20" }}>
<Flex flexDirection="row" w="100%" justifyContent="center" gap="36">
<Img
sizes="lg"
src="/static/images/illustrations/question-mark.svg"
alt="Solar Panel"
borderRadius="lg"
display={{base: 'none', lg: 'block'}}
display={{ base: "none", lg: "block" }}
ml="24"
/>
<form onSubmit={handleSubmit(onSubmit)}>
<VStack
align="flex-start"
w={{base: '100%', sm: 'max-content'}}
w={{ base: "100%", sm: "max-content" }}
spacing="19"
>
<Heading as="h1" size="2xl">
Expand All @@ -102,9 +102,9 @@ const Contact = () => {
type="text"
placeholder="Your Name"
disabled={isSubmitting}
w={{base: '100%', sm: 'sm'}}
w={{ base: "100%", sm: "sm" }}
size="lg"
{...register('name')}
{...register("name")}
/>
</Stack>
<FormErrorMessage>{errors?.name?.message}</FormErrorMessage>
Expand All @@ -116,9 +116,9 @@ const Contact = () => {
type="email"
placeholder="Email Address"
disabled={isSubmitting}
w={{base: '100%', sm: 'sm'}}
w={{ base: "100%", sm: "sm" }}
size="lg"
{...register('email_address')}
{...register("email_address")}
/>
</Stack>
<FormErrorMessage>
Expand All @@ -132,17 +132,17 @@ const Contact = () => {
h="36"
placeholder="Message"
disabled={isSubmitting}
w={{base: '100%', sm: 'sm'}}
w={{ base: "100%", sm: "sm" }}
size="lg"
{...register('message')}
{...register("message")}
/>
</Stack>
{errors?.message?.message ? (
<FormErrorMessage>{errors?.message?.message}</FormErrorMessage>
) : (
<Text
color={
watched?.message?.length > 700 ? 'red.500' : 'gray.500'
watched?.message?.length > 700 ? "red.500" : "gray.500"
}
fontSize="sm"
mt="2"
Expand All @@ -158,7 +158,6 @@ const Contact = () => {
colorScheme="brand"
type="submit"
loadingText="Submitting..."
size="lg"
rightIcon={<Icon as={FiArrowRight} />}
isLoading={isSubmitting}
>
Expand Down
Loading

0 comments on commit 4b907e5

Please sign in to comment.