refactor: split ProviderForm into smaller focused components
- Created ProviderPresetSelector component (80 lines) - Created BasicFormFields component (60 lines) - Created ClaudeFormFields component (272 lines) - Created CodexFormFields component (131 lines) - Reduced ProviderForm from 866 to 544 lines (37% reduction) Each component now has a clear single responsibility: - ProviderPresetSelector: Handles preset selection UI - BasicFormFields: Name and website URL inputs - ClaudeFormFields: All Claude-specific form fields - CodexFormFields: All Codex-specific form fields - ProviderForm: Orchestrates hooks and component composition Benefits: - Better code organization and maintainability - Easier to test individual components - Clearer separation of concerns - More reusable components
This commit is contained in:
60
src/components/providers/forms/BasicFormFields.tsx
Normal file
60
src/components/providers/forms/BasicFormFields.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import type { UseFormReturn } from "react-hook-form";
|
||||
import type { ProviderFormData } from "@/lib/schemas/provider";
|
||||
|
||||
interface BasicFormFieldsProps {
|
||||
form: UseFormReturn<ProviderFormData>;
|
||||
}
|
||||
|
||||
export function BasicFormFields({ form }: BasicFormFieldsProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="name"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
{t("provider.name", { defaultValue: "供应商名称" })}
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
placeholder={t("provider.namePlaceholder", {
|
||||
defaultValue: "例如:Claude 官方",
|
||||
})}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="websiteUrl"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
{t("provider.websiteUrl", { defaultValue: "官网链接" })}
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} placeholder="https://" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user