Skip to content

Commit 1152826

Browse files
committed
Add download CVs
1 parent af9303e commit 1152826

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

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

+42-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ import Link from "next/link";
1212
import { getServerSession } from "next-auth";
1313
import authOptions from "@/app/api/auth/[...nextauth]/authOptions";
1414
import { UserService } from "@/services/UserService";
15-
import { getUserActiveSignatureData, isAttendee } from "@/utils/utils";
15+
import {
16+
getUserActiveSignatureData,
17+
isAttendee,
18+
isCompany,
19+
} from "@/utils/utils";
1620
import UserSignOut from "@/components/UserSignOut";
1721
import { SPIN_WHEEL_MAXIMUM } from "@/constants";
1822
import { EventService } from "@/services/EventService";
23+
import { FileUser, Users } from "lucide-react";
1924

2025
const N_SESSION_TILES = 3;
2126
const N_COMPANY_TILES = 15;
@@ -58,14 +63,22 @@ export default async function Home() {
5863

5964
let standDates = new Set(
6065
companies?.flatMap(
61-
(c) => c.stands?.flatMap((cs) => cs.date.slice(0, 10)) ?? []
62-
) ?? []
66+
(c) => c.stands?.flatMap((cs) => cs.date.slice(0, 10)) ?? [],
67+
) ?? [],
6368
);
6469
let today = new Date().toISOString().split("T")[0];
6570
const spinWheelData = getUserActiveSignatureData(user, event?.id ?? ``);
6671
const showSpinWheelSection =
6772
standDates.has(today) && isAttendee(user.role) && !spinWheelData?.redeemed;
6873

74+
const downloadCVsLinks =
75+
isCompany(user.role) &&
76+
!!user.company?.length &&
77+
(await CompanyService.getDownloadLinks(
78+
session.cannonToken,
79+
user.company[0].company,
80+
));
81+
6982
return (
7083
<div className="container mx-auto">
7184
{/* Spin the Wheel Section */}
@@ -89,6 +102,32 @@ export default async function Home() {
89102
</ProgressBar>
90103
)}
91104

105+
{/* Download CVs section */}
106+
{downloadCVsLinks && (
107+
<List title="Download CVs">
108+
{downloadCVsLinks.all && (
109+
<Link
110+
className="button-primary text-sm"
111+
href={downloadCVsLinks.all}
112+
download
113+
>
114+
<FileUser size={16} />
115+
Download all
116+
</Link>
117+
)}
118+
{downloadCVsLinks.all && (
119+
<Link
120+
className="button-tertiary text-sm"
121+
href={downloadCVsLinks.all}
122+
download
123+
>
124+
<Users size={16} />
125+
Download company connections
126+
</Link>
127+
)}
128+
</List>
129+
)}
130+
92131
{/* Upcoming Sessions */}
93132
<List
94133
title={upcomingSessions.length > 0 ? "Next Up" : "Sessions"}

src/services/CompanyService.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,25 @@ export const CompanyService = (() => {
6060
return null;
6161
};
6262

63-
return { getCompany, getCompanies, getConnections, sign };
63+
const getDownloadLinks = async (
64+
cannonToken: string,
65+
id: string,
66+
): Promise<DownloadLinks | null> => {
67+
try {
68+
const resp = await fetch(`${companiesEndpoint}/${id}/url`, {
69+
headers: {
70+
Authorization: `Bearer ${cannonToken}`,
71+
},
72+
next: {
73+
revalidate: 0, // 1 day
74+
},
75+
});
76+
if (resp.ok) return (await resp.json()) as DownloadLinks;
77+
} catch (e) {
78+
console.error(e);
79+
}
80+
return null;
81+
};
82+
83+
return { getCompany, getCompanies, getConnections, sign, getDownloadLinks };
6484
})();

src/types/globals.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ type Achievement = {
9191
updated?: string;
9292
};
9393

94+
type DownloadLinks = {
95+
all?: string;
96+
companyConnections?: string;
97+
};
98+
9499
type SINFOSignature = {
95100
companyId: string;
96101
date: string;

0 commit comments

Comments
 (0)