- env.ts: added 10 missing Zod-validated env vars (imager, paypal currency, argon2/bcrypt params) - Migrated 6 modules from process.env to validated env.* (auth, proxy-auth, paypal, password, redis, imager, moderation, alert, logger) - Replaced console.warn/error with pino logger in 9 server-side modules - Removed 50+ dead exports (SWF wrappers, coalesceHotelName, signIn, isStaff re-export, formatTimestamp, Skeleton/SkeletonCard, 4 unused housekeeping sections) - Consolidated date formatting: 28 files migrated to shared formatDate() from @/lib/format-date - Wired 4 radio/settings API routes through cached siteSettings service instead of raw Prisma queries - Added getMany()/getAll() helpers to SiteSettings service - Removed 88 dead Prisma model definitions (schema 2763→1846 lines) - Created admin action-helper.ts with wrapAction() for standardized error handling - Fixed useEffect dependency arrays in 4 data-heavy components - Replaced raw btn CSS classes with shadcn Button component across admin pages - Stripped dead i18n namespaces (common, pages.client) from all 22 translation files - Removed 2 dead scripts (create-release.sh, check-local-imports.ts) - Fixed knip.json configuration - Added 7 new test suites: format-date, paypal, moderation, alert, webhook, action-helper, and fixed password.test.ts for env mocking - All 358 tests passing across 72 test files - TypeScript: 0 errors
206 lines
6.3 KiB
TypeScript
206 lines
6.3 KiB
TypeScript
import { redirect } from "next/navigation";
|
|
import { getTranslations } from "next-intl/server";
|
|
import type { CSSProperties } from "react";
|
|
import { applyStaff } from "@/actions/applications";
|
|
import { ContentCard, EmptyState } from "@/components/public/ui";
|
|
import { auth } from "@/lib/auth";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { formatDate } from "@/lib/format-date";
|
|
import { resolveHotelName } from "@/lib/hotel-name";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
// Canonical Habbo badge image CDN (same base used by the profile page).
|
|
const BADGE_IMG_BASE = "https://images.habbo.com/c_images/album1584";
|
|
|
|
function feedbackStyle(tone: "success" | "error"): CSSProperties {
|
|
const accent =
|
|
tone === "error" ? "var(--color-danger)" : "var(--color-primary)";
|
|
return {
|
|
margin: 0,
|
|
padding: "0.85rem 1rem",
|
|
borderRadius: "var(--radius-md)",
|
|
border: `1px solid ${accent}`,
|
|
color: "var(--color-text-readable, var(--color-text))",
|
|
fontSize: "0.9rem",
|
|
fontWeight: 600,
|
|
background: "var(--color-surface)",
|
|
borderLeft: `4px solid ${accent}`,
|
|
};
|
|
}
|
|
|
|
export default async function ApplyStaffPage({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ submitted?: string; error?: string }>;
|
|
}) {
|
|
const session = await auth();
|
|
if (!session?.user?.id) redirect("/login");
|
|
|
|
const t = await getTranslations("pages.applyStaff");
|
|
const { submitted, error } = await searchParams;
|
|
|
|
const errorMessage =
|
|
error === "empty"
|
|
? t("errors.empty")
|
|
: error === "duplicate"
|
|
? t("errors.duplicate")
|
|
: error === "ratelimit"
|
|
? t("errors.ratelimit")
|
|
: error === "invalid"
|
|
? t("errors.invalid")
|
|
: error
|
|
? t("errors.error")
|
|
: null;
|
|
|
|
const userId = Number(session.user.id);
|
|
const hotelName = await resolveHotelName();
|
|
|
|
// ── Open positions ──────────────────────────────────────────
|
|
// Each query is isolated so a DB hiccup degrades that section to empty
|
|
// rather than 500-ing the whole page.
|
|
const positions = await prisma.websiteOpenPositions
|
|
.findMany({ orderBy: { createdAt: "desc" } })
|
|
.catch(() => []);
|
|
|
|
// Resolve display info for each position's rank. The rich rank fields
|
|
// (rankName/badge/jobDescription/staffColor) live in website_teams, keyed by
|
|
// the same rank id the position's permission_id points at.
|
|
const rankIds = Array.from(new Set(positions.map((p) => p.permissionId)));
|
|
const teams = rankIds.length
|
|
? await prisma.websiteTeams
|
|
.findMany({
|
|
where: { id: { in: rankIds.map((r) => BigInt(r)) } },
|
|
})
|
|
.catch(() => [])
|
|
: [];
|
|
const teamByRankId = new Map(teams.map((t) => [Number(t.id), t]));
|
|
|
|
// Ranks this user has already applied for (block re-applying).
|
|
const myApps = await prisma.websiteStaffApplications
|
|
.findMany({ where: { userId }, select: { rankId: true } })
|
|
.catch(() => []);
|
|
const appliedRankIds = new Set(myApps.map((a) => a.rankId));
|
|
|
|
return (
|
|
<main style={{ display: "grid", gap: "1.5rem" }}>
|
|
{submitted === "1" ? (
|
|
<div role="status" style={feedbackStyle("success")}>
|
|
{t("success.submitted")}
|
|
</div>
|
|
) : null}
|
|
{errorMessage ? (
|
|
<div role="alert" style={feedbackStyle("error")}>
|
|
{errorMessage}
|
|
</div>
|
|
) : null}
|
|
|
|
<ContentCard
|
|
icon="🛡️"
|
|
title={t("title", { hotel: hotelName })}
|
|
subtitle={t("subtitle")}
|
|
/>
|
|
|
|
{positions.length === 0 ? (
|
|
<ContentCard icon="🛡️" title={t("noPositionsTitle")}>
|
|
<EmptyState icon="🛡️">{t("noPositionsBody")}</EmptyState>
|
|
</ContentCard>
|
|
) : (
|
|
<div className="card-grid sm-2">
|
|
{positions.map((position) => {
|
|
const team = teamByRankId.get(position.permissionId);
|
|
const rankName = team?.rankName ?? `Rank #${position.permissionId}`;
|
|
const alreadyApplied = appliedRankIds.has(position.permissionId);
|
|
return (
|
|
<article key={String(position.id)} className="content-card">
|
|
<div className="content-card-head">
|
|
{team?.badge ? (
|
|
/* eslint-disable-next-line @next/next/no-img-element */
|
|
<img
|
|
src={`${BADGE_IMG_BASE}/${team.badge}.gif`}
|
|
alt={rankName}
|
|
width={40}
|
|
height={40}
|
|
/>
|
|
) : (
|
|
<span className="content-card-icon" aria-hidden>
|
|
🛡️
|
|
</span>
|
|
)}
|
|
<div className="content-card-head-text">
|
|
<p
|
|
className="content-card-title"
|
|
style={{ color: team?.staffColor || undefined }}
|
|
>
|
|
{rankName}
|
|
</p>
|
|
{team?.jobDescription ? (
|
|
<p className="content-card-subtitle">
|
|
{team.jobDescription}
|
|
</p>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="content-card-body">
|
|
<p style={{ margin: "0 0 0.5rem" }}>{position.description}</p>
|
|
<p className="muted" style={{ margin: "0 0 0.75rem" }}>
|
|
{t("deadline", { date: formatDate(position.applyTo, "datetime", t("noDeadline")) })}
|
|
</p>
|
|
|
|
{alreadyApplied ? (
|
|
<button
|
|
type="button"
|
|
className="btn btn-danger"
|
|
disabled
|
|
style={{ width: "100%" }}
|
|
>
|
|
{t("alreadyApplied", { rank: rankName })}
|
|
</button>
|
|
) : (
|
|
<form action={applyStaff}>
|
|
{/* rank_id is the position's permission id; the applicant is
|
|
re-read from the session inside the action. */}
|
|
<input
|
|
type="hidden"
|
|
name="rankId"
|
|
value={String(position.permissionId)}
|
|
/>
|
|
<label
|
|
htmlFor={`content-${position.id}`}
|
|
className="muted"
|
|
>
|
|
{t("aboutYou")}
|
|
</label>
|
|
<textarea
|
|
id={`content-${position.id}`}
|
|
name="content"
|
|
required
|
|
minLength={10}
|
|
rows={5}
|
|
placeholder={t("aboutPlaceholder", { rank: rankName })}
|
|
style={{
|
|
width: "100%",
|
|
margin: "0.4rem 0 0.75rem",
|
|
resize: "vertical",
|
|
}}
|
|
/>
|
|
<button
|
|
type="submit"
|
|
className="btn btn-secondary"
|
|
style={{ width: "100%" }}
|
|
>
|
|
{t("applyFor", { rank: rankName })}
|
|
</button>
|
|
</form>
|
|
)}
|
|
</div>
|
|
</article>
|
|
);
|
|
})}
|
|
</div>
|
|
)}
|
|
</main>
|
|
);
|
|
}
|