add more ux and ui patches with extra login helper
This commit is contained in:
@@ -68,8 +68,12 @@ async function createRecord(collection: string, data: any): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// Seed two default seasons (Holidays, Term time) per family so the family-admin
|
||||
// season picker always has options. Idempotent by name.
|
||||
// Seed a default season (Holidays) per family so the family-admin season
|
||||
// picker always has at least one option. "Term time" is intentionally NOT
|
||||
// auto-seeded — it's a UK-school-specific term that not every family wants,
|
||||
// and force-seeding it meant a deleted "Term time" kept coming back on every
|
||||
// boot. Families that want it can add it themselves.
|
||||
// Only seeds when a family has zero seasons, so user deletions stick.
|
||||
async function ensureDefaultSeasons(): Promise<void> {
|
||||
const famsCol = await getCollection("fams");
|
||||
if (!famsCol) return;
|
||||
@@ -78,18 +82,19 @@ async function ensureDefaultSeasons(): Promise<void> {
|
||||
headers: { Authorization: `Bearer ${t}` },
|
||||
});
|
||||
const fams = (await famsRes.json()).items || [];
|
||||
const defaults = [
|
||||
{ name: "Holidays", color: "#f59e0b", active: true },
|
||||
{ name: "Term time", color: "#3b82f6", active: true },
|
||||
];
|
||||
const defaults = [{ name: "Holidays", color: "#f59e0b", active: true }];
|
||||
for (const fam of fams) {
|
||||
const sRes = await fetch(
|
||||
`${PB_ENDPOINT}/api/collections/seasons/records?filter=(famId='${fam.id}')&fields=name&perPage=200`,
|
||||
{ headers: { Authorization: `Bearer ${t}` } }
|
||||
);
|
||||
const have = new Set(((await sRes.json()).items || []).map((s: any) => s.name));
|
||||
for (const d of defaults) {
|
||||
if (!have.has(d.name)) {
|
||||
const have = ((await sRes.json()).items || []) as any[];
|
||||
// Only seed defaults for families that have no seasons at all. Seeding
|
||||
// per-name (idempotent) forced a deleted default (e.g. "Term time") back
|
||||
// on every boot; now a user who removes one keeps it removed as long as
|
||||
// at least one season remains.
|
||||
if (have.length === 0) {
|
||||
for (const d of defaults) {
|
||||
await createRecord("seasons", { famId: fam.id, ...d });
|
||||
console.log(` ✓ Seeded season ${d.name} for fam ${fam.id}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user