"use client"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@kandev/ui/dialog"; import { Button } from "@kandev/ui/button"; import { Input } from "@kandev/ui/input"; import { Label } from "@kandev/ui/label"; import { Switch } from "@kandev/ui/switch"; import type { WorkflowSyncController, WorkflowSyncFormState, } from "@/hooks/domains/settings/use-workflow-sync"; const HELP_TEXT = "The directory should contain workflow export files (.yml/.yaml/.json) in the kandev_workflow format — the same format produced by workflow export."; type RepoUrlFieldProps = { url: string; invalid: boolean; resolved: string; onChange: (value: string) => void; }; // RepoUrlField is the primary input: a full GitHub link (optionally with // /tree//) that resolves into the stored owner, repo, // branch, and directory. The resolved target is echoed underneath so the // structured fields stay visible to the user. function RepoUrlField({ url, invalid, resolved, onChange }: RepoUrlFieldProps) { return (
onChange(e.target.value)} aria-invalid={invalid} /> {invalid ? (

Not a recognized GitHub repository link.

) : (

{resolved || "Paste a GitHub link — /tree/… links carry the branch and directory too."}

)}
); } type FieldsProps = { form: WorkflowSyncFormState; update: (key: K, value: WorkflowSyncFormState[K]) => void; }; // PollFields is a single compact row: the auto-sync switch and, when on, the // interval right beside it. The branch needs no field of its own — it comes // from the pasted link (or defaults to main) and is echoed in the resolved // summary under the link input. function PollFields({ form, update }: FieldsProps) { return (
update("poll_enabled", checked)} className="cursor-pointer" /> {form.poll_enabled && (
update("interval_seconds", Number(e.target.value) || 0)} /> seconds
)}

{form.poll_enabled ? "Checks the repository on this interval (minimum 60s)." : "Syncs only run when you press Sync now."}

); } type WorkflowSyncDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; sync: WorkflowSyncController; }; // WorkflowSyncDialog holds the GitHub Sync configuration form. It closes // itself after a successful save or removal; failures keep it open with the // error surfaced via toast. export function WorkflowSyncDialog({ open, onOpenChange, sync }: WorkflowSyncDialogProps) { const hasConfig = !!sync.config; const intervalInvalid = sync.form.poll_enabled && (!Number.isInteger(sync.form.interval_seconds) || sync.form.interval_seconds < 60); const disableSave = sync.saving || sync.loading || sync.urlInvalid || intervalInvalid || !sync.form.repo_owner.trim() || !sync.form.repo_name.trim(); const resolved = sync.form.repo_owner ? `Syncing ${sync.form.repo_owner}/${sync.form.repo_name} @ ${sync.form.branch || "main"} — directory ${sync.form.path || "(repository root)"}.` : ""; const handleSave = async () => { if (await sync.handleSave()) onOpenChange(false); }; const handleRemove = async () => { if (await sync.handleDelete()) onOpenChange(false); }; return ( GitHub Sync Automatically sync workflow definitions from a GitHub repository into this workspace.

{HELP_TEXT}

{hasConfig && ( )}
); } function saveLabel(saving: boolean, hasConfig: boolean): string { if (saving) return "Saving..."; return hasConfig ? "Update" : "Save"; }