import { useTranslation } from "react-i18next"; import { Plus, Trash2 } from "lucide-react"; import { Input } from "@/components/input"; import { PasswordInput } from "@/components/password-input"; import { Switch } from "@/components/switch"; import type { SyncBasicAuth, SyncProxyHeader } from "@/api/sync-api"; interface ProxySettingsFieldsProps { customHeaders: SyncProxyHeader[]; basicAuth: SyncBasicAuth | null; onChange: (next: { customHeaders?: SyncProxyHeader[]; basicAuth?: SyncBasicAuth | null; }) => void; } /** * What a reverse proxy in front of the server wants: extra headers (a * Cloudflare Access service token, a gateway key) and basic auth. */ export function ProxySettingsFields({ customHeaders, basicAuth, onChange, }: ProxySettingsFieldsProps) { const { t } = useTranslation(); const setHeader = (index: number, patch: Partial) => { onChange({ customHeaders: customHeaders.map((header, i) => i === index ? { ...header, ...patch } : header, ), }); }; return (
{t("sync.proxy.headersTitle")} {t("sync.proxy.headersHint")}
{customHeaders.map((header, index) => (
setHeader(index, { name: event.target.value }) } /> setHeader(index, { value: event.target.value }) } />
))}
{t("sync.proxy.basicAuthTitle")} {t("sync.proxy.basicAuthHint")}
onChange({ basicAuth: checked ? { username: "", password: "" } : null, }) } />
{basicAuth && (
onChange({ basicAuth: { ...basicAuth, username: event.target.value }, }) } /> onChange({ basicAuth: { ...basicAuth, password: event.target.value }, }) } />
)}
); }