feat(portfolio): add artwork refinement and price visibility fields
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
listArtworks,
|
||||
listMediaAssets,
|
||||
listMediaFoundationGroups,
|
||||
updateArtwork,
|
||||
updateGrouping,
|
||||
} from "@cms/db"
|
||||
import { Button } from "@cms/ui/button"
|
||||
@@ -45,6 +46,15 @@ function readNonNegativeInt(formData: FormData, key: string): number {
|
||||
return Number.isFinite(value) && value >= 0 ? Math.floor(value) : 0
|
||||
}
|
||||
|
||||
function readOptionalNonNegativeInt(formData: FormData, key: string): number | undefined {
|
||||
const raw = readField(formData, key)
|
||||
if (!raw) {
|
||||
return undefined
|
||||
}
|
||||
const value = Number(raw)
|
||||
return Number.isFinite(value) && value >= 0 ? Math.floor(value) : undefined
|
||||
}
|
||||
|
||||
function readBooleanField(formData: FormData, key: string): boolean {
|
||||
return formData.get(key) === "on" || readField(formData, key) === "true"
|
||||
}
|
||||
@@ -106,6 +116,15 @@ async function createArtworkAction(formData: FormData) {
|
||||
dimensions: readOptionalField(formData, "dimensions"),
|
||||
framing: readOptionalField(formData, "framing"),
|
||||
availability: readOptionalField(formData, "availability"),
|
||||
priceAmountCents: (() => {
|
||||
const raw = readField(formData, "priceAmount")
|
||||
return raw ? Math.round(Number(raw) * 100) : undefined
|
||||
})(),
|
||||
priceCurrency: (() => {
|
||||
const raw = readField(formData, "priceCurrency").toUpperCase()
|
||||
return raw.length === 3 ? raw : undefined
|
||||
})(),
|
||||
isPriceVisible: readBooleanField(formData, "isPriceVisible"),
|
||||
year: (() => {
|
||||
const raw = readField(formData, "year")
|
||||
return raw ? Number(raw) : undefined
|
||||
@@ -119,6 +138,41 @@ async function createArtworkAction(formData: FormData) {
|
||||
redirectWithState({ notice: "Artwork created." })
|
||||
}
|
||||
|
||||
async function updateArtworkAction(formData: FormData) {
|
||||
"use server"
|
||||
|
||||
await requireWritePermission()
|
||||
|
||||
try {
|
||||
await updateArtwork({
|
||||
id: readField(formData, "artworkId"),
|
||||
medium: readOptionalNullableField(formData, "medium"),
|
||||
dimensions: readOptionalNullableField(formData, "dimensions"),
|
||||
year: (() => {
|
||||
const raw = readField(formData, "year")
|
||||
return raw ? Number(raw) : null
|
||||
})(),
|
||||
framing: readOptionalNullableField(formData, "framing"),
|
||||
availability: readOptionalNullableField(formData, "availability"),
|
||||
priceAmountCents: (() => {
|
||||
const value = readOptionalNonNegativeInt(formData, "priceAmountCents")
|
||||
return value ?? null
|
||||
})(),
|
||||
priceCurrency: (() => {
|
||||
const raw = readField(formData, "priceCurrency").toUpperCase()
|
||||
return raw.length === 3 ? raw : null
|
||||
})(),
|
||||
isPriceVisible: readBooleanField(formData, "isPriceVisible"),
|
||||
isPublished: readBooleanField(formData, "isPublished"),
|
||||
})
|
||||
} catch {
|
||||
redirectWithState({ error: "Failed to update artwork refinement fields." })
|
||||
}
|
||||
|
||||
revalidatePath("/portfolio")
|
||||
redirectWithState({ notice: "Artwork refinement updated." })
|
||||
}
|
||||
|
||||
async function createGroupAction(formData: FormData) {
|
||||
"use server"
|
||||
|
||||
@@ -357,6 +411,26 @@ export default async function PortfolioPage({
|
||||
placeholder="Availability"
|
||||
className="w-full rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
<div className="grid gap-3 md:grid-cols-3">
|
||||
<input
|
||||
name="priceAmount"
|
||||
type="number"
|
||||
step="0.01"
|
||||
min={0}
|
||||
placeholder="Price amount (e.g. 199.99)"
|
||||
className="rounded border border-neutral-300 px-3 py-2 text-sm"
|
||||
/>
|
||||
<input
|
||||
name="priceCurrency"
|
||||
maxLength={3}
|
||||
placeholder="Currency (USD)"
|
||||
className="rounded border border-neutral-300 px-3 py-2 text-sm uppercase"
|
||||
/>
|
||||
<label className="flex items-center gap-2 rounded border border-neutral-300 px-3 py-2 text-sm">
|
||||
<input type="checkbox" name="isPriceVisible" />
|
||||
Price visible
|
||||
</label>
|
||||
</div>
|
||||
<Button type="submit">Create artwork</Button>
|
||||
</form>
|
||||
</section>
|
||||
@@ -609,14 +683,16 @@ export default async function PortfolioPage({
|
||||
<th className="py-2 pr-4">Title</th>
|
||||
<th className="py-2 pr-4">Slug</th>
|
||||
<th className="py-2 pr-4">Published</th>
|
||||
<th className="py-2 pr-4">Refinement</th>
|
||||
<th className="py-2 pr-4">Renditions</th>
|
||||
<th className="py-2 pr-4">Groups</th>
|
||||
<th className="py-2 pr-4">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{artworks.length === 0 ? (
|
||||
<tr>
|
||||
<td className="py-3 text-neutral-500" colSpan={5}>
|
||||
<td className="py-3 text-neutral-500" colSpan={7}>
|
||||
No artworks yet. Add creation flows after media upload pipeline lands.
|
||||
</td>
|
||||
</tr>
|
||||
@@ -626,11 +702,102 @@ export default async function PortfolioPage({
|
||||
<td className="py-3 pr-4">{artwork.title}</td>
|
||||
<td className="py-3 pr-4 font-mono text-xs">{artwork.slug}</td>
|
||||
<td className="py-3 pr-4">{artwork.isPublished ? "yes" : "no"}</td>
|
||||
<td className="py-3 pr-4 text-xs text-neutral-600">
|
||||
{artwork.medium ? `medium: ${artwork.medium}` : "medium: -"}
|
||||
<br />
|
||||
{artwork.dimensions ? `dimensions: ${artwork.dimensions}` : "dimensions: -"}
|
||||
<br />
|
||||
{artwork.year ? `year: ${artwork.year}` : "year: -"}
|
||||
<br />
|
||||
{artwork.framing ? `framing: ${artwork.framing}` : "framing: -"}
|
||||
<br />
|
||||
{artwork.availability
|
||||
? `availability: ${artwork.availability}`
|
||||
: "availability: -"}
|
||||
<br />
|
||||
{artwork.priceAmountCents && artwork.priceCurrency
|
||||
? `price: ${(artwork.priceAmountCents / 100).toFixed(2)} ${artwork.priceCurrency} (${artwork.isPriceVisible ? "visible" : "hidden"})`
|
||||
: "price: -"}
|
||||
</td>
|
||||
<td className="py-3 pr-4">{artwork.renditions.length}</td>
|
||||
<td className="py-3 pr-4 text-neutral-600">
|
||||
g:{artwork.galleryLinks.length} a:{artwork.albumLinks.length} c:
|
||||
{artwork.categoryLinks.length} t:{artwork.tagLinks.length}
|
||||
</td>
|
||||
<td className="py-3 pr-4">
|
||||
<form action={updateArtworkAction} className="grid min-w-80 gap-2">
|
||||
<input type="hidden" name="artworkId" value={artwork.id} />
|
||||
<input
|
||||
name="medium"
|
||||
defaultValue={artwork.medium ?? ""}
|
||||
placeholder="Medium"
|
||||
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||
/>
|
||||
<input
|
||||
name="dimensions"
|
||||
defaultValue={artwork.dimensions ?? ""}
|
||||
placeholder="Dimensions"
|
||||
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||
/>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<input
|
||||
name="year"
|
||||
type="number"
|
||||
defaultValue={artwork.year ?? ""}
|
||||
placeholder="Year"
|
||||
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||
/>
|
||||
<input
|
||||
name="framing"
|
||||
defaultValue={artwork.framing ?? ""}
|
||||
placeholder="Framing"
|
||||
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||
/>
|
||||
</div>
|
||||
<input
|
||||
name="availability"
|
||||
defaultValue={artwork.availability ?? ""}
|
||||
placeholder="Availability"
|
||||
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||
/>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<input
|
||||
name="priceAmountCents"
|
||||
type="number"
|
||||
min={0}
|
||||
defaultValue={artwork.priceAmountCents ?? ""}
|
||||
placeholder="Price cents"
|
||||
className="rounded border border-neutral-300 px-2 py-1 text-xs"
|
||||
/>
|
||||
<input
|
||||
name="priceCurrency"
|
||||
maxLength={3}
|
||||
defaultValue={artwork.priceCurrency ?? ""}
|
||||
placeholder="USD"
|
||||
className="rounded border border-neutral-300 px-2 py-1 text-xs uppercase"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-3 text-xs">
|
||||
<label className="inline-flex items-center gap-1">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="isPriceVisible"
|
||||
defaultChecked={artwork.isPriceVisible}
|
||||
/>
|
||||
price visible
|
||||
</label>
|
||||
<label className="inline-flex items-center gap-1">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="isPublished"
|
||||
defaultChecked={artwork.isPublished}
|
||||
/>
|
||||
published
|
||||
</label>
|
||||
</div>
|
||||
<Button type="submit">Save</Button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
|
||||
@@ -17,6 +17,17 @@ function formatLabelList(values: string[]) {
|
||||
return values.join(", ")
|
||||
}
|
||||
|
||||
function formatArtworkPrice(priceAmountCents: number | null, priceCurrency: string | null) {
|
||||
if (!priceAmountCents || !priceCurrency) {
|
||||
return "-"
|
||||
}
|
||||
|
||||
return new Intl.NumberFormat("en-US", {
|
||||
style: "currency",
|
||||
currency: priceCurrency,
|
||||
}).format(priceAmountCents / 100)
|
||||
}
|
||||
|
||||
export default async function PublicArtworkPage({ params }: PublicArtworkPageProps) {
|
||||
const [{ slug }, t] = await Promise.all([params, getTranslations("Portfolio")])
|
||||
const artwork = await getPublishedArtworkBySlug(slug)
|
||||
@@ -78,6 +89,12 @@ export default async function PublicArtworkPage({ params }: PublicArtworkPagePro
|
||||
<p>
|
||||
<strong>{t("fields.availability")}:</strong> {artwork.availability || "-"}
|
||||
</p>
|
||||
<p>
|
||||
<strong>{t("fields.price")}:</strong>{" "}
|
||||
{artwork.isPriceVisible
|
||||
? formatArtworkPrice(artwork.priceAmountCents, artwork.priceCurrency)
|
||||
: "-"}
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2 text-sm">
|
||||
<p>
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
"dimensions": "Abmessungen",
|
||||
"year": "Jahr",
|
||||
"availability": "Verfügbarkeit",
|
||||
"price": "Preis",
|
||||
"galleries": "Galerien",
|
||||
"albums": "Alben",
|
||||
"categories": "Kategorien",
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
"dimensions": "Dimensions",
|
||||
"year": "Year",
|
||||
"availability": "Availability",
|
||||
"price": "Price",
|
||||
"galleries": "Galleries",
|
||||
"albums": "Albums",
|
||||
"categories": "Categories",
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
"dimensions": "Dimensiones",
|
||||
"year": "Año",
|
||||
"availability": "Disponibilidad",
|
||||
"price": "Precio",
|
||||
"galleries": "Galerías",
|
||||
"albums": "Álbumes",
|
||||
"categories": "Categorías",
|
||||
|
||||
@@ -84,6 +84,7 @@
|
||||
"dimensions": "Dimensions",
|
||||
"year": "Année",
|
||||
"availability": "Disponibilité",
|
||||
"price": "Prix",
|
||||
"galleries": "Galeries",
|
||||
"albums": "Albums",
|
||||
"categories": "Catégories",
|
||||
|
||||
Reference in New Issue
Block a user