Skip to content

Commit 1006f74

Browse files
anees-asgharnalves599
authored andcommitted
Implement spin the wheel section/page
1 parent 4edaebd commit 1006f74

File tree

26 files changed

+243
-54
lines changed

26 files changed

+243
-54
lines changed

.env.local

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
EVENT_EDITION = mock-edition-id
2+
13
WEBAPP_URL = http://localhost:3000
24

35
CANNON_URL = https://cannon-staging-dev.sinfo.org

src/app/(authenticated)/companies/[id]/connections/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import BlankPageWithMessage from "@/components/BlankPageMessage";
12
import List from "@/components/List";
23
import { UserTile } from "@/components/user/UserTile";
34
import { CompanyService } from "@/services/CompanyService";
@@ -16,7 +17,7 @@ export default async function CompanyConnections({
1617
const connections = await CompanyService.getConnections(companyID);
1718

1819
if (!connections) {
19-
return <div>Company connections not found</div>;
20+
return <BlankPageWithMessage message="Company connections not found!" />;
2021
}
2122

2223
return (

src/app/(authenticated)/companies/[id]/page.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import EventDayButton from "@/components/EventDayButton";
1414
import { Scan } from "lucide-react";
1515
import Link from "next/link";
1616
import { SocialNetwork } from "@/components/SocialNetwork";
17+
import BlankPageWithMessage from "@/components/BlankPageMessage";
1718

1819
interface CompanyParams {
1920
id: string;
@@ -27,17 +28,17 @@ export default async function Company({ params }: { params: CompanyParams }) {
2728
const company = await CompanyService.getCompany(companyID);
2829

2930
if (!company) {
30-
return <div>Company not found</div>;
31+
return <BlankPageWithMessage message="Company not found!" />;
3132
}
3233

3334
const companySessions = company.sessions?.sort((a, b) =>
34-
a.date.localeCompare(b.date),
35+
a.date.localeCompare(b.date)
3536
);
3637
const companyMembers = company.members?.sort((a, b) =>
37-
a.name.localeCompare(b.name),
38+
a.name.localeCompare(b.name)
3839
);
3940
const companyStands = company.stands?.sort((a, b) =>
40-
a.date.localeCompare(b.date),
41+
a.date.localeCompare(b.date)
4142
);
4243
const hereToday = isHereToday(company);
4344

src/app/(authenticated)/companies/[id]/promote/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import authOptions from "@/app/api/auth/[...nextauth]/authOptions";
22
import { CompanyService } from "@/services/CompanyService";
33
import { getServerSession } from "next-auth";
44
import CompanyPromoteScanner from "./CompanyPromoteScanner";
5+
import BlankPageWithMessage from "@/components/BlankPageMessage";
56

67
interface CompanyPromoteParams {
78
id: string;
@@ -17,7 +18,7 @@ export default async function CompanyPromote({
1718
const company = await CompanyService.getCompany(companyID);
1819

1920
if (!company) {
20-
return <div>Company not found</div>;
21+
return <BlankPageWithMessage message="Company not found!" />;
2122
}
2223

2324
const session = await getServerSession(authOptions);

src/app/(authenticated)/companies/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { CompanyService } from "@/services/CompanyService";
22
import CompaniesList from "./CompaniesList";
3+
import BlankPageWithMessage from "@/components/BlankPageMessage";
34

45
export default async function Companies() {
56
let companies = await CompanyService.getCompanies();
67

78
if (!companies) {
8-
return <div>Failed to load companies</div>;
9+
return <BlankPageWithMessage message="No companies found!" />;
910
}
1011

1112
// Sort companies by name

src/app/(authenticated)/home/page.tsx

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,72 @@ import { SessionTile } from "@/components/session";
77
import ListCard from "@/components/ListCard";
88
import List from "@/components/List";
99
import GridList from "@/components/GridList";
10+
import ProgressBar from "@/components/ProgressBar";
11+
import Link from "next/link";
12+
import { getServerSession } from "next-auth";
13+
import authOptions from "@/app/api/auth/[...nextauth]/authOptions";
14+
import { UserService } from "@/services/UserService";
15+
import { isCompany, isToday } from "@/utils/utils";
16+
import UserSignOut from "@/components/UserSignOut";
1017

1118
const N_SESSION_TILES = 3;
1219
const N_COMPANY_TILES = 6;
1320
const N_SPEAKER_TILES = 6;
21+
const SPIN_WHEEL_MAXIMUM = 10;
1422

1523
export default async function Home() {
24+
const session = (await getServerSession(authOptions))!;
25+
const user = await UserService.getMe(session.cannonToken);
26+
if (!user) return <UserSignOut />;
27+
1628
const eventSessions = await SessionService.getSessions();
1729
const companies = await CompanyService.getCompanies();
1830
const speakers = await SpeakerService.getSpeakers();
1931

2032
// choose upcoming sessions
21-
let upcomingSessions: SINFOSession[] = eventSessions
33+
const upcomingSessions: SINFOSession[] = eventSessions
2234
? eventSessions
2335
.filter((s) => new Date(s.date) >= new Date())
2436
.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime())
2537
.slice(0, N_SESSION_TILES)
2638
: [];
2739

2840
// choose random companies
29-
let highlightedCompanies: Company[] = companies
41+
const highlightedCompanies: Company[] = companies
3042
? companies.sort(() => Math.random() - 0.5).slice(0, N_COMPANY_TILES)
3143
: [];
3244

3345
// choose random speakers
34-
let highlightedSpeakers: Speaker[] = speakers
46+
const highlightedSpeakers: Speaker[] = speakers
3547
? speakers.sort(() => Math.random() - 0.5).slice(0, N_SPEAKER_TILES)
3648
: [];
3749

50+
const spinWheelData = user.signatures?.find(
51+
(s) => s.edition === process.env.EVENT_EDITION && isToday(s.day)
52+
);
53+
const showSpinWheelSection =
54+
!isCompany(user.role) && !spinWheelData?.redeemed;
55+
3856
return (
3957
<div className="container mx-auto">
58+
{/* Spin the Wheel Section */}
59+
{showSpinWheelSection && (
60+
<ProgressBar
61+
current={spinWheelData?.signatures.length ?? 0}
62+
maximum={SPIN_WHEEL_MAXIMUM}
63+
title="Companies Visited Today"
64+
className="pb-2"
65+
>
66+
<div className="text-xs text-gray-600">
67+
Visit {SPIN_WHEEL_MAXIMUM} companies for a chance to spin the wheel
68+
and win exciting prizes!&nbsp;
69+
<Link href={"/spin"} className="text-link">
70+
See more
71+
</Link>
72+
</div>
73+
</ProgressBar>
74+
)}
75+
4076
{/* Upcoming Sessions */}
4177
<List title="Next Up" link="/schedule?day=today" linkText="See all">
4278
{upcomingSessions.length > 0 ? (
@@ -45,6 +81,7 @@ export default async function Home() {
4581
<ListCard title="Nothing to show" />
4682
)}
4783
</List>
84+
4885
{/* Highlighted Companies */}
4986
<GridList
5087
title="Companies"
@@ -60,6 +97,7 @@ export default async function Home() {
6097
<ListCard title="Nothing to show" />
6198
)}
6299
</GridList>
100+
63101
{/* Highlighted Speakers */}
64102
<GridList title="Speakers" link="/speakers" linkText="See all" scrollable>
65103
{highlightedSpeakers.length > 0 ? (
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1+
import BlankPageWithMessage from "@/components/BlankPageMessage";
2+
13
export default function Loading() {
2-
return (
3-
<div className="h-full flex items-center justify-center text-gray-800">
4-
Loading...
5-
</div>
6-
);
4+
<BlankPageWithMessage message="Spinning up some magic..." />;
75
}

src/app/(authenticated)/prizes/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import { getServerSession } from "next-auth";
1010
import PrizeSessions from "./PrizeSessions";
1111
import MessageCard from "@/components/MessageCard";
1212
import DailyPrizesTable from "./DailyPrizesTable";
13+
import BlankPageWithMessage from "@/components/BlankPageMessage";
1314

1415
export default async function Prizes() {
1516
const prizes = await PrizeService.getPrizes();
1617

1718
if (!prizes) {
18-
return <div>Prizes not found.</div>;
19+
return <BlankPageWithMessage message="Prizes not found!" />;
1920
}
2021

2122
const session = await getServerSession(authOptions);
@@ -84,7 +85,7 @@ export default async function Prizes() {
8485
<PrizeTile prize={sessionPrize} />
8586
<PrizeSessions
8687
sessions={sinfoSessions.filter((s) =>
87-
sessionPrize.sessions?.includes(s.id),
88+
sessionPrize.sessions?.includes(s.id)
8889
)}
8990
/>
9091
</div>

src/app/(authenticated)/profile/achievements/page.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import authOptions from "@/app/api/auth/[...nextauth]/authOptions";
2+
import BlankPageWithMessage from "@/components/BlankPageMessage";
23
import GridList from "@/components/GridList";
34
import AchievementTile from "@/components/user/AchievementTile";
45
import { AchievementService } from "@/services/AchievementService";
56
import { UserService } from "@/services/UserService";
6-
import { humanizeAchivementKind } from "@/utils/utils";
7+
import { formatAchievementKind } from "@/utils/utils";
78
import { getServerSession } from "next-auth";
89

910
export default async function Achievements() {
1011
const achievements = await AchievementService.getAchievements();
1112

1213
if (!achievements) {
13-
return <div>Achievements not found.</div>;
14+
return <BlankPageWithMessage message="No achievements found." />;
1415
}
1516

1617
const session = await getServerSession(authOptions);
@@ -40,7 +41,7 @@ export default async function Achievements() {
4041
</span>
4142
</div>
4243
{sortedKinds.map((k) => (
43-
<GridList key={k} title={humanizeAchivementKind(k)}>
44+
<GridList key={k} title={formatAchievementKind(k)}>
4445
{achievementsByKind[k].slice(0, 30).map((a) => (
4546
<AchievementTile
4647
key={a.id}

src/app/(authenticated)/profile/edit/page.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import { UserService } from "@/services/UserService";
33
import { getServerSession } from "next-auth";
44
import EditProfileForm from "./EditProfileForm";
55
import { redirect } from "next/navigation";
6+
import UserSignOut from "@/components/UserSignOut";
67

78
export default async function EditProfile() {
89
const session = (await getServerSession(authOptions))!;
9-
const user: User | null = await UserService.getMe(session.cannonToken);
10-
11-
if (!user) {
12-
return <div>Profile not found</div>;
13-
}
10+
const user = await UserService.getMe(session.cannonToken);
11+
if (!user) return <UserSignOut />;
1412

1513
async function updateUser(newUser: User) {
1614
"use server";

0 commit comments

Comments
 (0)