refactor(frontend): move shared-form to components and unify default-model switch with SwitchCardField

This commit is contained in:
wenjie 2026-03-09 15:34:30 +08:00
parent d7b9534dbc
commit 895b81ec6a
8 changed files with 29 additions and 53 deletions

View file

@ -2,11 +2,7 @@ import { useTranslation } from "react-i18next"
import type { ChannelConfig } from "@/api/channels"
import { maskedSecretPlaceholder } from "@/components/channels/channel-forms/secret-placeholder"
import {
Field,
KeyInput,
SwitchCardField,
} from "@/components/models/shared-form"
import { Field, KeyInput, SwitchCardField } from "@/components/shared-form"
import { Input } from "@/components/ui/input"
interface DiscordFormProps {

View file

@ -2,7 +2,7 @@ import { useTranslation } from "react-i18next"
import type { ChannelConfig } from "@/api/channels"
import { maskedSecretPlaceholder } from "@/components/channels/channel-forms/secret-placeholder"
import { Field, KeyInput } from "@/components/models/shared-form"
import { Field, KeyInput } from "@/components/shared-form"
import { Input } from "@/components/ui/input"
interface FeishuFormProps {

View file

@ -2,11 +2,7 @@ import { useTranslation } from "react-i18next"
import type { ChannelConfig } from "@/api/channels"
import { maskedSecretPlaceholder } from "@/components/channels/channel-forms/secret-placeholder"
import {
Field,
KeyInput,
SwitchCardField,
} from "@/components/models/shared-form"
import { Field, KeyInput, SwitchCardField } from "@/components/shared-form"
import { Input } from "@/components/ui/input"
interface GenericFormProps {

View file

@ -2,7 +2,7 @@ import { useTranslation } from "react-i18next"
import type { ChannelConfig } from "@/api/channels"
import { maskedSecretPlaceholder } from "@/components/channels/channel-forms/secret-placeholder"
import { Field, KeyInput } from "@/components/models/shared-form"
import { Field, KeyInput } from "@/components/shared-form"
import { Input } from "@/components/ui/input"
interface SlackFormProps {

View file

@ -2,11 +2,7 @@ import { useTranslation } from "react-i18next"
import type { ChannelConfig } from "@/api/channels"
import { maskedSecretPlaceholder } from "@/components/channels/channel-forms/secret-placeholder"
import {
Field,
KeyInput,
SwitchCardField,
} from "@/components/models/shared-form"
import { Field, KeyInput, SwitchCardField } from "@/components/shared-form"
import { Input } from "@/components/ui/input"
interface TelegramFormProps {

View file

@ -3,6 +3,12 @@ import { useEffect, useState } from "react"
import { useTranslation } from "react-i18next"
import { addModel, setDefaultModel } from "@/api/models"
import {
AdvancedSection,
Field,
KeyInput,
SwitchCardField,
} from "@/components/shared-form"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import {
@ -13,9 +19,6 @@ import {
SheetHeader,
SheetTitle,
} from "@/components/ui/sheet"
import { Switch } from "@/components/ui/switch"
import { AdvancedSection, Field, KeyInput } from "./shared-form"
interface AddForm {
modelName: string
@ -187,21 +190,12 @@ export function AddModelSheet({ open, onClose, onSaved }: AddModelSheetProps) {
/>
</Field>
<div className="space-y-2">
<div className="border-input flex h-9 items-center justify-between rounded-md border px-2.5">
<span className="text-sm font-medium">
{t("models.defaultOnSave.label")}
</span>
<Switch
<SwitchCardField
label={t("models.defaultOnSave.label")}
hint={t("models.defaultOnSave.description")}
checked={setAsDefault}
onCheckedChange={setSetAsDefault}
aria-label={t("models.defaultOnSave.label")}
/>
</div>
<p className="text-muted-foreground text-xs">
{t("models.defaultOnSave.description")}
</p>
</div>
<AdvancedSection>
<Field

View file

@ -3,6 +3,12 @@ import { useEffect, useState } from "react"
import { useTranslation } from "react-i18next"
import { type ModelInfo, setDefaultModel, updateModel } from "@/api/models"
import {
AdvancedSection,
Field,
KeyInput,
SwitchCardField,
} from "@/components/shared-form"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import {
@ -13,9 +19,6 @@ import {
SheetHeader,
SheetTitle,
} from "@/components/ui/sheet"
import { Switch } from "@/components/ui/switch"
import { AdvancedSection, Field, KeyInput } from "./shared-form"
interface EditForm {
apiKey: string
@ -168,21 +171,12 @@ export function EditModelSheet({
/>
</Field>
<div className="space-y-2">
<div className="border-input flex h-9 items-center justify-between rounded-md border px-2.5">
<span className="text-sm font-medium">
{t("models.defaultOnSave.label")}
</span>
<Switch
<SwitchCardField
label={t("models.defaultOnSave.label")}
hint={t("models.defaultOnSave.description")}
checked={setAsDefault}
onCheckedChange={setSetAsDefault}
aria-label={t("models.defaultOnSave.label")}
/>
</div>
<p className="text-muted-foreground text-xs">
{t("models.defaultOnSave.description")}
</p>
</div>
<AdvancedSection>
<Field