Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sats Chain 👋 #112

Merged
merged 4 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const nextConfig = withPWA({
protocol: "https",
hostname: "storage.googleapis.com",
},
{
protocol: "https",
hostname: "images.ctfassets.net",
},
],
},
});
Expand Down
15 changes: 5 additions & 10 deletions src/components/modals/BookingPopupModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import DialogContent from "@mui/material/DialogContent";
import DialogContentText from "@mui/material/DialogContentText";
import React, { useState } from "react";

import { hasWaitingList } from "@/lib/helpers/popularity";
import { useUserSessions } from "@/lib/hooks/useUserSessions";
import { useUserSessionsIndex } from "@/lib/hooks/useUserSessionsIndex";
import { BookingPopupAction, ChainIdentifier, RezervoClass } from "@/types/chain";
Expand Down Expand Up @@ -67,7 +68,7 @@ const BookingPopupModal = ({
) : (
<>
Booking for <b>{classDescription}</b> har allerede åpnet. Vil du{" "}
{_class.availableSlots > 0 ? "booke timen nå" : "sette deg på venteliste"}?
{hasWaitingList(_class) ? "sette deg på venteliste" : "booke timen nå"}?
</>
)}
</Typography>
Expand All @@ -78,19 +79,13 @@ const BookingPopupModal = ({
Nei takk
</Button>
<LoadingButton
startIcon={
isCancellation ? <Clear /> : _class.availableSlots > 0 ? <Add /> : <HourglassTop />
}
color={isCancellation ? "error" : _class.availableSlots > 0 ? "primary" : "warning"}
startIcon={isCancellation ? <Clear /> : hasWaitingList(_class) ? <HourglassTop /> : <Add />}
color={isCancellation ? "error" : hasWaitingList(_class) ? "warning" : "primary"}
variant={"outlined"}
onClick={isCancellation ? cancelBooking : book}
loading={bookingLoading}
>
{isCancellation
? "Avbestill"
: _class.availableSlots > 0
? "Book nå"
: "Sett på venteliste"}
{isCancellation ? "Avbestill" : hasWaitingList(_class) ? "Sett på venteliste" : "Book nå"}
</LoadingButton>
</DialogActions>
</>
Expand Down
12 changes: 6 additions & 6 deletions src/components/modals/ClassInfo/ClassInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import ConfirmCancellation from "@/components/schedule/class/ConfirmCancellation
import { NoShowBadgeIcon } from "@/components/utils/NoShowBadgeIcon";
import { PlannedNotBookedBadgeIcon } from "@/components/utils/PlannedNotBookedBadgeIcon";
import { isClassInThePast } from "@/lib/helpers/date";
import { stringifyClassPopularity } from "@/lib/helpers/popularity";
import { hasWaitingList, stringifyClassPopularity } from "@/lib/helpers/popularity";
import { classConfigRecurrentId, classRecurrentId } from "@/lib/helpers/recurrentId";
import { useUserConfig } from "@/lib/hooks/useUserConfig";
import { useUserSessions } from "@/lib/hooks/useUserSessions";
Expand Down Expand Up @@ -206,7 +206,7 @@ export default function ClassInfo({
</Typography>
</Box>
)}
{((!_class.isBookable && !isInThePast) || _class.isCancelled) && (
{_class.totalSlots !== null && ((!_class.isBookable && !isInThePast) || _class.isCancelled) && (
<Box
sx={{
display: "flex",
Expand All @@ -222,7 +222,7 @@ export default function ClassInfo({
</Typography>
</Box>
)}
{!_class.isCancelled && (
{!_class.isCancelled && _class.totalSlots !== null && _class.availableSlots !== null && (
<Box
sx={{
display: "flex",
Expand Down Expand Up @@ -346,15 +346,15 @@ export default function ClassInfo({
) : (
!_class.isCancelled && (
<LoadingButton
startIcon={_class.availableSlots > 0 ? <Add /> : <HourglassTop />}
color={_class.availableSlots > 0 ? "primary" : "warning"}
startIcon={hasWaitingList(_class) ? <HourglassTop /> : <Add />}
color={hasWaitingList(_class) ? "warning" : "primary"}
sx={{ mt: 2, mr: 1 }}
variant={"outlined"}
disabled={isInThePast || !_class.isBookable}
onClick={() => book()}
loading={bookingLoading}
>
{_class.availableSlots > 0 ? "Book nå" : "Sett meg på venteliste"}
{hasWaitingList(_class) ? "Sett meg på venteliste" : "Book nå"}
</LoadingButton>
)
)}
Expand Down
5 changes: 4 additions & 1 deletion src/components/schedule/class/ClassCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ const ClassCard = ({
</Badge>
</Tooltip>
) : (
<ClassPopularityMeter _class={_class} historicPopularity={popularity} />
(_class.totalSlots !== null || (_class.isBookable && _class.waitingListCount !== null)) && (
<ClassPopularityMeter _class={_class} historicPopularity={popularity} />
)
)}
{showScheduleAction && (
<Tooltip
Expand All @@ -246,6 +248,7 @@ const ClassCard = ({
}}
size={"small"}
sx={{
marginTop: "auto",
padding: 0,
height: 28, // to avoid jumping when avatars are displayed
}}
Expand Down
8 changes: 5 additions & 3 deletions src/components/schedule/class/ClassPopularityMeter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React from "react";

import RippleBadge from "@/components/utils/RippleBadge";
import { isClassInThePast } from "@/lib/helpers/date";
import { determineClassPopularity, stringifyClassPopularity } from "@/lib/helpers/popularity";
import { determineClassPopularity, hasWaitingList, stringifyClassPopularity } from "@/lib/helpers/popularity";
import { RezervoClass } from "@/types/chain";
import { ClassPopularity } from "@/types/popularity";
import { StatusColors } from "@/types/userSessions";
Expand Down Expand Up @@ -38,7 +38,9 @@ const ClassPopularityMeter = ({
if (_class.isBookable) {
return (
<Tooltip
title={"Påmelding for denne timen har åpnet. " + stringifyClassPopularity(_class, historicPopularity)}
title={
"Påmelding for denne timen har åpnet. " + stringifyClassPopularity(_class, historicPopularity) ?? ""
}
>
<RippleBadge
invisible={isClassInThePast(_class)}
Expand All @@ -48,7 +50,7 @@ const ClassPopularityMeter = ({
horizontal: "right",
}}
variant={"dot"}
rippleColor={_class.availableSlots > 0 ? StatusColors.ACTIVE : StatusColors.WAITLIST}
rippleColor={hasWaitingList(_class) ? StatusColors.WAITLIST : StatusColors.ACTIVE}
>
{popularityIcon}
</RippleBadge>
Expand Down
19 changes: 17 additions & 2 deletions src/lib/helpers/popularity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import { RezervoClass, RezervoWeekSchedule } from "@/types/chain";
import { ClassPopularity, ClassPopularityIndex } from "@/types/popularity";

export function determineClassPopularity(_class: RezervoClass) {
if (!_class || _class.availableSlots === undefined) return ClassPopularity.Unknown;
if (!_class || _class.availableSlots === null || _class.totalSlots === null) {
if (_class.waitingListCount != null) {
if (_class.waitingListCount == 0) {
return ClassPopularity.Low;
}
return ClassPopularity.High;
}
return ClassPopularity.Unknown;
}
if (_class.availableSlots <= 0) return ClassPopularity.High;
if (_class.availableSlots / _class.totalSlots <= 0.2) return ClassPopularity.Medium;
return ClassPopularity.Low;
Expand All @@ -23,9 +31,12 @@ export function createClassPopularityIndex(previousWeekSchedule: RezervoWeekSche
);
}

export function stringifyClassPopularity(_class: RezervoClass, historicPopularity: ClassPopularity): string {
export function stringifyClassPopularity(_class: RezervoClass, historicPopularity: ClassPopularity): string | null {
let classPopularityInfo: string;
const isInThePast = isClassInThePast(_class);
if (_class.availableSlots === null || _class.totalSlots === null) {
return null;
}
const numberOfAttendees = _class.totalSlots - Math.max(_class.availableSlots, 0);

if (isInThePast) {
Expand All @@ -41,3 +52,7 @@ export function stringifyClassPopularity(_class: RezervoClass, historicPopularit
}
return classPopularityInfo;
}

export function hasWaitingList(_class: RezervoClass): boolean {
return _class.availableSlots === null ? (_class?.waitingListCount ?? 0) > 0 : _class.availableSlots <= 0;
}
6 changes: 3 additions & 3 deletions src/types/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export type RezervoClassBase = {
location: {
id: string;
studio: string;
room: string;
room: string | null;
};
isBookable: boolean;
isCancelled: boolean;
cancelText: string | null;
totalSlots: number;
availableSlots: number;
totalSlots: number | null;
availableSlots: number | null;
waitingListCount: number | null;
activity: RezervoActivity;
instructors: RezervoInstructor[];
Expand Down
Loading