import { createFileRoute, Link } from "@tanstack/react-router"; import { useRef, useState } from "react"; import { useApiKeys, useAuth, useChangePassword, useCreateApiKey, useDeleteApiKey, } from "../hooks/useAuth"; import { useCurrency } from "../hooks/useCurrency"; import { useExportItems, useImportItems } from "../hooks/useItems"; import { useUpdateSetting } from "../hooks/useSettings"; import { useWeightUnit } from "../hooks/useWeightUnit"; import type { Currency, WeightUnit } from "../lib/formatters"; const UNITS: WeightUnit[] = ["g", "oz", "lb", "kg"]; const CURRENCIES: { value: Currency; label: string }[] = [ { value: "USD", label: "$" }, { value: "EUR", label: "€" }, { value: "GBP", label: "£" }, { value: "JPY", label: "¥" }, { value: "CAD", label: "CA$" }, { value: "AUD", label: "A$" }, ]; export const Route = createFileRoute("/settings")({ component: SettingsPage, }); function ChangePasswordSection() { const changePassword = useChangePassword(); const [currentPassword, setCurrentPassword] = useState(""); const [newPassword, setNewPassword] = useState(""); const [message, setMessage] = useState<{ type: "success" | "error"; text: string; } | null>(null); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setMessage(null); try { await changePassword.mutateAsync({ currentPassword, newPassword }); setMessage({ type: "success", text: "Password changed" }); setCurrentPassword(""); setNewPassword(""); } catch (err) { setMessage({ type: "error", text: (err as Error).message }); } } return (
); } function ApiKeySection() { const { data: keys } = useApiKeys(); const createKey = useCreateApiKey(); const deleteKey = useDeleteApiKey(); const [name, setName] = useState(""); const [newKey, setNewKey] = useStateAPI keys allow programmatic access to GearBox (e.g., from Claude Desktop or scripts).
{newKey && (Copy this key now — it won't be shown again:
{newKey}
Export your gear collection as a CSV file, or import items from a CSV.
{importResult.imported} item {importResult.imported !== 1 ? "s" : ""} imported.
)} {importResult.createdCategories.length > 0 && (New categories: {importResult.createdCategories.join(", ")}
)} {importResult.errors.map((err, i) => ( // biome-ignore lint/suspicious/noArrayIndexKey: static error list{err}
))} {importResult.imported === 0 && importResult.errors.length === 0 && (No items found in the CSV.
)}Choose the unit used to display weights across the app
Changes the currency symbol displayed. This does not convert values.