make the connection settings reachable at /gitea/connection

The form appeared only when nothing was configured, so once a token was saved
there was no way back to it — a member who mistyped theirs, or anyone rotating
one, had nowhere to go. On a single-user machine that is an annoyance; on a
company one it is the ordinary case, because every member has a token of their
own to set.

Uses the route pair the platform already generates for every plugin, so this
needed no platform change. A plug icon beside the open-in-new-tab button, as a
real Link rather than a button, because it is navigation and should be
cmd-clickable.

Saving returns to the frame — otherwise you are left looking at the form you
just submitted, which reads as nothing having happened.

The two halves were already right: the panel shows only the token field when
isOwner is false, and getResolvedServiceCredentials gives a member the owner's
URL with their OWN secret, never the owner's.
This commit is contained in:
officer
2026-08-19 09:58:30 +00:00
parent fe67de0281
commit c31f95155f
2 changed files with 42 additions and 15 deletions
+17 -4
View File
@@ -1,4 +1,5 @@
import { useState } from 'react';
import { useNavigate } from 'react-router';
import { Loader2 } from 'lucide-react';
import { useClient } from 'hooks/useClient';
import { Button } from '@/components/ui/button';
@@ -34,6 +35,7 @@ type Props = { state: ConnectionState; onSaved: () => void };
export const GiteaConnection = ({ state, onSaved }: Props) => {
const { put } = useClient();
const navigate = useNavigate();
// Loopback is the right default and worth putting in front of someone: the sidecar fetches
// SERVER-SIDE, so `localhost` means the machine Officer runs on. It needs no TLS and never leaves the
// box — where the public URL would take the same traffic out and back.
@@ -48,6 +50,9 @@ export const GiteaConnection = ({ state, onSaved }: Props) => {
try {
await put('/gitea/_config', state.isOwner === false ? { token } : { url, token });
onSaved();
// Back to the frame. Saving from `/gitea/connection` otherwise leaves you looking at the form you
// just submitted, which reads as nothing having happened.
navigate('/gitea');
} catch (err) {
setError(err instanceof Error ? err.message : 'could not save');
} finally {
@@ -91,10 +96,18 @@ export const GiteaConnection = ({ state, onSaved }: Props) => {
{error && <p className="text-xs text-destructive">{error}</p>}
<Button onClick={save} disabled={busy || ((!state.configured || state.unreadable) && !token)}>
{busy ? <Loader2 className="mr-2 h-3.5 w-3.5 animate-spin" /> : null}
{state.configured ? 'Save' : 'Connect'}
</Button>
<div className="flex gap-2">
<Button onClick={save} disabled={busy || ((!state.configured || state.unreadable) && !token)}>
{busy ? <Loader2 className="mr-2 h-3.5 w-3.5 animate-spin" /> : null}
{state.configured ? 'Save' : 'Connect'}
</Button>
{/* Only once there is something to go back TO. */}
{state.configured && !state.unreadable ? (
<Button variant="outline" onClick={() => navigate('/gitea')} disabled={busy}>
Cancel
</Button>
) : null}
</div>
</div>
);
};