feat(events): unify registration checkout and receipts
This commit is contained in:
80
src/lib/registration-hub-display.ts
Normal file
80
src/lib/registration-hub-display.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { getEventRegistrationState, type EventAvailabilityInput } from "./event-ui.ts";
|
||||
import type { RegistrationHubState } from "./types.ts";
|
||||
|
||||
export type RegistrationHubGate =
|
||||
| "registration_ended"
|
||||
| "capacity_full"
|
||||
| "registration_not_started"
|
||||
| null;
|
||||
|
||||
export type RegistrationHubGateCopy = {
|
||||
status: string;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
};
|
||||
|
||||
export function getRegistrationHubGate(
|
||||
event: EventAvailabilityInput,
|
||||
now = Date.now(),
|
||||
): RegistrationHubGate {
|
||||
if (event.status !== "published") return "registration_ended";
|
||||
|
||||
const state = getEventRegistrationState(event, now).state;
|
||||
if (state === "closed" || state === "unavailable") return "registration_ended";
|
||||
if (state === "full") return "capacity_full";
|
||||
if (state === "not_started") return "registration_not_started";
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getRegistrationHubGateCopy(
|
||||
gate: RegistrationHubGate,
|
||||
): RegistrationHubGateCopy | null {
|
||||
if (gate === "registration_ended") {
|
||||
return {
|
||||
status: "پایان زمان ثبتنام",
|
||||
title: "پایان مهلت ثبتنام",
|
||||
subtitle: "",
|
||||
};
|
||||
}
|
||||
|
||||
if (gate === "capacity_full") {
|
||||
return {
|
||||
status: "تکمیل ظرفیت",
|
||||
title: "ظرفیت رویداد تکمیل شده",
|
||||
subtitle: "",
|
||||
};
|
||||
}
|
||||
|
||||
if (gate === "registration_not_started") {
|
||||
return {
|
||||
status: "ثبتنام هنوز آغاز نشده",
|
||||
title: "مهلت ثبتنام هنوز آغاز نشده است",
|
||||
subtitle: "",
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getRegistrationHubDisplayState(
|
||||
state: RegistrationHubState,
|
||||
): RegistrationHubState {
|
||||
return state === "legacy_pending" ? "verification_pending" : state;
|
||||
}
|
||||
|
||||
export function normalizeCouponAmounts(raw: {
|
||||
discount_amount?: number | null;
|
||||
final_price?: number | null;
|
||||
}) {
|
||||
return {
|
||||
discount_amount: (raw.discount_amount ?? 0) / 10,
|
||||
final_price: (raw.final_price ?? 0) / 10,
|
||||
};
|
||||
}
|
||||
|
||||
export function getFinalPriceToman(
|
||||
eventPriceInRials: number,
|
||||
couponFinalPriceInToman?: number | null,
|
||||
) {
|
||||
return couponFinalPriceInToman ?? Math.floor(eventPriceInRials / 10);
|
||||
}
|
||||
Reference in New Issue
Block a user