{/* The command is a value, not copy: writing it into the catalog lets the
pseudo-locale transliterate it into something the user cannot type. */}
Sign in with {"{{command}}"}, then reopen this dialog.
);
}
// Plain function, so `t` is threaded in rather than taken from the hook. The
// guard never inspects this shape — `mode: "jsx-only"` only sees JSX literals.
function accountPlaceholder(t: TFunction, loading: boolean, loadError: string | null) {
if (loading) return t("github:loadingAccounts");
if (loadError) return t("github:accountsUnavailable");
return t("github:noGhAccountsFound");
}
export function GitHubCLIForm({
workspaceId,
onAccountChange,
disabled,
}: {
workspaceId: string;
onAccountChange: (account: GitHubCLIAccount | null) => void;
disabled?: boolean;
}) {
const { t } = useTranslation();
const [accounts, setAccounts] = useState([]);
const [selected, setSelected] = useState("");
const [loadError, setLoadError] = useState(null);
const [loading, setLoading] = useState(true);
const onAccountChangeRef = useRef(onAccountChange);
onAccountChangeRef.current = onAccountChange;
useEffect(() => {
let current = true;
setAccounts([]);
setSelected("");
setLoadError(null);
setLoading(true);
onAccountChangeRef.current(null);
fetchGitHubCLIAccounts(workspaceId, { cache: "no-store" })
.then((items) => {
if (!current) return;
setAccounts(items);
const preferred =
items.find((item) => item.selected) ?? items.find((item) => item.active) ?? items[0];
setSelected(preferred ? `${preferred.host}\n${preferred.login}` : "");
})
.catch((error) => {
if (!current) return;
setAccounts([]);
setLoadError(
error instanceof Error ? error.message : t("github:unexpectedResponseFromTheServer"),
);
})
.finally(() => current && setLoading(false));
return () => {
current = false;
};
}, [workspaceId]);
const account = useMemo(() => {
const [host, login] = selected.split("\n");
return accounts.find((item) => item.host === host && item.login === login);
}, [accounts, selected]);
useEffect(() => {
onAccountChangeRef.current(account ?? null);
}, [account]);
return (