Open-source event management and ticket selling platform β perfect for concerts, conferences, and everything in between ποΈ If you find this project helpful, please consider giving us a star βοΈ
PHP attendize-alternativedoor-managementevent-check-inevent-managementevent-registrationevent-ticketingeventbrite-alternativeeventslaravelopen-sourcephpreactself-hostedsell-ticketssell-tickets-onlineticket-sellingticketing-systemtickettailor-alternativetito-alternative
import {t} from "@lingui/macro";
import {Product} from "../../../types.ts";
import {formatLocalDateTime} from "./ledgerSummaries.ts";
export type VisibilityLevel = 'visible' | 'conditional' | 'hidden';
export interface VisibilityStatus {
level: VisibilityLevel;
message: string;
}
const hasValue = (value: unknown): boolean => value !== undefined && value !== null && value !== '';
export const computeVisibilityStatus = (values: Product, nowInEventTz: string): VisibilityStatus => {
if (values.is_hidden) {
return {
level: 'hidden',
message: t`Hidden from everyone β the master hide switch is on.`,
};
}
if (values.is_addon_only) {
return {
level: 'conditional',
message: t`Only shown as an add-on to the products it's attached to.`,
};
}
if (values.is_hidden_without_promo_code) {
return {
level: 'conditional',
message: t`Only visible to buyers with an applicable promo code.`,
};
}
if (values.hide_before_sale_start_date && hasValue(values.sale_start_date) && String(values.sale_start_date) > nowInEventTz) {
const start = formatLocalDateTime(values.sale_start_date as string);
return {
level: 'conditional',
message: t`Visible from ${start} β hidden until sales open.`,
};
}
if (values.hide_after_sale_end_date && hasValue(values.sale_end_date) && String(values.sale_end_date) < nowInEventTz) {
const end = formatLocalDateTime(values.sale_end_date as string);
return {
level: 'conditional',
message: t`Hidden β sales ended ${end}.`,
};
}
return {
level: 'visible',
message: t`Visible to everyone on the event page.`,
};
};