Show content automation action for all page views
This commit is contained in:
@@ -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