import { useEffect, useState } from "react"; import {ButtonPrimary} from "../../../../components/ui/buttons/ButtonPrimary"; import InputText from "../../../../components/ui/input/InputText"; import { defaultLandingPage } from "../../utils/defaultPages/defaultLandingPage"; import { PageBlockDto } from "../../dtos/PageBlockDto"; import { defaultPricingPage } from "../../utils/defaultPages/defaultPricingPage"; import { useApp } from "../../../../hooks"; type TemplateDto = { title: string; blocks: PageBlockDto[]; }; export default function PageBlocksTemplateEditor({ items, onSelected }: { items: PageBlockDto[]; onSelected: (items: PageBlockDto[]) => void }) { const { t } = useApp(); const [templates, setTemplates] = useState([]); const [currentJson, setCurrentJson] = useState(""); useEffect(() => { const templates: TemplateDto[] = [ { title: "Current", blocks: items }, { title: "Landing Page", blocks: defaultLandingPage({ t }) }, { title: "Pricing Page", blocks: defaultPricingPage({ t }) }, { title: "Empty", blocks: [] }, ]; setCurrentJson(JSON.stringify(templates[0].blocks, null, "\t")); setTemplates(templates); }, [items, t]); function onSave() { // const jsonBlocks = PageBlockUtils.downloadBlocks(currentBlocks); try { const blocks = JSON.parse(currentJson) as PageBlockDto[]; onSelected(blocks); } catch (e: any) { alert("Error: " + e.message); } } return (
{templates.map((t) => ( ))}
Save
); }