cg / hackerproducts
63 files · 5,740 lines · 159.1 KB — Next.js 15, React 19, TypeScript, PostgreSQL, Object Storage, plain CSS.
Quick jump: page.tsxpage.tsxglobals.cssschema.sqlpackage.json
root / src / app / submit / page.tsx
src/app/submit/page.tsx · 67 lines · 1.9 KB← back to folder
| 1 | import type { Metadata } from "next"; |
| 2 | import Link from "next/link"; |
| 3 | import { getCurrentUser } from "@/lib/auth"; |
| 4 | import { getProductSubmissionCooldown, PRODUCT_COOLDOWN_DAYS } from "@/lib/antispam"; |
| 5 | import { formatDisplayDate } from "@/lib/format"; |
| 6 | import { ProductForm } from "@/components/ProductForm"; |
| 7 | |
| 8 | export const dynamic = "force-dynamic"; |
| 9 | |
| 10 | export const metadata: Metadata = { |
| 11 | title: "Submit a product", |
| 12 | description: "Submit a product you built to Hacker Products.", |
| 13 | }; |
| 14 | |
| 15 | export default async function SubmitPage() { |
| 16 | const user = await getCurrentUser(); |
| 17 | |
| 18 | if (!user) { |
| 19 | return ( |
| 20 | <div> |
| 21 | <h1>Submit a product</h1> |
| 22 | <p className="subtitle">Sign in to publish a product on Hacker Products.</p> |
| 23 | <p> |
| 24 | <Link href="/login?next=/submit">Sign in to continue →</Link> |
| 25 | </p> |
| 26 | </div> |
| 27 | ); |
| 28 | } |
| 29 | |
| 30 | const cooldown = user.is_admin |
| 31 | ? { allowed: true } |
| 32 | : await getProductSubmissionCooldown(user.id); |
| 33 | |
| 34 | if (!cooldown.allowed) { |
| 35 | const daysText = |
| 36 | cooldown.daysRemaining === 1 ? "1 day" : `${cooldown.daysRemaining} days`; |
| 37 | return ( |
| 38 | <div> |
| 39 | <h1>Submit a product</h1> |
| 40 | <p className="subtitle"> |
| 41 | To keep Hacker Products spam-free, each maker can publish one product every{" "} |
| 42 | {PRODUCT_COOLDOWN_DAYS} days. |
| 43 | </p> |
| 44 | <p> |
| 45 | You can submit your next product in <strong>{daysText}</strong> |
| 46 | {cooldown.nextAllowedAt ? ` (${formatDisplayDate(cooldown.nextAllowedAt)})` : ""}. |
| 47 | </p> |
| 48 | <p> |
| 49 | In the meantime, you can edit your existing products from{" "} |
| 50 | <Link href={`/${user.username}`}>your profile</Link>. |
| 51 | </p> |
| 52 | </div> |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | return ( |
| 57 | <div> |
| 58 | <h1>Submit a product</h1> |
| 59 | <p className="subtitle"> |
| 60 | Publishing as <Link href={`/${user.username}`}>{user.username}</Link>. One product every{" "} |
| 61 | {PRODUCT_COOLDOWN_DAYS} days. |
| 62 | </p> |
| 63 | <ProductForm mode="create" /> |
| 64 | </div> |
| 65 | ); |
| 66 | } |
| 67 |