1136 lines
56 KiB
JavaScript
1136 lines
56 KiB
JavaScript
import React, { useEffect, useMemo, useState } from 'react'
|
|
import { Head, Link, router, usePage } from '@inertiajs/react'
|
|
import AdminLayout from '../../../Layouts/AdminLayout'
|
|
import AccessBadge from '../../../components/academy/billing/AccessBadge'
|
|
|
|
const PROMPT_VIEW_STORAGE_KEY = 'skinbase.admin.academy.prompts.view'
|
|
const COURSE_VIEW_STORAGE_KEY = 'skinbase.admin.academy.courses.view'
|
|
const PROMPT_VIEW_OPTIONS = [
|
|
{ value: 'gallery', label: 'Gallery', icon: 'fa-images' },
|
|
{ value: 'grid', label: 'Grid', icon: 'fa-grid-2' },
|
|
{ value: 'table', label: 'Table', icon: 'fa-table-list' },
|
|
]
|
|
const COURSE_VIEW_OPTIONS = [
|
|
{ value: 'grid', label: 'Grid', icon: 'fa-grid-2' },
|
|
{ value: 'table', label: 'Table', icon: 'fa-table-list' },
|
|
]
|
|
|
|
function formatDateLabel(value) {
|
|
if (!value) return 'Recently updated'
|
|
|
|
const date = new Date(value)
|
|
|
|
if (Number.isNaN(date.getTime())) return 'Recently updated'
|
|
|
|
return new Intl.DateTimeFormat('en-GB', { day: 'numeric', month: 'short', year: 'numeric' }).format(date)
|
|
}
|
|
|
|
function paginationLabel(label) {
|
|
return String(label || '')
|
|
.replace(/«/g, 'Previous')
|
|
.replace(/»/g, 'Next')
|
|
.replace(/<[^>]+>/g, '')
|
|
.trim()
|
|
}
|
|
|
|
function courseStatusMeta(status) {
|
|
const normalized = String(status || 'draft')
|
|
|
|
if (normalized === 'published') {
|
|
return { label: 'Published', className: 'border-emerald-300/20 bg-emerald-300/10 text-emerald-100' }
|
|
}
|
|
|
|
if (normalized === 'review') {
|
|
return { label: 'Review', className: 'border-amber-300/20 bg-amber-300/10 text-amber-100' }
|
|
}
|
|
|
|
if (normalized === 'archived') {
|
|
return { label: 'Archived', className: 'border-white/10 bg-white/[0.04] text-slate-300' }
|
|
}
|
|
|
|
return { label: 'Draft', className: 'border-slate-500/20 bg-slate-500/10 text-slate-300' }
|
|
}
|
|
|
|
function courseAccessMeta(accessLevel) {
|
|
const normalized = String(accessLevel || 'free')
|
|
|
|
if (normalized === 'premium') {
|
|
return { label: 'Premium', className: 'border-[#ffcfbf]/20 bg-[#ffcfbf]/10 text-[#fff0ea]' }
|
|
}
|
|
|
|
if (normalized === 'mixed') {
|
|
return { label: 'Mixed', className: 'border-sky-300/20 bg-sky-300/10 text-sky-100' }
|
|
}
|
|
|
|
return { label: 'Free', className: 'border-white/10 bg-white/[0.05] text-slate-200' }
|
|
}
|
|
|
|
function courseSummary(items = [], summary = null) {
|
|
if (summary && typeof summary === 'object') {
|
|
return {
|
|
total: Number(summary.total || 0),
|
|
published: Number(summary.published || 0),
|
|
featured: Number(summary.featured || 0),
|
|
drafts: Number(summary.drafts || 0),
|
|
visibleOnPage: Array.isArray(items) ? items.length : 0,
|
|
}
|
|
}
|
|
|
|
return items.reduce((accumulator, item) => ({
|
|
total: accumulator.total + 1,
|
|
published: accumulator.published + (item.status === 'published' ? 1 : 0),
|
|
featured: accumulator.featured + (item.is_featured ? 1 : 0),
|
|
drafts: accumulator.drafts + (item.status === 'draft' ? 1 : 0),
|
|
visibleOnPage: accumulator.visibleOnPage + 1,
|
|
}), { total: 0, published: 0, featured: 0, drafts: 0, visibleOnPage: 0 })
|
|
}
|
|
|
|
function promptSummary(items = [], summary = null) {
|
|
if (summary && typeof summary === 'object') {
|
|
return {
|
|
total: Number(summary.total || 0),
|
|
active: Number(summary.active || 0),
|
|
featured: Number(summary.featured || 0),
|
|
promptOfWeek: Number(summary.promptOfWeek || 0),
|
|
comparisons: Array.isArray(items) ? items.reduce((count, item) => count + Number(item.comparisons_count || 0), 0) : 0,
|
|
access: {
|
|
free: Number(summary.access?.free || 0),
|
|
creator: Number(summary.access?.creator || 0),
|
|
pro: Number(summary.access?.pro || 0),
|
|
},
|
|
}
|
|
}
|
|
|
|
return items.reduce((summary, item) => ({
|
|
total: summary.total + 1,
|
|
active: summary.active + (item.active ? 1 : 0),
|
|
featured: summary.featured + (item.featured ? 1 : 0),
|
|
promptOfWeek: summary.promptOfWeek + (item.prompt_of_week ? 1 : 0),
|
|
comparisons: summary.comparisons + Number(item.comparisons_count || 0),
|
|
access: {
|
|
free: summary.access.free + (item.access_level === 'free' ? 1 : 0),
|
|
creator: summary.access.creator + (item.access_level === 'creator' ? 1 : 0),
|
|
pro: summary.access.pro + (item.access_level === 'pro' ? 1 : 0),
|
|
},
|
|
}), { total: 0, active: 0, featured: 0, promptOfWeek: 0, comparisons: 0, access: { free: 0, creator: 0, pro: 0 } })
|
|
}
|
|
|
|
function PromptFlag({ children, tone = 'default' }) {
|
|
const toneClass = tone === 'warm'
|
|
? 'border-[#ffcfbf]/20 bg-[#ffcfbf]/10 text-[#fff0ea]'
|
|
: tone === 'sky'
|
|
? 'border-sky-300/20 bg-sky-300/10 text-sky-100'
|
|
: tone === 'emerald'
|
|
? 'border-emerald-300/20 bg-emerald-300/10 text-emerald-100'
|
|
: 'border-white/10 bg-white/[0.05] text-slate-200'
|
|
|
|
return <span className={`rounded-full border px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.18em] ${toneClass}`}>{children}</span>
|
|
}
|
|
|
|
function CoursePill({ children, tone = 'default' }) {
|
|
const toneClass = tone === 'warm'
|
|
? 'border-[#ffcfbf]/20 bg-[#ffcfbf]/10 text-[#fff0ea]'
|
|
: tone === 'sky'
|
|
? 'border-sky-300/20 bg-sky-300/10 text-sky-100'
|
|
: tone === 'emerald'
|
|
? 'border-emerald-300/20 bg-emerald-300/10 text-emerald-100'
|
|
: 'border-white/10 bg-white/[0.05] text-slate-200'
|
|
|
|
return <span className={`rounded-full border px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.18em] ${toneClass}`}>{children}</span>
|
|
}
|
|
|
|
function CourseCover({ item, compact = false }) {
|
|
if (item.cover_image_url) {
|
|
return <img src={item.cover_image_url} alt={item.title} className={`h-full w-full object-cover transition duration-500 ${compact ? 'group-hover:scale-[1.04]' : 'group-hover:scale-[1.03]'}`} />
|
|
}
|
|
|
|
return (
|
|
<div className="flex h-full items-center justify-center bg-[radial-gradient(circle_at_top_left,rgba(56,189,248,0.18),transparent_28%),radial-gradient(circle_at_bottom_right,rgba(255,207,191,0.18),transparent_24%),linear-gradient(135deg,rgba(15,23,42,0.98),rgba(30,41,59,0.94))] p-6 text-center text-slate-300">
|
|
<div>
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.2em] text-slate-500">Course cover</p>
|
|
<p className="mt-3 text-sm font-semibold text-white">No cover image attached yet</p>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function CourseCoverWall({ items = [] }) {
|
|
const images = items
|
|
.map((item) => item?.cover_image_url)
|
|
.filter(Boolean)
|
|
.slice(0, 4)
|
|
|
|
if (!images.length) {
|
|
return (
|
|
<div className="flex min-h-[320px] items-center justify-center rounded-[32px] border border-white/10 bg-[radial-gradient(circle_at_top_left,rgba(56,189,248,0.14),transparent_24%),radial-gradient(circle_at_bottom_right,rgba(255,207,191,0.18),transparent_26%),linear-gradient(135deg,rgba(12,18,31,0.98),rgba(30,41,59,0.94))] px-8 text-center">
|
|
<div>
|
|
<p className="text-[11px] font-semibold uppercase tracking-[0.24em] text-slate-500">Course cover wall</p>
|
|
<p className="mt-4 text-lg font-semibold text-white">Course artwork will appear here once covers are added.</p>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-3">
|
|
<div className="overflow-hidden rounded-[30px] border border-white/10 bg-black/20 shadow-[0_18px_45px_rgba(2,6,23,0.2)]">
|
|
<div className="aspect-[16/10] overflow-hidden">
|
|
<img src={images[0]} alt="" aria-hidden="true" className="h-full w-full object-cover" />
|
|
</div>
|
|
</div>
|
|
|
|
{images.length > 1 ? (
|
|
<div className="grid grid-cols-2 gap-3">
|
|
{images.slice(1, 4).map((image, index) => (
|
|
<div
|
|
key={`${image}-${index}`}
|
|
className="aspect-square overflow-hidden rounded-[24px] border border-white/10 bg-black/20 shadow-[0_18px_45px_rgba(2,6,23,0.2)]"
|
|
>
|
|
<img src={image} alt="" aria-hidden="true" className="h-full w-full object-cover" />
|
|
</div>
|
|
))}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function CourseStatCard({ label, value, tone = 'default' }) {
|
|
const toneClass = tone === 'sky'
|
|
? 'border-sky-300/20 bg-sky-300/10 text-sky-100'
|
|
: tone === 'emerald'
|
|
? 'border-emerald-300/20 bg-emerald-300/10 text-emerald-100'
|
|
: tone === 'warm'
|
|
? 'border-[#ffcfbf]/20 bg-[#ffcfbf]/10 text-[#fff0ea]'
|
|
: 'border-white/10 bg-black/20 text-slate-300'
|
|
|
|
return (
|
|
<div className={`rounded-[24px] border px-5 py-4 ${toneClass}`}>
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.18em] opacity-70">{label}</p>
|
|
<p className="mt-2 text-2xl font-semibold tracking-[-0.04em] text-white">{value}</p>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function PromptActions({ item }) {
|
|
return (
|
|
<div className="flex flex-wrap gap-3">
|
|
{item.preview_url ? <Link href={item.preview_url} className="inline-flex items-center gap-2 rounded-full border border-[#ffcfbf]/20 bg-[#ffcfbf]/10 px-4 py-2 text-sm font-semibold text-[#fff0ea]"><i className="fa-solid fa-eye text-xs" />Preview</Link> : null}
|
|
<Link href={item.edit_url} className="inline-flex items-center gap-2 rounded-full border border-white/10 bg-white/[0.04] px-4 py-2 text-sm font-semibold text-white"><i className="fa-solid fa-pen-to-square text-xs" />Edit</Link>
|
|
<button type="button" onClick={() => { if (!window.confirm('Delete this prompt?')) return; router.delete(item.destroy_url, { preserveScroll: true }) }} className="inline-flex items-center gap-2 rounded-full border border-rose-300/20 bg-rose-300/10 px-4 py-2 text-sm font-semibold text-rose-100"><i className="fa-solid fa-trash text-xs" />Delete</button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function CourseActions({ item }) {
|
|
return (
|
|
<div className="flex flex-wrap gap-3">
|
|
<Link href={item.builder_url} className="inline-flex items-center gap-2 rounded-full border border-[#ffcfbf]/20 bg-[#ffcfbf]/10 px-4 py-2 text-sm font-semibold text-[#fff0ea]"><i className="fa-solid fa-sitemap text-xs" />Builder</Link>
|
|
<Link href={item.edit_url} className="inline-flex items-center gap-2 rounded-full border border-white/10 bg-white/[0.04] px-4 py-2 text-sm font-semibold text-white"><i className="fa-solid fa-pen-to-square text-xs" />Edit</Link>
|
|
<button type="button" onClick={() => { if (!window.confirm('Delete this course?')) return; router.delete(item.destroy_url, { preserveScroll: true }) }} className="inline-flex items-center gap-2 rounded-full border border-rose-300/20 bg-rose-300/10 px-4 py-2 text-sm font-semibold text-rose-100"><i className="fa-solid fa-trash text-xs" />Delete</button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function CourseGridCard({ item }) {
|
|
const status = courseStatusMeta(item.status)
|
|
const access = courseAccessMeta(item.access_level)
|
|
|
|
return (
|
|
<article className="group overflow-hidden rounded-[30px] border border-white/[0.08] bg-[linear-gradient(180deg,rgba(255,255,255,0.04),rgba(15,23,42,0.18))] shadow-[0_18px_60px_rgba(2,6,23,0.18)]">
|
|
<div className="relative h-56 overflow-hidden border-b border-white/10">
|
|
<CourseCover item={item} compact />
|
|
<div className="absolute inset-0 bg-[linear-gradient(180deg,rgba(2,6,23,0.02),rgba(2,6,23,0.34))]" />
|
|
</div>
|
|
|
|
<div className="p-5">
|
|
<div className="flex flex-wrap gap-2">
|
|
<CoursePill tone="warm">{item.lessons_count || 0} lessons</CoursePill>
|
|
<CoursePill tone={item.is_featured ? 'sky' : 'default'}>{item.is_featured ? 'Featured' : 'Course'}</CoursePill>
|
|
<span className={`rounded-full border px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.18em] ${status.className}`}>{status.label}</span>
|
|
</div>
|
|
|
|
<h2 className="mt-4 text-xl font-semibold tracking-[-0.04em] text-white">{item.title}</h2>
|
|
{item.subtitle ? <p className="mt-2 text-sm leading-6 text-slate-300">{item.subtitle}</p> : null}
|
|
<p className="mt-3 text-sm leading-7 text-slate-300">{item.excerpt || 'No excerpt added yet.'}</p>
|
|
|
|
<div className="mt-5 flex items-center justify-between gap-3 text-sm text-slate-400">
|
|
<span>{access.label}</span>
|
|
<span>{formatDateLabel(item.updated_at)}</span>
|
|
</div>
|
|
|
|
<div className="mt-5">
|
|
<CourseActions item={item} />
|
|
</div>
|
|
</div>
|
|
</article>
|
|
)
|
|
}
|
|
|
|
function CourseTable({ items }) {
|
|
return (
|
|
<div className="overflow-hidden rounded-[30px] border border-white/[0.08] bg-[linear-gradient(180deg,rgba(15,23,42,0.92),rgba(2,6,23,0.92))] shadow-[0_24px_80px_rgba(2,6,23,0.22)]">
|
|
<div className="overflow-x-auto">
|
|
<table className="min-w-full divide-y divide-white/10 text-left">
|
|
<thead className="bg-white/[0.04] text-[11px] font-semibold uppercase tracking-[0.22em] text-slate-400">
|
|
<tr>
|
|
<th className="px-5 py-4">Cover</th>
|
|
<th className="px-5 py-4">Course</th>
|
|
<th className="px-5 py-4">Access</th>
|
|
<th className="px-5 py-4">Status</th>
|
|
<th className="px-5 py-4">Lessons</th>
|
|
<th className="px-5 py-4">Updated</th>
|
|
<th className="px-5 py-4 text-right">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody className="divide-y divide-white/10 text-sm text-slate-200">
|
|
{items.map((item) => {
|
|
const status = courseStatusMeta(item.status)
|
|
const access = courseAccessMeta(item.access_level)
|
|
|
|
return (
|
|
<tr key={item.id} className="align-top transition hover:bg-white/[0.03]">
|
|
<td className="px-5 py-4">
|
|
<div className="h-20 w-28 overflow-hidden rounded-2xl border border-white/10 bg-black/30">
|
|
<CourseCover item={item} compact />
|
|
</div>
|
|
</td>
|
|
<td className="px-5 py-4">
|
|
<div>
|
|
<p className="font-semibold text-white">{item.title}</p>
|
|
{item.subtitle ? <p className="mt-1 max-w-md text-sm leading-6 text-slate-400">{item.subtitle}</p> : null}
|
|
<p className="mt-2 max-w-xl text-sm leading-6 text-slate-400">{item.excerpt || 'No excerpt added yet.'}</p>
|
|
</div>
|
|
</td>
|
|
<td className="px-5 py-4"><span className={`inline-flex rounded-full border px-3 py-1 text-xs font-semibold ${access.className}`}>{access.label}</span></td>
|
|
<td className="px-5 py-4"><span className={`inline-flex rounded-full border px-3 py-1 text-xs font-semibold ${status.className}`}>{status.label}</span></td>
|
|
<td className="px-5 py-4">
|
|
<div className="space-y-1 text-white">
|
|
<p>{item.lessons_count || 0} lessons</p>
|
|
<p>{item.is_featured ? 'Featured' : 'Standard'}</p>
|
|
</div>
|
|
</td>
|
|
<td className="px-5 py-4">{formatDateLabel(item.updated_at)}</td>
|
|
<td className="px-5 py-4">
|
|
<div className="flex justify-end gap-2">
|
|
<Link href={item.builder_url} className="rounded-full border border-[#ffcfbf]/20 bg-[#ffcfbf]/10 px-3 py-2 text-xs font-semibold text-[#fff0ea]">Builder</Link>
|
|
<Link href={item.edit_url} className="rounded-full border border-white/10 bg-white/[0.04] px-3 py-2 text-xs font-semibold text-white">Edit</Link>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
)
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function CourseSearchBar({ value, onChange, onSubmit, onClear, viewMode, onViewModeChange }) {
|
|
return (
|
|
<div className="rounded-[28px] border border-white/10 bg-white/[0.03] p-4 shadow-[0_18px_50px_rgba(2,6,23,0.14)]">
|
|
<div className="flex flex-col gap-4 xl:flex-row xl:items-center xl:justify-between">
|
|
<form onSubmit={onSubmit} className="flex flex-1 flex-col gap-3 sm:flex-row sm:items-center">
|
|
<div className="relative flex-1 max-w-2xl">
|
|
<i className="fa-solid fa-magnifying-glass absolute left-3.5 top-1/2 -translate-y-1/2 text-xs text-slate-500" />
|
|
<input
|
|
name="search"
|
|
value={value}
|
|
onChange={(event) => onChange(event.target.value)}
|
|
placeholder="Search title, slug, subtitle, excerpt, or description…"
|
|
className="w-full rounded-2xl border border-white/10 bg-black/20 py-3 pl-9 pr-4 text-sm text-white placeholder:text-slate-600 focus:border-white/20 focus:outline-none focus:ring-1 focus:ring-white/10"
|
|
/>
|
|
</div>
|
|
<button type="submit" className="rounded-2xl bg-sky-300/12 px-4 py-3 text-sm font-semibold text-sky-100 transition hover:bg-sky-300/16">
|
|
Search
|
|
</button>
|
|
{value ? (
|
|
<button type="button" onClick={onClear} className="rounded-2xl border border-white/10 bg-white/[0.04] px-4 py-3 text-sm font-semibold text-white/80 transition hover:bg-white/[0.08]">
|
|
Clear
|
|
</button>
|
|
) : null}
|
|
</form>
|
|
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
{COURSE_VIEW_OPTIONS.map((option) => {
|
|
const active = option.value === viewMode
|
|
|
|
return (
|
|
<button
|
|
key={option.value}
|
|
type="button"
|
|
onClick={() => onViewModeChange(option.value)}
|
|
className={`inline-flex items-center gap-2 rounded-full border px-4 py-2.5 text-sm font-semibold transition ${active ? 'border-sky-300/25 bg-sky-300/12 text-sky-100' : 'border-white/10 bg-white/[0.04] text-slate-200 hover:border-white/20 hover:bg-white/[0.07]'}`}
|
|
>
|
|
<i className={`fa-solid ${option.icon} text-xs`} />
|
|
<span>{option.label}</span>
|
|
</button>
|
|
)
|
|
})}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function PromptPreview({ item, compact = false }) {
|
|
if (item.preview_image_url) {
|
|
return <img src={item.preview_image_url} alt={item.title} className={`h-full w-full object-cover transition duration-500 ${compact ? 'group-hover:scale-[1.04]' : 'group-hover:scale-[1.03]'}`} />
|
|
}
|
|
|
|
return (
|
|
<div className="flex h-full items-center justify-center bg-[radial-gradient(circle_at_top_left,rgba(56,189,248,0.18),transparent_30%),linear-gradient(135deg,rgba(15,23,42,0.98),rgba(30,41,59,0.94))] p-6 text-center text-slate-300">
|
|
<div>
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.2em] text-slate-500">Prompt preview</p>
|
|
<p className="mt-3 text-sm font-semibold text-white">No image attached yet</p>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function PromptMeta({ item }) {
|
|
return (
|
|
<div className="flex flex-wrap gap-2">
|
|
{item.access_level ? <AccessBadge tier={item.access_level} className="px-3 py-1" /> : null}
|
|
{item.category_name ? <PromptFlag tone="warm">{item.category_name}</PromptFlag> : null}
|
|
{item.difficulty ? <PromptFlag>{item.difficulty}</PromptFlag> : null}
|
|
{item.aspect_ratio ? <PromptFlag>{item.aspect_ratio}</PromptFlag> : null}
|
|
{item.featured ? <PromptFlag tone="sky">Featured</PromptFlag> : null}
|
|
{item.prompt_of_week ? <PromptFlag tone="emerald">Prompt of week</PromptFlag> : null}
|
|
<PromptFlag tone={item.active ? 'sky' : 'default'}>{item.active ? 'Active' : 'Draft'}</PromptFlag>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function PromptGalleryCard({ item }) {
|
|
return (
|
|
<article className="group overflow-hidden rounded-[30px] border border-white/[0.08] bg-[linear-gradient(135deg,rgba(8,15,28,0.98),rgba(15,23,42,0.92))] shadow-[0_24px_80px_rgba(2,6,23,0.24)]">
|
|
<div className="grid gap-0 xl:grid-cols-[340px_minmax(0,1fr)]">
|
|
<div className="relative min-h-[250px] overflow-hidden border-b border-white/10 xl:min-h-full xl:border-b-0 xl:border-r xl:border-white/10">
|
|
<PromptPreview item={item} />
|
|
<div className="absolute inset-0 bg-[linear-gradient(180deg,rgba(2,6,23,0.04),rgba(2,6,23,0.32))]" />
|
|
<div className="absolute left-4 top-4 flex flex-wrap gap-2">
|
|
<AccessBadge tier={item.access_level || 'free'} className="px-3 py-1.5 text-[12px]" />
|
|
<PromptFlag>{Number(item.views_count || 0).toLocaleString()} views</PromptFlag>
|
|
<PromptFlag tone="warm">{item.comparisons_count || 0} comparisons</PromptFlag>
|
|
{item.slug ? <PromptFlag>{item.slug}</PromptFlag> : null}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex h-full flex-col justify-between p-6 lg:p-7">
|
|
<div>
|
|
<PromptMeta item={item} />
|
|
<h2 className="mt-4 text-2xl font-semibold tracking-[-0.04em] text-white">{item.title}</h2>
|
|
<p className="mt-3 max-w-3xl text-sm leading-7 text-slate-300">{item.excerpt || 'Add an excerpt to make this prompt easier to scan in moderation.'}</p>
|
|
|
|
{item.tags?.length ? (
|
|
<div className="mt-5 flex flex-wrap gap-2">
|
|
{item.tags.slice(0, 5).map((tag) => (
|
|
<span key={tag} className="rounded-full border border-white/10 bg-black/20 px-3 py-1 text-xs font-semibold uppercase tracking-[0.18em] text-slate-300">{tag}</span>
|
|
))}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
|
|
<div className="mt-6 flex flex-wrap items-center justify-between gap-4 border-t border-white/10 pt-5">
|
|
<div className="grid gap-3 sm:grid-cols-3">
|
|
<div>
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.2em] text-slate-500">Updated</p>
|
|
<p className="mt-1 text-sm font-semibold text-white">{formatDateLabel(item.updated_at)}</p>
|
|
</div>
|
|
<div>
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.2em] text-slate-500">Access</p>
|
|
<div className="mt-2"><AccessBadge tier={item.access_level || 'free'} /></div>
|
|
</div>
|
|
<div>
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.2em] text-slate-500">Status</p>
|
|
<p className="mt-1 text-sm font-semibold text-white">{item.active ? 'Visible' : 'Hidden'}</p>
|
|
</div>
|
|
</div>
|
|
|
|
<PromptActions item={item} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</article>
|
|
)
|
|
}
|
|
|
|
function PromptGridCard({ item }) {
|
|
return (
|
|
<article className="group overflow-hidden rounded-[28px] border border-white/[0.08] bg-[linear-gradient(180deg,rgba(255,255,255,0.04),rgba(15,23,42,0.18))] shadow-[0_18px_60px_rgba(2,6,23,0.18)]">
|
|
<div className="relative h-52 overflow-hidden border-b border-white/10">
|
|
<PromptPreview item={item} compact />
|
|
<div className="absolute inset-0 bg-[linear-gradient(180deg,rgba(2,6,23,0.02),rgba(2,6,23,0.34))]" />
|
|
<div className="absolute left-4 top-4">
|
|
<AccessBadge tier={item.access_level || 'free'} className="px-3 py-1.5 text-[12px]" />
|
|
</div>
|
|
</div>
|
|
<div className="p-5">
|
|
<PromptMeta item={item} />
|
|
<h2 className="mt-4 text-xl font-semibold tracking-[-0.04em] text-white">{item.title}</h2>
|
|
<p className="mt-3 text-sm leading-7 text-slate-300">{item.excerpt || 'No excerpt added yet.'}</p>
|
|
<div className="mt-5 flex items-center justify-between gap-3 text-sm text-slate-400">
|
|
<span>{formatDateLabel(item.updated_at)}</span>
|
|
<span>{Number(item.views_count || 0).toLocaleString()} views</span>
|
|
</div>
|
|
<div className="mt-5">
|
|
<PromptActions item={item} />
|
|
</div>
|
|
</div>
|
|
</article>
|
|
)
|
|
}
|
|
|
|
function PromptTable({ items }) {
|
|
return (
|
|
<div className="overflow-hidden rounded-[30px] border border-white/[0.08] bg-[linear-gradient(180deg,rgba(15,23,42,0.92),rgba(2,6,23,0.92))] shadow-[0_24px_80px_rgba(2,6,23,0.22)]">
|
|
<div className="overflow-x-auto">
|
|
<table className="min-w-full divide-y divide-white/10 text-left">
|
|
<thead className="bg-white/[0.04] text-[11px] font-semibold uppercase tracking-[0.22em] text-slate-400">
|
|
<tr>
|
|
<th className="px-5 py-4">Prompt</th>
|
|
<th className="px-5 py-4">Category</th>
|
|
<th className="px-5 py-4">Access</th>
|
|
<th className="px-5 py-4">Signals</th>
|
|
<th className="px-5 py-4">Views</th>
|
|
<th className="px-5 py-4">Updated</th>
|
|
<th className="px-5 py-4 text-right">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody className="divide-y divide-white/10 text-sm text-slate-200">
|
|
{items.map((item) => (
|
|
<tr key={item.id} className="align-top transition hover:bg-white/[0.03]">
|
|
<td className="px-5 py-4">
|
|
<div className="flex gap-4">
|
|
<div className="h-16 w-20 overflow-hidden rounded-2xl border border-white/10 bg-black/30 shrink-0">
|
|
<PromptPreview item={item} compact />
|
|
</div>
|
|
<div>
|
|
<p className="font-semibold text-white">{item.title}</p>
|
|
<p className="mt-1 max-w-md text-sm leading-6 text-slate-400">{item.excerpt || 'No excerpt added yet.'}</p>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<td className="px-5 py-4">{item.category_name || 'Uncategorized'}</td>
|
|
<td className="px-5 py-4"><AccessBadge tier={item.access_level || 'free'} className="px-3 py-1.5 text-[12px]" /></td>
|
|
<td className="px-5 py-4">
|
|
<div className="space-y-1">
|
|
<p>{item.comparisons_count || 0} comparisons</p>
|
|
<p>{item.difficulty || 'No difficulty'}</p>
|
|
<p>{item.active ? 'Active' : 'Draft'}</p>
|
|
</div>
|
|
</td>
|
|
<td className="px-5 py-4">{Number(item.views_count || 0).toLocaleString()}</td>
|
|
<td className="px-5 py-4">{formatDateLabel(item.updated_at)}</td>
|
|
<td className="px-5 py-4">
|
|
<div className="flex justify-end gap-2">
|
|
{item.preview_url ? <Link href={item.preview_url} className="rounded-full border border-[#ffcfbf]/20 bg-[#ffcfbf]/10 px-3 py-2 text-xs font-semibold text-[#fff0ea]">Preview</Link> : null}
|
|
<Link href={item.edit_url} className="rounded-full border border-white/10 bg-white/[0.04] px-3 py-2 text-xs font-semibold text-white">Edit</Link>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function PromptStatCard({ label, value, tone = 'default' }) {
|
|
const toneClass = tone === 'sky'
|
|
? 'border-sky-300/20 bg-sky-300/10 text-sky-100'
|
|
: tone === 'emerald'
|
|
? 'border-emerald-300/20 bg-emerald-300/10 text-emerald-100'
|
|
: tone === 'warm'
|
|
? 'border-amber-300/20 bg-amber-300/10 text-amber-100'
|
|
: 'border-white/10 bg-black/20 text-slate-300'
|
|
|
|
return (
|
|
<div className={`rounded-[24px] border px-5 py-4 ${toneClass}`}>
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.18em] opacity-70">{label}</p>
|
|
<p className="mt-2 text-2xl font-semibold tracking-[-0.04em] text-white">{value}</p>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function PromptSelect({ value, options = [], onChange }) {
|
|
return (
|
|
<select
|
|
value={value}
|
|
onChange={(event) => onChange(event.target.value)}
|
|
className="w-full rounded-2xl border border-white/10 bg-black/20 px-4 py-3 text-sm text-white focus:border-white/20 focus:outline-none focus:ring-1 focus:ring-white/10"
|
|
>
|
|
{options.map((option) => (
|
|
<option key={`${option.value}-${option.label}`} value={option.value} className="bg-slate-950 text-white">
|
|
{option.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
)
|
|
}
|
|
|
|
function PromptSearchBar({ filters, onChange, onSubmit, onReset, viewMode, onViewModeChange, filterOptions = {} }) {
|
|
return (
|
|
<div className="rounded-[28px] border border-white/10 bg-white/[0.03] p-4 shadow-[0_18px_50px_rgba(2,6,23,0.14)]">
|
|
<div className="flex flex-col gap-4 2xl:flex-row 2xl:items-start 2xl:justify-between">
|
|
<form onSubmit={onSubmit} className="flex-1 space-y-4">
|
|
<div className="grid gap-4 xl:grid-cols-[minmax(0,1.2fr)_repeat(3,minmax(0,0.8fr))]">
|
|
<div className="relative">
|
|
<i className="fa-solid fa-magnifying-glass absolute left-3.5 top-1/2 -translate-y-1/2 text-xs text-slate-500" />
|
|
<input
|
|
name="search"
|
|
value={filters.search}
|
|
onChange={(event) => onChange('search', event.target.value)}
|
|
placeholder="Search title, slug, excerpt, prompt text, or category…"
|
|
className="w-full rounded-2xl border border-white/10 bg-black/20 py-3 pl-9 pr-4 text-sm text-white placeholder:text-slate-600 focus:border-white/20 focus:outline-none focus:ring-1 focus:ring-white/10"
|
|
/>
|
|
</div>
|
|
<PromptSelect value={filters.category} onChange={(value) => onChange('category', value)} options={filterOptions.categories} />
|
|
<PromptSelect value={filters.access_level} onChange={(value) => onChange('access_level', value)} options={filterOptions.access} />
|
|
<PromptSelect value={filters.order} onChange={(value) => onChange('order', value)} options={filterOptions.order} />
|
|
</div>
|
|
|
|
<div className="grid gap-4 xl:grid-cols-4">
|
|
<PromptSelect value={filters.difficulty} onChange={(value) => onChange('difficulty', value)} options={filterOptions.difficulty} />
|
|
<PromptSelect value={filters.featured} onChange={(value) => onChange('featured', value)} options={filterOptions.featured} />
|
|
<PromptSelect value={filters.prompt_of_week} onChange={(value) => onChange('prompt_of_week', value)} options={filterOptions.promptOfWeek} />
|
|
<PromptSelect value={filters.active} onChange={(value) => onChange('active', value)} options={filterOptions.active} />
|
|
</div>
|
|
|
|
<div className="flex flex-wrap gap-3">
|
|
<button type="submit" className="rounded-2xl bg-sky-300/12 px-4 py-3 text-sm font-semibold text-sky-100 transition hover:bg-sky-300/16">
|
|
Apply filters
|
|
</button>
|
|
<button type="button" onClick={onReset} className="rounded-2xl border border-white/10 bg-white/[0.04] px-4 py-3 text-sm font-semibold text-white/80 transition hover:bg-white/[0.08]">
|
|
Reset
|
|
</button>
|
|
</div>
|
|
</form>
|
|
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
{PROMPT_VIEW_OPTIONS.map((option) => {
|
|
const active = option.value === viewMode
|
|
|
|
return (
|
|
<button
|
|
key={option.value}
|
|
type="button"
|
|
onClick={() => onViewModeChange(option.value)}
|
|
className={`inline-flex items-center gap-2 rounded-full border px-4 py-2.5 text-sm font-semibold transition ${active ? 'border-sky-300/25 bg-sky-300/12 text-sky-100' : 'border-white/10 bg-white/[0.04] text-slate-200 hover:border-white/20 hover:bg-white/[0.07]'}`}
|
|
>
|
|
<i className={`fa-solid ${option.icon} text-xs`} />
|
|
<span>{option.label}</span>
|
|
</button>
|
|
)
|
|
})}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function PromptHeroCollage({ items = [] }) {
|
|
const images = items
|
|
.map((item) => item?.preview_image_url)
|
|
.filter(Boolean)
|
|
.slice(0, 4)
|
|
|
|
if (!images.length) {
|
|
return (
|
|
<div className="flex min-h-[320px] items-center justify-center rounded-[32px] border border-white/10 bg-[radial-gradient(circle_at_top_left,rgba(56,189,248,0.14),transparent_24%),radial-gradient(circle_at_bottom_right,rgba(255,207,191,0.18),transparent_26%),linear-gradient(135deg,rgba(12,18,31,0.98),rgba(30,41,59,0.94))] px-8 text-center">
|
|
<div>
|
|
<p className="text-[11px] font-semibold uppercase tracking-[0.24em] text-slate-500">Prompt preview wall</p>
|
|
<p className="mt-4 text-lg font-semibold text-white">Preview images will appear here as prompts get covers.</p>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-3">
|
|
<div className="overflow-hidden rounded-[30px] border border-white/10 bg-black/20 shadow-[0_18px_45px_rgba(2,6,23,0.2)]">
|
|
<div className="aspect-[16/10] overflow-hidden">
|
|
<img src={images[0]} alt="" aria-hidden="true" className="h-full w-full object-cover" />
|
|
</div>
|
|
</div>
|
|
|
|
{images.length > 1 ? (
|
|
<div className="grid grid-cols-2 gap-3">
|
|
{images.slice(1, 4).map((image, index) => (
|
|
<div
|
|
key={`${image}-${index}`}
|
|
className="overflow-hidden rounded-[24px] border border-white/10 bg-black/20 shadow-[0_18px_45px_rgba(2,6,23,0.2)] aspect-square"
|
|
>
|
|
<img src={image} alt="" aria-hidden="true" className="h-full w-full object-cover" />
|
|
</div>
|
|
))}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
)
|
|
|
|
}
|
|
function CourseIndexContent({ title, subtitle, items, createUrl, filters = {}, summary = {} }) {
|
|
const { url } = usePage()
|
|
const courses = items?.data || []
|
|
const [viewMode, setViewMode] = useState('grid')
|
|
const [searchValue, setSearchValue] = useState(filters.search || '')
|
|
|
|
useEffect(() => {
|
|
setSearchValue(filters.search || '')
|
|
}, [filters.search])
|
|
|
|
useEffect(() => {
|
|
if (typeof window === 'undefined') return
|
|
|
|
const storedView = window.localStorage.getItem(COURSE_VIEW_STORAGE_KEY)
|
|
if (COURSE_VIEW_OPTIONS.some((option) => option.value === storedView)) {
|
|
setViewMode(storedView)
|
|
}
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
if (typeof window === 'undefined') return
|
|
window.localStorage.setItem(COURSE_VIEW_STORAGE_KEY, viewMode)
|
|
}, [viewMode])
|
|
|
|
const stats = useMemo(() => courseSummary(courses, summary), [courses, summary])
|
|
const currentPath = url.split('?')[0]
|
|
const hasSearch = Boolean(searchValue.trim())
|
|
const meta = items?.meta || {}
|
|
|
|
const handleSearch = (event) => {
|
|
event.preventDefault()
|
|
router.get(currentPath, { search: searchValue.trim() || undefined }, { preserveScroll: true, preserveState: true, replace: true })
|
|
}
|
|
|
|
const handleClearSearch = () => {
|
|
setSearchValue('')
|
|
router.get(currentPath, {}, { preserveScroll: true, preserveState: true, replace: true })
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<section className="overflow-hidden rounded-[38px] border border-white/[0.08] bg-[radial-gradient(circle_at_top_left,rgba(56,189,248,0.16),transparent_24%),radial-gradient(circle_at_bottom_right,rgba(255,207,191,0.16),transparent_24%),linear-gradient(135deg,rgba(4,9,18,0.98),rgba(15,23,42,0.92))] shadow-[0_28px_90px_rgba(2,6,23,0.28)]">
|
|
<div className="grid gap-8 p-6 xl:grid-cols-[minmax(0,1fr)_360px] xl:items-start xl:p-10">
|
|
<div>
|
|
<div className="flex flex-wrap gap-2">
|
|
<span className="rounded-full border border-[#ffcfbf]/20 bg-[#ffcfbf]/10 px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.24em] text-[#fff0ea]">Academy moderation</span>
|
|
<span className="rounded-full border border-white/10 bg-white/[0.05] px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.24em] text-slate-300">Course library</span>
|
|
</div>
|
|
|
|
<h2 className="mt-5 max-w-4xl text-4xl font-semibold tracking-[-0.055em] text-white md:text-5xl xl:text-6xl">{title}</h2>
|
|
<p className="mt-5 max-w-3xl text-base leading-8 text-slate-300 md:text-lg">{subtitle} Search courses quickly, switch between grid and table views, and jump into editing with a cleaner visual overview of covers, status, and lesson counts.</p>
|
|
|
|
<div className="mt-7 grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
|
|
<CourseStatCard label="Total" value={stats.total} tone="sky" />
|
|
<CourseStatCard label="Published" value={stats.published} tone="emerald" />
|
|
<CourseStatCard label="Featured" value={stats.featured} tone="warm" />
|
|
<CourseStatCard label="Drafts" value={stats.drafts} />
|
|
</div>
|
|
|
|
<div className="mt-7 flex flex-wrap gap-3">
|
|
<Link href={createUrl} className="inline-flex items-center gap-2 whitespace-nowrap rounded-full border border-sky-300/25 bg-sky-300/12 px-5 py-3 text-sm font-semibold text-sky-100"><i className="fa-solid fa-plus text-xs" />Create course</Link>
|
|
<Link href="/academy/courses" className="inline-flex items-center gap-2 whitespace-nowrap rounded-full border border-white/10 bg-white/[0.04] px-5 py-3 text-sm font-semibold text-white/85"><i className="fa-solid fa-book-open text-xs" />Open public courses</Link>
|
|
<span className="inline-flex items-center gap-2 whitespace-nowrap rounded-full border border-white/10 bg-white/[0.04] px-5 py-3 text-sm font-semibold text-white/85"><i className="fa-solid fa-layer-group text-xs" />{meta.total || courses.length} courses in view</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="xl:pt-2">
|
|
<CourseCoverWall items={courses} />
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<CourseSearchBar
|
|
value={searchValue}
|
|
onChange={setSearchValue}
|
|
onSubmit={handleSearch}
|
|
onClear={handleClearSearch}
|
|
viewMode={viewMode}
|
|
onViewModeChange={setViewMode}
|
|
/>
|
|
|
|
<div className="flex flex-wrap items-center justify-between gap-4">
|
|
<p className="text-sm text-slate-400">
|
|
{meta.total ? (
|
|
<>
|
|
Showing {meta.from || 0}-{meta.to || 0} of {meta.total} courses
|
|
{hasSearch ? <span className="ml-2 text-sky-200">filtered by “{searchValue.trim()}”</span> : null}
|
|
</>
|
|
) : (
|
|
'Manage Academy courses below. Changes clear Academy cache automatically.'
|
|
)}
|
|
</p>
|
|
<div className="flex flex-wrap gap-3">
|
|
<Link href={createUrl} className="inline-flex items-center gap-2 rounded-full border border-sky-300/25 bg-sky-300/12 px-5 py-3 text-sm font-semibold text-sky-100"><i className="fa-solid fa-plus text-xs" />Create course</Link>
|
|
</div>
|
|
</div>
|
|
|
|
{courses.length === 0 ? (
|
|
<div className="rounded-[28px] border border-white/[0.08] bg-white/[0.03] px-6 py-12 text-center text-slate-400">
|
|
{hasSearch ? (
|
|
<div className="space-y-3">
|
|
<p className="text-lg font-semibold text-white">No courses matched your search.</p>
|
|
<button type="button" onClick={handleClearSearch} className="rounded-full border border-white/10 bg-white/[0.04] px-4 py-2 text-sm font-semibold text-white">Clear search</button>
|
|
</div>
|
|
) : (
|
|
<div className="space-y-3">
|
|
<p className="text-lg font-semibold text-white">No courses exist yet.</p>
|
|
<Link href={createUrl} className="inline-flex items-center gap-2 rounded-full border border-sky-300/25 bg-sky-300/12 px-4 py-2 text-sm font-semibold text-sky-100"><i className="fa-solid fa-plus text-xs" />Create the first course</Link>
|
|
</div>
|
|
)}
|
|
</div>
|
|
) : viewMode === 'table' ? (
|
|
<CourseTable items={courses} />
|
|
) : (
|
|
<div className="grid gap-5 md:grid-cols-2 2xl:grid-cols-3">
|
|
{courses.map((item) => <CourseGridCard key={item.id} item={item} />)}
|
|
</div>
|
|
)}
|
|
|
|
<PaginationLinks links={items?.links} />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function PaginationLinks({ links = [] }) {
|
|
if (!Array.isArray(links) || links.length <= 3) return null
|
|
|
|
return (
|
|
<div className="mt-8 flex flex-wrap gap-2">
|
|
{links.map((link, index) => {
|
|
const label = paginationLabel(link.label)
|
|
const className = link.active
|
|
? 'border-sky-300/25 bg-sky-300/12 text-sky-100'
|
|
: 'border-white/10 bg-white/[0.04] text-slate-200 hover:border-white/20 hover:bg-white/[0.07]'
|
|
|
|
return link.url ? (
|
|
<Link key={`${label}-${index}`} href={link.url} className={`rounded-full border px-4 py-2 text-sm font-semibold transition ${className}`} preserveScroll>
|
|
{label}
|
|
</Link>
|
|
) : (
|
|
<span key={`${label}-${index}`} className="rounded-full border border-white/10 bg-black/20 px-4 py-2 text-sm font-semibold text-slate-500">{label}</span>
|
|
)
|
|
})}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function renderCrudCell(column, item) {
|
|
if (column === 'active') {
|
|
const active = Boolean(item.active)
|
|
|
|
return (
|
|
<span className={`inline-flex items-center gap-2 rounded-full border px-3 py-1 text-xs font-semibold uppercase tracking-[0.16em] ${active ? 'border-emerald-300/20 bg-emerald-300/10 text-emerald-100' : 'border-white/10 bg-white/[0.04] text-slate-300'}`}>
|
|
<i className={`fa-solid ${active ? 'fa-circle-check' : 'fa-circle-minus'} text-[11px]`} />
|
|
<span>{active ? 'Active' : 'Inactive'}</span>
|
|
</span>
|
|
)
|
|
}
|
|
|
|
if (column === 'course_names') {
|
|
const courseNames = Array.isArray(item.course_names) ? item.course_names.filter(Boolean) : []
|
|
|
|
if (courseNames.length === 0) {
|
|
return <span className="text-sm text-slate-400">Not attached</span>
|
|
}
|
|
|
|
return (
|
|
<div className="flex flex-wrap gap-2">
|
|
{courseNames.map((courseName) => (
|
|
<span key={courseName} className="rounded-full border border-white/10 bg-white/[0.04] px-3 py-1 text-xs font-semibold text-slate-200">{courseName}</span>
|
|
))}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (column === 'course_order') {
|
|
return <span className="text-sm text-white">{item.course_order ?? 'Not set'}</span>
|
|
}
|
|
|
|
return <p className="mt-1 text-sm text-white">{String(item[column] ?? '')}</p>
|
|
}
|
|
|
|
function PromptIndexContent({ title, subtitle, items, createUrl, filters = {}, summary = {}, filterOptions = {} }) {
|
|
const { url } = usePage()
|
|
const promptItems = items?.data || []
|
|
const stats = useMemo(() => promptSummary(promptItems, summary), [promptItems, summary])
|
|
const [viewMode, setViewMode] = useState('gallery')
|
|
const [query, setQuery] = useState({
|
|
search: filters.search || '',
|
|
category: filters.category || 'all',
|
|
featured: filters.featured || 'all',
|
|
prompt_of_week: filters.prompt_of_week || 'all',
|
|
active: filters.active || 'all',
|
|
access_level: filters.access_level || 'all',
|
|
difficulty: filters.difficulty || 'all',
|
|
order: filters.order || 'updated_desc',
|
|
})
|
|
|
|
useEffect(() => {
|
|
if (typeof window === 'undefined') return
|
|
|
|
const storedView = window.localStorage.getItem(PROMPT_VIEW_STORAGE_KEY)
|
|
if (PROMPT_VIEW_OPTIONS.some((option) => option.value === storedView)) {
|
|
setViewMode(storedView)
|
|
}
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
if (typeof window === 'undefined') return
|
|
window.localStorage.setItem(PROMPT_VIEW_STORAGE_KEY, viewMode)
|
|
}, [viewMode])
|
|
|
|
useEffect(() => {
|
|
setQuery({
|
|
search: filters.search || '',
|
|
category: filters.category || 'all',
|
|
featured: filters.featured || 'all',
|
|
prompt_of_week: filters.prompt_of_week || 'all',
|
|
active: filters.active || 'all',
|
|
access_level: filters.access_level || 'all',
|
|
difficulty: filters.difficulty || 'all',
|
|
order: filters.order || 'updated_desc',
|
|
})
|
|
}, [filters])
|
|
|
|
const currentPath = url.split('?')[0]
|
|
const meta = items?.meta || {}
|
|
const hasFilters = Boolean(
|
|
(query.search || '').trim()
|
|
|| query.category !== 'all'
|
|
|| query.featured !== 'all'
|
|
|| query.prompt_of_week !== 'all'
|
|
|| query.active !== 'all'
|
|
|| query.access_level !== 'all'
|
|
|| query.difficulty !== 'all'
|
|
|| query.order !== 'updated_desc'
|
|
)
|
|
|
|
const applyQuery = (nextQuery) => {
|
|
const payload = {}
|
|
|
|
if ((nextQuery.search || '').trim()) payload.search = nextQuery.search.trim()
|
|
if (nextQuery.category && nextQuery.category !== 'all') payload.category = nextQuery.category
|
|
if (nextQuery.featured && nextQuery.featured !== 'all') payload.featured = nextQuery.featured
|
|
if (nextQuery.prompt_of_week && nextQuery.prompt_of_week !== 'all') payload.prompt_of_week = nextQuery.prompt_of_week
|
|
if (nextQuery.active && nextQuery.active !== 'all') payload.active = nextQuery.active
|
|
if (nextQuery.access_level && nextQuery.access_level !== 'all') payload.access_level = nextQuery.access_level
|
|
if (nextQuery.difficulty && nextQuery.difficulty !== 'all') payload.difficulty = nextQuery.difficulty
|
|
if (nextQuery.order && nextQuery.order !== 'updated_desc') payload.order = nextQuery.order
|
|
|
|
router.get(currentPath, payload, { preserveScroll: true, preserveState: true, replace: true })
|
|
}
|
|
|
|
const handleFilterChange = (key, value) => {
|
|
setQuery((current) => ({ ...current, [key]: value }))
|
|
}
|
|
|
|
const handleSubmit = (event) => {
|
|
event.preventDefault()
|
|
applyQuery(query)
|
|
}
|
|
|
|
const handleReset = () => {
|
|
const nextQuery = {
|
|
search: '',
|
|
category: 'all',
|
|
featured: 'all',
|
|
prompt_of_week: 'all',
|
|
active: 'all',
|
|
access_level: 'all',
|
|
difficulty: 'all',
|
|
order: 'updated_desc',
|
|
}
|
|
|
|
setQuery(nextQuery)
|
|
router.get(currentPath, {}, { preserveScroll: true, preserveState: true, replace: true })
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
<section className="overflow-hidden rounded-[38px] border border-white/[0.08] bg-[radial-gradient(circle_at_top_left,rgba(56,189,248,0.16),transparent_24%),radial-gradient(circle_at_bottom_right,rgba(255,207,191,0.16),transparent_24%),linear-gradient(135deg,rgba(4,9,18,0.98),rgba(15,23,42,0.92))] shadow-[0_28px_90px_rgba(2,6,23,0.28)]">
|
|
<div className="grid gap-8 p-6 xl:grid-cols-[minmax(0,1fr)_360px] xl:items-start xl:p-10">
|
|
<div>
|
|
<div className="flex flex-wrap gap-2">
|
|
<span className="rounded-full border border-[#ffcfbf]/20 bg-[#ffcfbf]/10 px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.24em] text-[#fff0ea]">Academy moderation</span>
|
|
<span className="rounded-full border border-white/10 bg-white/[0.05] px-3 py-1 text-[11px] font-semibold uppercase tracking-[0.24em] text-slate-300">Prompt library</span>
|
|
</div>
|
|
|
|
<h2 className="mt-5 max-w-4xl text-4xl font-semibold tracking-[-0.055em] text-white md:text-5xl xl:text-6xl">{title}</h2>
|
|
<p className="mt-5 max-w-3xl text-base leading-8 text-slate-300 md:text-lg">{subtitle} Review prompts in a visual-first moderation surface, jump into edits quickly, and switch between gallery, grid, or table depending on the task in front of you.</p>
|
|
|
|
<div className="mt-7 grid gap-3 sm:grid-cols-3">
|
|
<div className="rounded-[24px] border border-white/10 bg-black/20 px-5 py-4">
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.18em] text-slate-500">Visual-first</p>
|
|
<p className="mt-2 text-sm font-semibold text-white">Curate covers and prompt outputs before opening the form.</p>
|
|
</div>
|
|
<div className="rounded-[24px] border border-white/10 bg-black/20 px-5 py-4">
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.18em] text-slate-500">Workflow-ready</p>
|
|
<p className="mt-2 text-sm font-semibold text-white">Switch between gallery, compact cards, and scan-heavy tables.</p>
|
|
</div>
|
|
<div className="rounded-[24px] border border-white/10 bg-black/20 px-5 py-4">
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.18em] text-slate-500">Comparison-aware</p>
|
|
<p className="mt-2 text-sm font-semibold text-white">Spot prompts with provider notes and attached result references.</p>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="mt-7 flex flex-nowrap gap-3 overflow-x-auto pb-1">
|
|
<Link href={createUrl} className="inline-flex items-center gap-2 whitespace-nowrap rounded-full border border-sky-300/25 bg-sky-300/12 px-5 py-3 text-sm font-semibold text-sky-100"><i className="fa-solid fa-plus text-xs" />Create prompt</Link>
|
|
<Link href="/academy/prompts" className="inline-flex items-center gap-2 whitespace-nowrap rounded-full border border-white/10 bg-white/[0.04] px-5 py-3 text-sm font-semibold text-white/85"><i className="fa-solid fa-book-open text-xs" />Open public library</Link>
|
|
<span className="inline-flex items-center gap-2 whitespace-nowrap rounded-full border border-white/10 bg-white/[0.04] px-5 py-3 text-sm font-semibold text-white/85"><i className="fa-solid fa-layer-group text-xs" />{stats.total} prompts in view</span>
|
|
</div>
|
|
|
|
<div className="mt-7 grid gap-3 sm:grid-cols-2 xl:grid-cols-4">
|
|
<PromptStatCard label="Active" value={stats.active} tone="emerald" />
|
|
<PromptStatCard label="Featured" value={stats.featured} tone="sky" />
|
|
<PromptStatCard label="Prompt of week" value={stats.promptOfWeek} tone="warm" />
|
|
<PromptStatCard label="Views on page" value={promptItems.reduce((count, item) => count + Number(item.views_count || 0), 0).toLocaleString()} />
|
|
</div>
|
|
|
|
<div className="mt-3 grid gap-3 sm:grid-cols-3">
|
|
<div className="rounded-[24px] border border-white/10 bg-black/20 px-5 py-4">
|
|
<div className="flex items-center justify-between gap-3">
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.18em] text-slate-500">Free access</p>
|
|
<AccessBadge tier="free" />
|
|
</div>
|
|
<p className="mt-2 text-2xl font-semibold tracking-[-0.04em] text-white">{stats.access.free}</p>
|
|
</div>
|
|
<div className="rounded-[24px] border border-white/10 bg-black/20 px-5 py-4">
|
|
<div className="flex items-center justify-between gap-3">
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.18em] text-slate-500">Creator access</p>
|
|
<AccessBadge tier="creator" />
|
|
</div>
|
|
<p className="mt-2 text-2xl font-semibold tracking-[-0.04em] text-white">{stats.access.creator}</p>
|
|
</div>
|
|
<div className="rounded-[24px] border border-white/10 bg-black/20 px-5 py-4">
|
|
<div className="flex items-center justify-between gap-3">
|
|
<p className="text-[10px] font-semibold uppercase tracking-[0.18em] text-slate-500">Pro access</p>
|
|
<AccessBadge tier="pro" />
|
|
</div>
|
|
<p className="mt-2 text-2xl font-semibold tracking-[-0.04em] text-white">{stats.access.pro}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="xl:pt-2">
|
|
<PromptHeroCollage items={promptItems} />
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<PromptSearchBar
|
|
filters={query}
|
|
onChange={handleFilterChange}
|
|
onSubmit={handleSubmit}
|
|
onReset={handleReset}
|
|
viewMode={viewMode}
|
|
onViewModeChange={setViewMode}
|
|
filterOptions={filterOptions}
|
|
/>
|
|
|
|
<div className="flex flex-wrap items-center justify-between gap-4">
|
|
<p className="text-sm text-slate-400">
|
|
{meta.total ? (
|
|
<>
|
|
Showing {meta.from || 0}-{meta.to || 0} of {meta.total} prompts
|
|
{hasFilters ? <span className="ml-2 text-sky-200">with active search or filters</span> : null}
|
|
</>
|
|
) : (
|
|
'Manage Academy content below. Changes clear Academy cache automatically.'
|
|
)}
|
|
</p>
|
|
<div className="flex flex-wrap gap-3">
|
|
<Link href="/academy/prompts" className="inline-flex items-center gap-2 rounded-full border border-white/10 bg-white/[0.04] px-5 py-3 text-sm font-semibold text-white/85"><i className="fa-solid fa-book-open text-xs" />View public library</Link>
|
|
<Link href={createUrl} className="inline-flex items-center gap-2 rounded-full border border-sky-300/25 bg-sky-300/12 px-5 py-3 text-sm font-semibold text-sky-100"><i className="fa-solid fa-plus text-xs" />Create prompt</Link>
|
|
</div>
|
|
</div>
|
|
|
|
{promptItems.length === 0 ? (
|
|
<div className="rounded-[28px] border border-white/[0.08] bg-white/[0.03] px-6 py-12 text-center text-slate-400">
|
|
{hasFilters ? (
|
|
<div className="space-y-3">
|
|
<p className="text-lg font-semibold text-white">No prompt templates matched these filters.</p>
|
|
<button type="button" onClick={handleReset} className="rounded-full border border-white/10 bg-white/[0.04] px-4 py-2 text-sm font-semibold text-white">Reset filters</button>
|
|
</div>
|
|
) : (
|
|
'No prompt templates exist yet.'
|
|
)}
|
|
</div>
|
|
) : viewMode === 'table' ? (
|
|
<PromptTable items={promptItems} />
|
|
) : viewMode === 'grid' ? (
|
|
<div className="grid gap-5 md:grid-cols-2 2xl:grid-cols-3">
|
|
{promptItems.map((item) => <PromptGridCard key={item.id} item={item} />)}
|
|
</div>
|
|
) : (
|
|
<div className="space-y-5">
|
|
{promptItems.map((item) => <PromptGalleryCard key={item.id} item={item} />)}
|
|
</div>
|
|
)}
|
|
|
|
<PaginationLinks links={items?.links} />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default function AcademyCrudIndex({ title, subtitle, items, columns, createUrl }) {
|
|
const flash = usePage().props.flash || {}
|
|
const resource = usePage().props.resource
|
|
const filters = usePage().props.filters || {}
|
|
const summary = usePage().props.summary || {}
|
|
const filterOptions = usePage().props.filterOptions || {}
|
|
|
|
return (
|
|
<AdminLayout title={title} subtitle={subtitle}>
|
|
<Head title={`Admin · ${title}`} />
|
|
|
|
{flash.success ? <div className="mb-6 rounded-2xl border border-emerald-300/20 bg-emerald-300/10 px-4 py-3 text-sm text-emerald-100">{flash.success}</div> : null}
|
|
|
|
{resource === 'courses' ? (
|
|
<CourseIndexContent title={title} subtitle={subtitle} items={items} createUrl={createUrl} filters={filters} summary={summary} />
|
|
) : resource === 'prompts' ? (
|
|
<PromptIndexContent title={title} subtitle={subtitle} items={items} createUrl={createUrl} filters={filters} summary={summary} filterOptions={filterOptions} />
|
|
) : (
|
|
<>
|
|
<div className="mb-6 flex items-center justify-between gap-4">
|
|
<p className="text-sm text-slate-400">Manage Academy content below. Changes clear Academy cache automatically.</p>
|
|
<Link href={createUrl} className="rounded-full border border-sky-300/25 bg-sky-300/12 px-5 py-3 text-sm font-semibold text-sky-100">Create record</Link>
|
|
</div>
|
|
|
|
{(items?.data || []).length === 0 ? (
|
|
<div className="rounded-[28px] border border-white/[0.08] bg-white/[0.03] px-6 py-12 text-center text-slate-400">No records exist yet.</div>
|
|
) : (
|
|
<div className="space-y-4">
|
|
{items.data.map((item) => (
|
|
<div key={item.id} className="rounded-[28px] border border-white/[0.08] bg-white/[0.03] p-5">
|
|
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_auto] lg:items-center">
|
|
<div className="grid gap-2 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-6">
|
|
{columns.map((column) => (
|
|
<div key={column}>
|
|
<p className="text-[11px] font-semibold uppercase tracking-[0.2em] text-slate-500">{column.replaceAll('_', ' ')}</p>
|
|
<div className="mt-1">{renderCrudCell(column, item)}</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
|
|
<div className="flex flex-wrap gap-3 lg:justify-end">
|
|
{item.builder_url ? <Link href={item.builder_url} className="rounded-full border border-amber-300/20 bg-amber-300/10 px-4 py-2 text-sm font-semibold text-amber-100">Builder</Link> : null}
|
|
<Link href={item.edit_url} className="rounded-full border border-white/10 bg-white/[0.04] px-4 py-2 text-sm font-semibold text-white">Edit</Link>
|
|
<button type="button" onClick={() => { if (!window.confirm('Delete this record?')) return; router.delete(item.destroy_url, { preserveScroll: true }) }} className="rounded-full border border-rose-300/20 bg-rose-300/10 px-4 py-2 text-sm font-semibold text-rose-100">Delete</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
</>
|
|
)}
|
|
</AdminLayout>
|
|
)
|
|
}
|