// R-P5 Interim-UI (AD-28) — connect/reconnect wizard as a REAL ~/ui Dialog // (D-P5 "Connection-Setup-Wizard", archetype A5+A6, size M 720) with a // StepperHorizontal: prerequisites → auto-generated credential form (from the // app's connectionSchema, secret fields with reveal toggle) → review & connect. // Submit posts the existing connect/reconnect route action (adapter validation + // health check server-side). OAuth2 apps without credential fields show an // interim hint (the guided OAuth redirect ships with the module phases P14/P16). // Final Subframe optics land as a tracked design-nachzug once David's D-P5 ships. import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { FeatherEye, FeatherEyeOff } from "@subframe/core"; import type { AppCredentialField } from "@hivegrid/integrations"; import { Alert } from "~/ui/components/Alert"; import { Button } from "~/ui/components/Button"; import { Dialog } from "~/ui/components/Dialog"; import { IconButton } from "~/ui/components/IconButton"; import { StepperHorizontal } from "~/ui/components/StepperHorizontal"; import { TextInput } from "~/ui/components/TextInput"; export type ConnectWizardMode = { type: "connect" } | { type: "reconnect"; connectionId: string; label: string }; export type ConnectWizardSubmit = { label: string; credentials: Record }; export type ConnectWizardDialogProps = { open: boolean; mode: ConnectWizardMode; appTitleKey: string; connectionType: string; credentialFields: readonly AppCredentialField[]; submitting: boolean; errorMessage: string | null; onSubmit: (input: ConnectWizardSubmit) => void; onClose: () => void; }; const STEPS = ["prerequisites", "credentials", "confirm"] as const; export function ConnectWizardDialog({ open, mode, appTitleKey, connectionType, credentialFields, submitting, errorMessage, onSubmit, onClose }: ConnectWizardDialogProps) { const { t } = useTranslation(); const [step, setStep] = useState(0); const [label, setLabel] = useState(mode.type === "reconnect" ? mode.label : ""); const [values, setValues] = useState>({}); const [revealed, setRevealed] = useState>(new Set()); // Reset the wizard whenever it (re)opens or the target changes (the parent // passes a fresh `mode` object per open, so state identity stays stable // across mere re-renders like submitting toggles). useEffect(() => { if (open) { setStep(0); setLabel(mode.type === "reconnect" ? mode.label : ""); setValues({}); setRevealed(new Set()); } }, [open, mode]); const isOauthWithoutForm = connectionType === "oauth2" && credentialFields.length === 0; const labelMissing = mode.type === "connect" && label.trim().length === 0; const requiredMissing = credentialFields.some((field) => field.required && !(values[field.name] ?? "").trim()); const credentialsIncomplete = labelMissing || requiredMissing; function toggleReveal(name: string) { setRevealed((prev) => { const next = new Set(prev); if (next.has(name)) next.delete(name); else next.add(name); return next; }); } function submit() { onSubmit({ label: label.trim(), credentials: values }); } return ( (nextOpen ? undefined : onClose())}>
{mode.type === "reconnect" ? t("integrations.wizard.reconnectTitle", { app: t(appTitleKey) }) : t("integrations.wizard.title", { app: t(appTitleKey) })} {errorMessage ? : null}
{STEPS.map((key, index) => ( ))} {step === 0 ? (
{t("integrations.wizard.prerequisites.body", { app: t(appTitleKey) })} {isOauthWithoutForm ? ( ) : null}
) : null} {step === 1 ? (
{mode.type === "connect" ? ( setLabel(event.target.value)} required data-ui-id="ui.integrations.app.wizard.label" /> ) : ( {t("integrations.wizard.reconnectHint", { label: mode.label })} )} {credentialFields.map((field) => { const isSecret = field.type === "secret"; const shown = revealed.has(field.name); return ( : } onClick={() => toggleReveal(field.name)} aria-label={t(shown ? "integrations.wizard.hideSecret" : "integrations.wizard.revealSecret")} /> ) : undefined } > setValues((prev) => ({ ...prev, [field.name]: event.target.value }))} required={field.required} data-wizard-field={field.name} /> ); })} {credentialFields.length === 0 && !isOauthWithoutForm ? ( {t("integrations.wizard.noFields")} ) : null} {isOauthWithoutForm ? : null}
) : null} {step === 2 ? (
{t("integrations.wizard.confirm.body")} {t("integrations.wizard.label")}: {mode.type === "reconnect" ? mode.label : label || "—"} {credentialFields.map((field) => ( {t(field.labelKey)}: {(values[field.name] ?? "").trim() ? (field.type === "secret" ? "••••••" : values[field.name]) : "—"} ))}
) : null}
{step > 0 ? ( ) : null} {step < STEPS.length - 1 ? ( ) : ( )}
); }