diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 47c47577..af74014f 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -192,7 +192,7 @@ model Winners { year Int userId String lastDateClaim DateTime - type WinnerType + type String user User @relation(fields: [userId], references: [id]) claimed DateTime? @@ -203,12 +203,6 @@ model Winners { @@index([claimed]) } -enum WinnerType { - EXTRA - COMPETITION - NOVU -} - model VerificationToken { identifier String token String @unique diff --git a/src/components/pages/claim/hero/form.jsx b/src/components/pages/claim/hero/form.jsx index e69de29b..36455f2b 100644 --- a/src/components/pages/claim/hero/form.jsx +++ b/src/components/pages/claim/hero/form.jsx @@ -0,0 +1,134 @@ +import { getNames } from 'country-list'; +import moment from 'moment'; +import PropTypes from 'prop-types'; +import React from 'react'; +import { useFormContext } from 'react-hook-form'; + +import Input from '../../../shared/button/input'; +import Select from '../../../shared/button/select'; + +const Form = ({ info }) => { + const { + register, + formState: { errors, isSubmitSuccessful }, + } = useFormContext(); + return ( + <> +
+ Select Prizes to claim: + {info.map((winner) => ( +
+
+ +
+
+ {winner.type === 'COMPETITION' && 'Competition Winner'} + {winner.type === 'NOVU' && 'Novu Swag Claim'} + {winner.type === 'EXTRA' && 'Giveaway or other'} - Expires on{' '} + {moment.utc(winner.lastDateClaim).local().format('DD/MM/YYYY HH:mm')} +
+
+ ))} + {!!errors.type && ( +
+ You must select a prize to claim +
+ )} +
+ + + + + + + + + + + + + + ); +}; + +Form.propTypes = { + info: PropTypes.object, +}; + +export default Form; diff --git a/src/components/pages/claim/hero/hero.jsx b/src/components/pages/claim/hero/hero.jsx index e69de29b..2ff6fd7e 100644 --- a/src/components/pages/claim/hero/hero.jsx +++ b/src/components/pages/claim/hero/hero.jsx @@ -0,0 +1,83 @@ +import { useRouter } from 'next/router'; +import { useSession } from 'next-auth/react'; +import PropTypes from 'prop-types'; +import React from 'react'; +import { useForm, FormProvider } from 'react-hook-form'; +import { toast } from 'react-toastify'; + +import Hero2 from 'components/pages/no-win/hero'; + +import Novu from '../../../shared/socials/novu'; + +import Form from './form'; +import NoLogged from './no-logged'; + +const title = '>> Claim Prizes 🎉'; + +const Hero = ({ info }) => { + const { push } = useRouter(); + + const all = useForm({ + defaultValues: { + first_name: '', + }, + }); + + const onSubmit = (data) => { + (async () => { + const newData = await fetch('/api/claim', { + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + method: 'POST', + body: JSON.stringify({ ...data, type: Array.isArray(data.type) ? data.type : [data.type] }), + }); + + const isValid = newData.json(); + if (isValid.invalid) { + toast.error('Invalid submission, please refresh the page and try again'); + return; + } + + push('/claim-success'); + })(); + }; + + const { status } = useSession(); + if (status === 'loading') { + return <>; + } + if (status !== 'authenticated') { + return ; + } + + if (info.length === 0) { + return ; + } + + return ( + +
+
+ +

+ {title} +

+
+ +
+
+
+
+ ); +}; + +Hero.propTypes = { + info: PropTypes.object, +}; + +export default Hero; diff --git a/src/components/pages/claim/hero/images/bg.jpg b/src/components/pages/claim/hero/images/bg.jpg index e69de29b..870f4ef1 100644 Binary files a/src/components/pages/claim/hero/images/bg.jpg and b/src/components/pages/claim/hero/images/bg.jpg differ diff --git a/src/components/pages/claim/hero/index.js b/src/components/pages/claim/hero/index.js index e69de29b..2eb98699 100644 --- a/src/components/pages/claim/hero/index.js +++ b/src/components/pages/claim/hero/index.js @@ -0,0 +1 @@ +export { default } from './hero'; diff --git a/src/components/pages/claim/hero/no-logged.jsx b/src/components/pages/claim/hero/no-logged.jsx index e69de29b..54905aad 100644 --- a/src/components/pages/claim/hero/no-logged.jsx +++ b/src/components/pages/claim/hero/no-logged.jsx @@ -0,0 +1,36 @@ +import Image from 'next/image'; +import React from 'react'; + +import SignUpButton from 'components/shared/sign-up-button'; +import Socials from 'components/shared/socials'; + +import bg from './images/bg.jpg'; + +const title = '>>Sign in!'; +const description = <>Oh no, you have probably signed out of the system; + +const NoLogged = () => ( +
+
+

+ {title} +

+

{description}

+ + +
+ + +
+); + +export default NoLogged; diff --git a/src/layouts/layouts/layout-main/layout-main.jsx b/src/layouts/layouts/layout-main/layout-main.jsx index 09717cb1..fd26f2e5 100644 --- a/src/layouts/layouts/layout-main/layout-main.jsx +++ b/src/layouts/layouts/layout-main/layout-main.jsx @@ -5,7 +5,6 @@ import { ToastContainer } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; // import ReactTooltip from 'react-tooltip'; -import Banner from 'components/shared/banner'; import MobileMenu from 'components/shared/mobile-menu'; import Footer from 'components/shared/old-footer'; import Header from 'components/shared/old-header'; @@ -34,7 +33,7 @@ const LayoutMain = ({ closeButton={false} />
- + {/* */}
{ await airTable .base(process.env.AIRTABLE_BASE) - .table('Hacksquad 2022') + .table('Hacksquad 2023') .create({ first_name: req.body.first_name, last_name: req.body.last_name,