From 2c497f6ab3aa4ffdc8823d6c30d5a52c1cf7a126 Mon Sep 17 00:00:00 2001 From: tomas-salgado Date: Fri, 2 Aug 2024 14:12:54 -0700 Subject: [PATCH] add swag pack eligibility modal --- .../_profile.home.swag-pack.eligibility.tsx | 82 +++++++++++++++++++ .../app/routes/_profile.home.tsx | 27 ++++-- apps/member-profile/app/shared/constants.ts | 1 + 3 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 apps/member-profile/app/routes/_profile.home.swag-pack.eligibility.tsx diff --git a/apps/member-profile/app/routes/_profile.home.swag-pack.eligibility.tsx b/apps/member-profile/app/routes/_profile.home.swag-pack.eligibility.tsx new file mode 100644 index 00000000..0cfbafad --- /dev/null +++ b/apps/member-profile/app/routes/_profile.home.swag-pack.eligibility.tsx @@ -0,0 +1,82 @@ +import { + type ActionFunctionArgs, + json, + type LoaderFunctionArgs, +} from '@remix-run/node'; +import { Link, useLoaderData } from '@remix-run/react'; + +import { db } from '@oyster/db'; +import { Button, getButtonCn, Modal, Text } from '@oyster/ui'; + +import { Route } from '@/shared/constants'; +import { ensureUserAuthenticated, user } from '@/shared/session.server'; + +export async function loader({ request }: LoaderFunctionArgs) { + const session = await ensureUserAuthenticated(request); + const student = await db + .selectFrom('students') + .select(['activatedAt', 'claimedSwagPackAt', 'createdAt']) + .where('id', '=', user(session)) + .executeTakeFirst(); + + if (!student) { + throw new Response(null, { status: 404 }); + } + + const hasClaimed = student.claimedSwagPackAt; + const isActivated = student.activatedAt; + const joinedBeforeActivation = student.createdAt < new Date('2023-06-09'); // date when activation flow updated for new members + + return json({ hasClaimed, isActivated, joinedBeforeActivation }); +} + +export async function action({ request }: ActionFunctionArgs) { + await ensureUserAuthenticated(request); +} + +export default function SwagPackEligibilityModal() { + return ( + + + Swag Pack Eligibility + + + + + + ); +} + +function SwagPackEligibility() { + const { hasClaimed, isActivated, joinedBeforeActivation } = + useLoaderData(); + + return ( +
+ {hasClaimed && ( + + You have already claimed your swag pack! Check out the Merch Shop for + more swag! + + )} + {!hasClaimed && isActivated && ( + <> + + You are eligible to claim your swag pack! + + + + Claim Swag Pack + + + + )} + {!hasClaimed && joinedBeforeActivation && ( + [ Member joined before the activation date message ] + )} +
+ ); +} diff --git a/apps/member-profile/app/routes/_profile.home.tsx b/apps/member-profile/app/routes/_profile.home.tsx index 760b1911..4f863e11 100644 --- a/apps/member-profile/app/routes/_profile.home.tsx +++ b/apps/member-profile/app/routes/_profile.home.tsx @@ -689,15 +689,24 @@ function MerchStoreCard() { /> - - - Shop Now - - +
+ + + Swag Pack + + + + Shop Now + + +
); } diff --git a/apps/member-profile/app/shared/constants.ts b/apps/member-profile/app/shared/constants.ts index 79e0ebc3..91baac0b 100644 --- a/apps/member-profile/app/shared/constants.ts +++ b/apps/member-profile/app/shared/constants.ts @@ -21,6 +21,7 @@ const ROUTES = [ '/home', '/home/claim-swag-pack', '/home/claim-swag-pack/confirmation', + '/home/swag-pack/eligibility', '/login', '/login/otp/send', '/login/otp/verify',