Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 13 additions & 21 deletions src/components/features/raffle/raffle-draw-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ import {
totalEntries,
} from "@/lib/raffle";
import { cn } from "@/lib/utils";
import { Gift, Loader2, RefreshCw, Stamp } from "lucide-react";
import { Gift, Loader2, RefreshCw } from "lucide-react";
import { useState } from "react";

interface RaffleDrawPanelProps {
hackathon: string;
prizes: RafflePrize[];
winners: RaffleWinner[];
entrants: RaffleEntrant[];
eligibleStampCount: number;
poolLoading: boolean;
/** the last pool load failed, so `entrants` is empty and drawing is blocked */
poolError: boolean;
poolFetchedAt: Date | null;
onRefreshPool: () => void;
onManageStamps: () => void;
className?: string;
}

Expand All @@ -36,11 +36,10 @@ export function RaffleDrawPanel({
prizes,
winners,
entrants,
eligibleStampCount,
poolLoading,
poolError,
poolFetchedAt,
onRefreshPool,
onManageStamps,
className,
}: RaffleDrawPanelProps) {
const [selectedPrizeId, setSelectedPrizeId] = useState<string>("");
Expand All @@ -60,12 +59,12 @@ export function RaffleDrawPanel({
const disabledReason =
prizes.length === 0
? "Add prizes before drawing"
: eligibleStampCount === 0
? "Choose which stamps count as entries"
: poolLoading
? "Loading the entry pool..."
: poolLoading
? "Loading the entry pool..."
: poolError
? "Couldn't load the entry pool, refresh to try again"
: poolEntries === 0
? "No entries yet, nobody has collected an eligible stamp"
? "No entries yet, nobody has earned any points"
: !selectedPrize
? "Every prize has been fully drawn"
: remaining <= 0
Expand Down Expand Up @@ -125,11 +124,13 @@ export function RaffleDrawPanel({
<Loader2 className="size-3 animate-spin" />
Loading entries...
</span>
) : poolError ? (
<span className="text-destructive">Couldn't load entries</span>
) : (
<span>
<span className="font-medium text-foreground">{poolEntries}</span> entries from{" "}
<span className="font-medium text-foreground">{entrants.length}</span> hackers across{" "}
{eligibleStampCount} eligible stamp{eligibleStampCount === 1 ? "" : "s"}
<span className="font-medium text-foreground">{entrants.length}</span> hackers, 1 entry
per point
</span>
)}
{poolFetchedAt && !poolLoading && (
Expand All @@ -145,15 +146,6 @@ export function RaffleDrawPanel({
<RefreshCw className="size-3" />
Refresh
</Button>
<Button
variant="ghost"
size="sm"
onClick={onManageStamps}
className="h-auto px-2 py-1 text-xs"
>
<Stamp className="size-3" />
Eligible stamps
</Button>
</div>

{disabledReason && <p className="text-muted-foreground text-xs">{disabledReason}</p>}
Expand Down
87 changes: 0 additions & 87 deletions src/components/features/raffle/raffle-stamps-dialog.tsx

This file was deleted.

68 changes: 68 additions & 0 deletions src/components/features/settings/hackathon-settings-form.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { HackathonConfig } from "@/lib/firebase/types";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { HackathonSettingsForm } from "./hackathon-settings-form";

const settings = vi.hoisted(() => ({
config: null as unknown as HackathonConfig,
updateHackathonConfig: vi.fn(),
}));

vi.mock("@/services/hackathon-settings", () => ({
subscribeToHackathonConfig: (callback: (data: HackathonConfig) => void) => {
callback(settings.config);
return () => {};
},
updateHackathonConfig: settings.updateHackathonConfig,
}));

vi.mock("@/components/features/settings/wallet-email-control", () => ({
WalletEmailControl: () => null,
}));

vi.mock("sonner", () => ({ toast: { success: vi.fn(), error: vi.fn() } }));

const timeline = {
hackathonStart: { hackcamp: "2026-11-07T17:00:00.000Z" },
hackathonEnd: { hackcamp: "2026-11-08T23:00:00.000Z" },
hackingStart: { hackcamp: "2026-11-07T19:00:00.000Z" },
hackingEnd: { hackcamp: "2026-11-08T19:00:00.000Z" },
};

const toggleCtfAndSave = async () => {
render(<HackathonSettingsForm hackathonId="HackCamp2026" />);
fireEvent.click(screen.getByRole("button", { name: "Edit" }));
fireEvent.click(screen.getByRole("switch", { name: "CTF Open" }));
fireEvent.click(screen.getByRole("button", { name: "Save" }));
await waitFor(() => expect(settings.updateHackathonConfig).toHaveBeenCalledOnce());
return settings.updateHackathonConfig.mock.calls[0][0] as HackathonConfig;
};

describe("HackathonSettingsForm CTF Open", () => {
beforeEach(() => {
settings.updateHackathonConfig.mockReset();
});

it("creates the ctfOpen map when the doc doesn't have one yet", async () => {
settings.config = {
...timeline,
portalLive: { hackcamp: false },
} as unknown as HackathonConfig;

const saved = await toggleCtfAndSave();

expect(saved.ctfOpen).toEqual({ hackcamp: true });
expect(saved.portalLive).toEqual({ hackcamp: false });
});

it("only changes this hackathon's flag", async () => {
settings.config = {
...timeline,
ctfOpen: { hackcamp: false, nwhacks: true },
} as unknown as HackathonConfig;

const saved = await toggleCtfAndSave();

expect(saved.ctfOpen).toEqual({ hackcamp: true, nwhacks: true });
});
});
18 changes: 17 additions & 1 deletion src/components/features/settings/hackathon-settings-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ export function HackathonSettingsForm({ hackathonId }: { hackathonId: string })
}

const currentValue = editedConfig[field];
// toggles are per-hackathon maps; one missing from older docs (like ctfOpen) starts as a new map
const isMapField =
typeof currentValue === "object" && currentValue !== null && !Array.isArray(currentValue);
(typeof currentValue === "object" && currentValue !== null && !Array.isArray(currentValue)) ||
(currentValue === undefined && typeof value === "boolean");

if (nestedField) {
const hackathonValue =
Expand Down Expand Up @@ -283,6 +285,20 @@ export function HackathonSettingsForm({ hackathonId }: { hackathonId: string })
disabled={isEditing || isSaving}
/>
</div>
<div className="flex items-center justify-between">
<div>
<Label htmlFor="ctfOpen">CTF Open</Label>
<p className="mt-1 text-muted-foreground text-sm">
Shows the CTF page to RSVP'd hackers, even before the portal is live
</p>
</div>
<Switch
id="ctfOpen"
checked={getBooleanValue("ctfOpen")}
onCheckedChange={(checked) => handleFieldChange("ctfOpen", checked)}
disabled={!isEditing}
/>
</div>
</div>
</div>

Expand Down
17 changes: 9 additions & 8 deletions src/components/features/stampbook/export-raffle-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ export function ExportRaffleDialog({ open, onClose, stamps }: ExportRaffleDialog
}

const csvContent = generateRaffleCSV(raffleEntries);
const filename = `raffle-${selectedHackathon}-${new Date().toISOString().split("T")[0]}.csv`;
const filename = `stamp-holders-${selectedHackathon}-${new Date().toISOString().split("T")[0]}.csv`;
downloadCSV(csvContent, filename);
toast.success(`Exported ${raffleEntries.length} raffle entries`);
toast.success(`Exported ${raffleEntries.length} stamp holder rows`);
} catch (error) {
console.error("Error exporting raffle:", error);
toast.error("Failed to export raffle data");
console.error("Error exporting stamp holders:", error);
toast.error("Failed to export stamp holders");
} finally {
setLoading(false);
}
Expand All @@ -96,10 +96,11 @@ export function ExportRaffleDialog({ open, onClose, stamps }: ExportRaffleDialog
aria-describedby="raffle-export-description"
>
<DialogHeader>
<DialogTitle>Export Raffle</DialogTitle>
<DialogTitle>Export stamp holders</DialogTitle>
<DialogDescription id="raffle-export-description" className="text-xs">
Export a CSV of obfuscated emails for raffles. Outputs a list of name + emails, where
duplicate entries correlate to number of stamps collected by a hacker.
Export a CSV of obfuscated emails with one row per collected stamp, so a hacker appears
once for each selected stamp they hold. This is not the raffle pool, which is based on
points.
</DialogDescription>
</DialogHeader>

Expand Down Expand Up @@ -140,7 +141,7 @@ export function ExportRaffleDialog({ open, onClose, stamps }: ExportRaffleDialog
) : (
<Download className="mr-2 h-4 w-4" />
)}
Export Raffle CSV
Export stamp holders CSV
</Button>
</div>
</DialogContent>
Expand Down
Loading
Loading