Show content automation action for all page views
This commit is contained in:
@@ -40,7 +40,7 @@ export default async function OverviewPage(props: PageProps<"/">) {
|
||||
const openDays = Array.from({ length: 7 }, (_, i) => addDays(week, i)).filter(d => d >= today).length;
|
||||
const planFor = ctx.selected && editable.includes(ctx.selected.id) && openDays > 0 ? ctx.selected : null;
|
||||
return <>
|
||||
<PageTitle title="แผนคอนเทนต์" subtitle={ctx.selected ? `จัดคิวโพสต์ของ ${ctx.selected.name}` : "ทุกไอเดีย ทุกเพจ ในแผนเดียว · เวลาไทย"} actions={editable.length > 0 ? <>{planFor && <ContentAutoLauncher pageId={planFor.id} />}<Link href="/posts/new" className="btn btn-primary"><Icon name="plus" /> สร้างโพสต์</Link></> : undefined} />
|
||||
<PageTitle title="แผนคอนเทนต์" subtitle={ctx.selected ? `จัดคิวโพสต์ของ ${ctx.selected.name}` : "ทุกไอเดีย ทุกเพจ ในแผนเดียว · เวลาไทย"} actions={editable.length > 0 ? <><ContentAutoLauncher pages={ctx.pages.filter((page) => editable.includes(page.id)).map(({ id, name }) => ({ id, name }))} initialPageId={ctx.selected?.id} /><Link href="/posts/new" className="btn btn-primary"><Icon name="plus" /> สร้างโพสต์</Link></> : undefined} />
|
||||
<div className="flex flex-wrap items-center gap-3 text-[12px] text-ink-3">
|
||||
<span>{posts.length} โพสต์ในสัปดาห์นี้</span><span className="w-1 h-1 bg-line rounded-full" /><span>{tray.length}{tray.length === 50 ? "+" : ""} โพสต์ยังไม่วางวัน</span>
|
||||
{pending > 0 && <Link href="/posts?status=PENDING_APPROVAL" className="pill pill-amber">รออนุมัติ {pending}</Link>}
|
||||
|
||||
@@ -4,8 +4,9 @@ import { useEffect, useState } from "react";
|
||||
import { Icon } from "./Icon";
|
||||
import { ContentAutoForm } from "./ContentAutoForm";
|
||||
|
||||
export function ContentAutoLauncher({ pageId }: { pageId: string }) {
|
||||
export function ContentAutoLauncher({ pages, initialPageId }: { pages: { id: string; name: string }[]; initialPageId?: string }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [pageId, setPageId] = useState(initialPageId ?? pages[0]?.id ?? "");
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const close = (event: KeyboardEvent) => { if (event.key === "Escape") setOpen(false); };
|
||||
@@ -18,7 +19,8 @@ export function ContentAutoLauncher({ pageId }: { pageId: string }) {
|
||||
{open && <div className="fixed inset-0 z-50 bg-ink/35 p-3 sm:p-6 overflow-y-auto" role="presentation" onMouseDown={(event) => { if (event.target === event.currentTarget) setOpen(false); }}>
|
||||
<section role="dialog" aria-modal="true" aria-labelledby="content-auto-title" className="bg-paper border border-line rounded-2xl shadow-xl w-full max-w-3xl mx-auto my-4 p-4 sm:p-6">
|
||||
<div className="flex items-center justify-between gap-3 mb-4 pb-3 border-b border-line"><h2 id="content-auto-title" className="font-semibold text-[16px]">ตั้งค่าแผนอัตโนมัติ</h2><button type="button" className="btn btn-ghost btn-sm" onClick={() => setOpen(false)} aria-label="ปิดหน้าต่าง">ปิด</button></div>
|
||||
<ContentAutoForm pageId={pageId} />
|
||||
{pages.length > 1 && <label className="field mb-5"><span>เพจที่ต้องการวางแผน</span><select className="select" value={pageId} onChange={(event) => setPageId(event.target.value)}>{pages.map((page) => <option key={page.id} value={page.id}>{page.name}</option>)}</select></label>}
|
||||
{pageId && <ContentAutoForm key={pageId} pageId={pageId} />}
|
||||
</section>
|
||||
</div>}
|
||||
</>;
|
||||
|
||||
Reference in New Issue
Block a user