Back
Version 31
7/9/2024
/** @jsxImportSource npm:react **/
import { renderToString } from "npm:react-dom@18/server";
import { addDays } from "npm:date-fns";
import moment from "npm:moment";
export default async function(req: Request): Promise<Response> {
// ============= Data Fetching =================
const today = new Date();
const tomorrow = addDays(today, 1);
const data = await fetch(
`https://api.stage.teamsurfboard.com/api/v1/schedule?start=${today.toISOString()}&end=${tomorrow.toISOString()}`,
{
headers: {
"Authorization": `Bearer ${Deno.env.get("TEAMSURFBOARD_API_TOKEN")}`,
},
},
)
.then((res) => res.json())
.then((data) => data);
// ============= React Components =================
const Schedule = ({ data }) => {
const groupedSchedules = groupSchedulesByDate(data.data);
return (
<div style={styles.container}>
{Object.entries(groupedSchedules).map(([date, schedules]) => (
<div key={date} style={styles.dateGroup}>
<h2 style={styles.dateHeader}>{moment(date).format("MMMM D, YYYY")}</h2>
<div style={styles.scheduleGrid}>
{schedules.map((schedule, index) => <ScheduleItem key={index} schedule={schedule} />)}
</div>
</div>
))}
</div>
keenanzucker-stagingdailyschedule.web.val.run
Updated: August 29, 2024