Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

fix (#1234)

bautistaaa68350eaf1501
diff --git a/apps/web/src/app/[locale]/aot-2023/_components/card-grid.tsx b/apps/web/src/app/[locale]/aot-2023/_components/card-grid.tsx
index 43ce9681..a70aa3e1 100644
--- a/apps/web/src/app/[locale]/aot-2023/_components/card-grid.tsx
+++ b/apps/web/src/app/[locale]/aot-2023/_components/card-grid.tsx
@@ -1,7 +1,7 @@
import { prisma } from '@repo/db';
import { TiltableCard } from './tiltable-card';
import { auth, type Session } from '@repo/auth/server';
-import { daysAfterDecemberFirst } from '../../challenge/[slug]/page';
+import { daysAfterDecemberFirst } from '~/utils/aot';
export async function CardGrid() {
const session = await auth();
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/getChallengeRouteData.ts b/apps/web/src/app/[locale]/challenge/[slug]/getChallengeRouteData.ts
index 4c105fb8..c487119e 100644
--- a/apps/web/src/app/[locale]/challenge/[slug]/getChallengeRouteData.ts
+++ b/apps/web/src/app/[locale]/challenge/[slug]/getChallengeRouteData.ts
@@ -2,12 +2,23 @@ import { type Session } from '@repo/auth/server';
import { prisma } from '@repo/db';
import { cache } from 'react';
import { getAllFlags } from '~/utils/feature-flags';
+import { AOT_CHALLENGES } from './aot-slugs';
+import { daysAfterDecemberFirst } from '~/utils/aot';
export type ChallengeRouteData = NonNullable<Awaited<ReturnType<typeof getChallengeRouteData>>>;
// this is to data to populate the description tab (default tab on challenge page)
export const getChallengeRouteData = cache(async (slug: string, session: Session | null) => {
const featureFlags = await getAllFlags();
+ const isAotChallenge = AOT_CHALLENGES.includes(slug);
+
+ if (featureFlags.enableHolidayEvent && isAotChallenge) {
+ const [, day = '1'] = slug.split('-');
+ const daysPassed = daysAfterDecemberFirst();
+ if (parseInt(day) > daysPassed + 1) {
+ throw new Error('Not Available');
+ }
+ }
const challenge = await prisma.challenge.findFirstOrThrow({
where: {
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/page.tsx b/apps/web/src/app/[locale]/challenge/[slug]/page.tsx
index 87c03308..0600a221 100644
--- a/apps/web/src/app/[locale]/challenge/[slug]/page.tsx
+++ b/apps/web/src/app/[locale]/challenge/[slug]/page.tsx
@@ -1,13 +1,14 @@
import { auth, type Session } from '@repo/auth/server';
import { notFound, redirect } from 'next/navigation';
import { buildMetaForChallenge, buildMetaForEventPage } from '~/app/metadata';
+import { daysAfterDecemberFirst } from '~/utils/aot';
+import { getAllFlags } from '~/utils/feature-flags';
import { getRelativeTime } from '~/utils/relativeTime';
import { isBetaUser } from '~/utils/server/is-beta-user';
import { Comments } from '../_components/comments';
import { Description } from '../_components/description';
-import { getChallengeRouteData } from './getChallengeRouteData';
-import { getAllFlags } from '~/utils/feature-flags';
import { AOT_CHALLENGES } from './aot-slugs';
+import { getChallengeRouteData } from './getChallengeRouteData';
interface Props {
params: {
@@ -69,13 +70,3 @@ export default async function Challenges({ params: { slug } }: Props) {
export function isAuthor(session: Session | null, userId?: string | null) {
return userId && session?.user?.id && userId === session?.user?.id;
}
-
-export function daysAfterDecemberFirst() {
- const MS_PER_DAY = 24 * 60 * 60 * 1000;
- const startDate = new Date('2023-12-01T05:00:00.000Z').getTime();
- const today = Date.now();
-
- const daysPassed = Math.floor((today - startDate) / MS_PER_DAY);
-
- return daysPassed;
-}
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/save-submission.action.ts b/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/save-submission.action.ts
index 73ecd185..c316b9c6 100644
--- a/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/save-submission.action.ts
+++ b/apps/web/src/app/[locale]/challenge/[slug]/submissions/[[...catchAll]]/save-submission.action.ts
@@ -8,14 +8,34 @@ import {
createCompletedSubmissionCacheKey,
createInProgressSubmissionCacheKey,
} from './cache-keys';
+import { auth } from '@repo/auth/server';
+import { AOT_CHALLENGES } from '../../aot-slugs';
+import { getAllFlags } from '~/utils/feature-flags';
+import { daysAfterDecemberFirst } from '~/utils/aot';
interface Args {
challenge: ChallengeRouteData['challenge'];
- userId: string;
code: string;
isSuccessful: boolean;
}
-export async function saveSubmission({ challenge, userId, code, isSuccessful }: Args) {
+export async function saveSubmission({ challenge, code, isSuccessful }: Args) {
+ const session = await auth();
+ if (!session?.user) {
+ throw new Error('Not Authorized');
+ }
+
+ const featureFlags = await getAllFlags();
+ const isAotChallenge = AOT_CHALLENGES.includes(challenge.slug);
+
+ if (featureFlags.enableHolidayEvent && isAotChallenge) {
+ const [, day = '1'] = challenge.slug.split('-');
+ const daysPassed = daysAfterDecemberFirst();
+ if (parseInt(day) > daysPassed + 1) {
+ throw new Error('Not Available');
+ }
+ }
+ const userId = session.user.id;
+
const submission = await prisma.submission.create({
data: {
challengeId: challenge.id,
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/wrapper.tsx b/apps/web/src/app/[locale]/challenge/[slug]/wrapper.tsx
index 088b0aa7..0ad1a780 100644
--- a/apps/web/src/app/[locale]/challenge/[slug]/wrapper.tsx
+++ b/apps/web/src/app/[locale]/challenge/[slug]/wrapper.tsx
@@ -48,7 +48,6 @@ export function Wrapper({ track, challenge }: Props) {
const submission = await saveSubmission({
challenge,
- userId: session?.user.id!,
code,
isSuccessful,
});
diff --git a/apps/web/src/utils/aot.ts b/apps/web/src/utils/aot.ts
new file mode 100644
index 00000000..5813b70a
--- /dev/null
+++ b/apps/web/src/utils/aot.ts
@@ -0,0 +1,9 @@
+export function daysAfterDecemberFirst() {
+ const MS_PER_DAY = 24 * 60 * 60 * 1000;
+ const startDate = new Date('2023-12-01T05:00:00.000Z').getTime();
+ const today = Date.now();
+
+ const daysPassed = Math.floor((today - startDate) / MS_PER_DAY);
+
+ return daysPassed;
+}