import { Navigate, createFileRoute } from "@tanstack/react-router"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { useEffect, useState } from "react"; import type { AutofixMode, TeamSettings, TriggerMode } from "@/lib/api"; import { AppShell, SettingsRow, SettingsSection } from "@/components/AppShell"; import { ReviewStylesPanel } from "@/components/ReviewStylesPanel"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Skeleton } from "@/components/ui/skeleton"; import { Switch } from "@/components/ui/switch"; import { api } from "@/lib/api"; import { useSession } from "@/lib/session"; export const Route = createFileRoute("/review")({ component: ReviewPage }); const TRIGGER_MODES: Array<{ value: TriggerMode; label: string; description: string }> = [ { value: "every_push", label: "Every Push", description: "Review every push to a PR" }, { value: "ready_for_review", label: "Ready For Review", description: "Only when the PR is marked ready for review", }, { value: "manual", label: "Manual", description: "Review only when explicitly invoked" }, ]; const AUTOFIX_MODES: Array<{ value: AutofixMode; label: string }> = [ { value: "off", label: "Off" }, { value: "low", label: "Low" }, { value: "medium", label: "Medium" }, { value: "high", label: "High" }, ]; const DEFAULT_SETTINGS: TeamSettings = { trigger_mode: "every_push", review_draft_prs: false, pr_summaries: true, autofix_mode: "off", autofix_severity_threshold: "medium", }; function ReviewPage() { const session = useSession(); const qc = useQueryClient(); const settings = useQuery({ queryKey: ["teamSettings"], queryFn: api.getTeamSettings, enabled: !!session.data, }); const [local, setLocal] = useState(DEFAULT_SETTINGS); const [error, setError] = useState(null); useEffect(() => { if (settings.data) setLocal(settings.data); }, [settings.data]); const save = useMutation({ mutationFn: (body: TeamSettings) => api.saveTeamSettings(body), onSuccess: (saved) => { qc.setQueryData(["teamSettings"], saved); setError(null); }, onError: (e: Error) => setError(e.message), }); if (session.isLoading) { return (
); } if (!session.data) return ; const current: TeamSettings = local; const canEdit = session.data.is_admin; const persist = (patch: Partial) => { const next: TeamSettings = { ...current, ...patch }; setLocal(next); if (canEdit) save.mutate(next); }; const triggerDescription = TRIGGER_MODES.find((m) => m.value === current.trigger_mode)?.description ?? "Open SWE Review will automatically review every push to a PR"; return (
persist({ trigger_mode: v as TriggerMode })} disabled={!canEdit} > {TRIGGER_MODES.map((m) => ( {m.label} ))} } /> persist({ review_draft_prs: v })} disabled={!canEdit} /> } /> persist({ pr_summaries: v })} disabled={!canEdit} /> } /> persist({ autofix_mode: v as AutofixMode })} disabled={!canEdit} > {AUTOFIX_MODES.map((m) => ( {m.label} ))} } /> persist({ autofix_severity_threshold: v as AutofixMode }) } disabled={!canEdit} > {AUTOFIX_MODES.map((m) => ( {m.label} ))} } />
{!canEdit && (

These settings are read-only. Ask a workspace admin to change them.

)} {error &&

{error}

}
); }