Skip to content

Commit

Permalink
feat: support infinite quota in UI (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelSiidorow authored Oct 30, 2024
1 parent f8228c0 commit 13fee16
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 23 deletions.
33 changes: 21 additions & 12 deletions apps/web/src/app/[locale]/events/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,27 @@ async function SignUpQuotas({ event }: { event: IlmomasiinaEvent }) {
) : (
<>
<span>{quota.title}</span>
<div className="relative">
<Progress
value={Math.min(
((quota.signupCount ?? 0) / quota.size) * 100,
100,
)}
/>
<span className="absolute bottom-1/2 left-0 w-full translate-y-1/2 text-center text-sm">
{Math.min(quota.signupCount ?? 0, quota.size)} /{" "}
{quota.size}
</span>
</div>
{typeof quota.size === "number" ? (
<div className="relative">
<Progress
value={Math.min(
((quota.signupCount ?? 0) / quota.size) * 100,
100,
)}
/>
<span className="absolute bottom-1/2 left-0 w-full translate-y-1/2 text-center text-sm">
{Math.min(quota.signupCount ?? 0, quota.size)} /{" "}
{quota.size}
</span>
</div>
) : (
<div className="relative">
<Progress value={100} />
<span className="absolute bottom-1/2 left-0 w-full translate-y-1/2 text-center text-sm">
{quota.signupCount}
</span>
</div>
)}
</>
)}
</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-nested-ternary -- I like */
import { notFound } from "next/navigation";
import { getSignup } from "../../../../../lib/api/external/ilmomasiina";
import { openGraphImage } from "../../../../shared-metadata";
Expand Down Expand Up @@ -64,14 +65,19 @@ export default async function Page({
? t("You are in queue at position {position}", {
position: signupInfo.data.signup.position,
})
: t(
"You are in the quota {quotaName} at position {position}/{quotaSize}",
{
: typeof signupInfo.data.signup.quota.size === "number"
? t(
"You are in the quota {quotaName} at position {position}/{quotaSize}",
{
quotaName: signupInfo.data.signup.quota.title,
position: signupInfo.data.signup.position,
quotaSize: signupInfo.data.signup.quota.size,
},
)
: t("You are in the quota {quotaName} at position {position}", {
quotaName: signupInfo.data.signup.quota.title,
position: signupInfo.data.signup.position,
quotaSize: signupInfo.data.signup.quota.size,
},
)}
})}
</p>
</hgroup>
<SignupForm
Expand Down
12 changes: 8 additions & 4 deletions apps/web/src/custom-pages/events-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async function SignupQuotas({
(acc, quota) => acc + (quota.signupCount ?? 0),
0,
);
const totalSize = quotas.reduce((acc, quota) => acc + quota.size, 0);
const totalSize = quotas.reduce((acc, quota) => acc + (quota.size ?? 0), 0);

const isSingleQuota = quotas.length === 1;

Expand Down Expand Up @@ -107,9 +107,13 @@ async function SignupQuotas({
key={quota.id}
>
<span className="w-3/4 truncate">{quota.title}</span>{" "}
<span className="w-1/4 text-left">
{quota.signupCount} / {quota.size}
</span>
{typeof quota.size === "number" ? (
<span className="w-1/4 text-left">
{quota.signupCount} / {quota.size}
</span>
) : (
<span className="w-1/4 text-left">{quota.signupCount}</span>
)}
</li>
))}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/lib/api/external/ilmomasiina/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface EventQuestion {
export interface EventQuota {
id: string;
title: string;
size: number;
size?: number | null;
signupCount?: number;
signups?: QuotaSignup[] | null;
}
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const en = {
"invoicegenerator.Invoicer information": "Invoicer information",
"ilmomasiina.form.You are in queue at position {position}":
"You are in queue at position {position}.",
"ilmomasiina.form.You are in the quota {quotaName} at position {position}":
"You are in the quota {quotaName} at position {position}.",
"ilmomasiina.form.You are in the quota {quotaName} at position {position}/{quotaSize}":
"You are in the quota {quotaName} at position {position}/{quotaSize}.",
"ilmomasiina.form.fieldError.missing": "This field is required.",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/locales/fi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const fi = {
"invoicegenerator.Invoicer information": "Laskuttajan tiedot",
"ilmomasiina.form.You are in queue at position {position}":
"Olet jonossa sijalla {position}.",
"ilmomasiina.form.You are in the quota {quotaName} at position {position}":
"Olet kiintiössä {quotaName} sijalla {position}.",
"ilmomasiina.form.You are in the quota {quotaName} at position {position}/{quotaSize}":
"Olet kiintiössä {quotaName} sijalla {position}/{quotaSize}.",
"ilmomasiina.form.fieldError.missing": "Tämä kenttä on pakollinen.",
Expand Down

0 comments on commit 13fee16

Please sign in to comment.