Skip to content
Open
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
16 changes: 12 additions & 4 deletions src/utils/registerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ import { safeJsonParse } from "./safeJsonParse.js";
const STORAGE_KEY = "eventRegistrations";

const normalizeEmail = (email) => (email || "").trim().toLowerCase();
const getStorage = () => {
if (typeof window !== "undefined" && window.localStorage) {
return window.localStorage;
}
return globalThis.localStorage;
};

const readRegistrations = () => {
if (typeof window === "undefined") return {};
const storage = getStorage();
if (!storage) return {};
try {
const data = localStorage.getItem(STORAGE_KEY);
const data = storage.getItem(STORAGE_KEY);
const parsed = safeJsonParse(data, {});
// Migrate legacy array-based storage to Set-based storage
const migrated = {};
Expand All @@ -23,9 +30,10 @@ const readRegistrations = () => {
};

const writeRegistrations = (registrations) => {
if (typeof window === "undefined") return;
const storage = getStorage();
if (!storage) return;
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(registrations));
storage.setItem(STORAGE_KEY, JSON.stringify(registrations));
} catch {
// localStorage may be unavailable or full; keep the UI functional.
}
Expand Down
Loading