"use client"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; interface PostizPushModalProps { assetIds: string[]; onClose: () => void; } export function PostizPushModal({ assetIds, onClose }: PostizPushModalProps) { const [scheduledAt, setScheduledAt] = useState(() => { const d = new Date(); d.setHours(d.getHours() + 1); return d.toISOString().slice(0, 16); }); const [loading, setLoading] = useState(false); const [result, setResult] = useState(null); async function handlePush() { setLoading(true); const res = await fetch("/api/postiz", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ assetIds, scheduledAt: new Date(scheduledAt).toISOString(), }), }); const data = await res.json(); if (res.ok) { const scheduled = data.results?.filter( (r: { status: string }) => r.status === "scheduled" ).length; setResult(`${scheduled} asset(s) scheduled successfully.`); setTimeout(onClose, 2000); } else { setResult(`Error: ${data.error || "Failed to push"}`); } setLoading(false); } return ( Push to Postiz Schedule {assetIds.length} asset(s) for publishing via Postiz.
setScheduledAt(e.target.value)} />
{result && (

{result}

)}
); }