import { useState } from "react"; import { checkPagesDomain, disablePages, savePages, setPagesDomain } from "~/fns/pages"; import type { getPages } from "~/fns/pages"; import { useAction } from "~/hooks/use-action"; import { Badge, Panel } from "~/components/ui/Primitives"; import { Button } from "~/components/ui/Button"; import { CheckboxField, ErrorBanner, SelectField, TextField } from "~/components/ui/Field"; export type PagesData = Awaited>; type RepoParams = { owner: string; repo: string }; const SOURCES = [ { value: "branch", label: "Deploy from a branch" }, { value: "workflow", label: "Deploy from a workflow artifact" }, ] as const; export function PagesSourceForm({ data, params }: { data: PagesData; params: RepoParams }) { const save = useAction(savePages); const disable = useAction(disablePages); const [source, setSource] = useState<"branch" | "workflow">(data.site?.source ?? "branch"); const branchOptions = (data.branches.length ? data.branches : [data.defaultBranch]).map((name) => ({ value: name, label: name, })); return ( Enabled}>
{ event.preventDefault(); const form = new FormData(event.currentTarget); await save.run({ data: { ...params, source, branch: String(form.get("branch") ?? data.defaultBranch), folder: String(form.get("folder") ?? ""), artifactName: String(form.get("artifactName") ?? "pages"), spa: form.get("spa") === "on", previews: form.get("previews") === "on", }, }); }} > setSource(event.target.value === "workflow" ? "workflow" : "branch")} /> {source === "workflow" && ( )}
{data.site && ( )}
); } export function PagesDomainForm({ data, params }: { data: PagesData; params: RepoParams }) { const update = useAction(setPagesDomain); const check = useAction(checkPagesDomain); const [details, setDetails] = useState>>(null); const site = data.site; if (!site) return null; if (!data.customDomainsEnabled) { return (

Custom domains are not configured on this forge.

); } return ( {site.domainStatus} ) } >
{ event.preventDefault(); const domain = String(new FormData(event.currentTarget).get("domain") ?? "").trim(); await update.run({ data: { ...params, domain: domain || null } }); }} >
{site.customDomain && ( )}
{details && (
Status: {details.status}
{details.errors.map((error) => (
{error}
))} {details.verification && (
{details.verification.type.toUpperCase()} {details.verification.name} = {details.verification.value}
)}
)}
); }