Skip to content

Commit

Permalink
use showcase api data to determine showcase active status
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbarnum4 committed May 1, 2024
1 parent 2058b8f commit 1998403
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
20 changes: 20 additions & 0 deletions data/types/gradShowcase.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,23 @@ export interface IGradShowcase {
eventbriteUrl: string;
isActive: boolean;
}

export type Showcase = {
id: string;
cohortName: string;
startDateTime: Date;
timezone: string;
/** Minutes before event start time */
doorsOffset: number;
/** Minutes after start to disable registration/zoom */
disableOffset: number; // TODO
zoomUrl: string;
teams: Record<string, unknown>[];
promoBanner?: { url: string };
active: boolean;
signups: string[];
ticketCount: number;
websiteActive?: boolean;
createdAt?: Date;
updatedAt?: Date;
};
45 changes: 34 additions & 11 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@ import { useState } from 'react';
import { IHome } from '../data/types/home';
import { getStaticAsset } from './api/static/[asset]';

import Main from '@this/components/layout/Main';
import {
TopCard,
AlumSpotlight,
ProgramsForAll,
IgniteCareer,
GreatCompanies,
IgniteCareer,
ProgramsForAll,
TeamEffort,
TopCard,
} from '@this/components/Home';
import Main from '@this/components/layout/Main';

import Carousel from '@this/components/Elements/Carousel';
import { Showcase } from '@this/data/types/gradShowcase';
import { ILogo } from '@this/data/types/logos';
import AtlantaPromo from '@this/src/components/Elements/AtlantaPromo';
import PromoVideo from '@this/src/components/Home/PromoVideo';
import ShowcasePromo from '@this/src/components/Home/ShowcasePromo';
import { IGradShowcase } from '@this/data/types/gradShowcase';
import { parseShowcaseTime } from '@this/src/helpers/timeUtils';
import { toDayJs } from '@this/src/helpers/time';
import axios from 'axios';

// const gCloudBaseUrl = 'https://storage.googleapis.com/operationspark-org';

interface HomeProps extends IHome {
logos: ILogo[];
showcase?: IGradShowcase | null;
showcase?: Showcase | null;
}

const Home: NextPage<HomeProps> = ({
Expand All @@ -37,7 +38,7 @@ const Home: NextPage<HomeProps> = ({
teamEffort,
showcase,
}) => {
const [showcaseInfo, setShowcaseInfo] = useState<IGradShowcase | null>(showcase || null);
const [showcaseInfo, setShowcaseInfo] = useState<Showcase | null>(showcase || null);

return (
<Main style={{ paddingTop: 0 }}>
Expand All @@ -59,14 +60,36 @@ const Home: NextPage<HomeProps> = ({
);
};

const getShowcase = async () => {
try {
const { data } = await axios.get<Showcase>(
'https://showcase.operationspark.org/api/showcases/active',
);

if (!data || !data.startDateTime || !data.websiteActive || !data.active) {
return null;
}

const disableTime = toDayJs(data.startDateTime).add(data.doorsOffset ?? 30, 'minutes');

if (disableTime.isBefore(toDayJs())) {
return null;
}

return data;
} catch {
console.info('Showcase inactive');
return null;
}
};

export const getStaticProps: GetStaticProps<HomeProps> = async () => {
const { greatCompanies, programsForAll, igniteCareer, teamEffort }: IHome = await getStaticAsset(
'index',
);
const logos: ILogo[] = await getStaticAsset('logos', 'partners');
const showcaseInfo: IGradShowcase = await getStaticAsset('gradShowcase');
const startDateTime = parseShowcaseTime(showcaseInfo.startDateTime);
const showcase = startDateTime ? { ...showcaseInfo, startDateTime: startDateTime } : null;

const showcase = await getShowcase();

return {
props: {
Expand Down
8 changes: 4 additions & 4 deletions src/components/Home/ShowcasePromo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { FC, useEffect, useState } from 'react';
import styled, { keyframes } from 'styled-components';

import Content from '@this/components/layout/Content';
import { Showcase } from '@this/data/types/gradShowcase';
import { toDayJs } from '@this/src/helpers/time';
import { circuitBoardBg } from '@this/src/theme/styled/mixins/circuitBoardBg';
import { IGradShowcase } from '@this/data/types/gradShowcase';
import { CountdownTimer } from '../Elements/Countdown';
import { toDayJs } from '@this/src/helpers/time';

type ShowcasePromoProps = {
info: IGradShowcase;
info: Showcase;
clearShowcase: () => void;
};

Expand Down Expand Up @@ -102,7 +102,7 @@ const ShowcasePromo: FC<ShowcasePromoProps> = ({ info, clearShowcase }) => {
className='showcase-website-button'
onClick={() =>
window.open(
'https://showcase.operationspark.org/Operation%20Spark%20Website',
'https://showcase.operationspark.org/share/Operation%20Spark%20Website',
'_blank',
)
}
Expand Down

0 comments on commit 1998403

Please sign in to comment.