mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-25 13:45:03 +08:00
feat(common-config): show first-run notice dialog when editing providers
Display a one-time informational dialog explaining the Common Config Snippet feature when users first open the add/edit provider form. Uses a derived isOpen state from settings to avoid race conditions. Adds commonConfigConfirmed flag to both TS and Rust settings types.
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { useEffect, useMemo, useState, useCallback } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Form, FormField, FormItem, FormMessage } from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { providerSchema, type ProviderFormData } from "@/lib/schemas/provider";
|
||||
import { providersApi, type AppId } from "@/lib/api";
|
||||
import { providersApi, settingsApi, type AppId } from "@/lib/api";
|
||||
import type {
|
||||
ProviderCategory,
|
||||
ProviderMeta,
|
||||
@@ -84,6 +84,8 @@ import {
|
||||
useCopilotAuth,
|
||||
useCodexOauth,
|
||||
} from "./hooks";
|
||||
import { ConfirmDialog } from "@/components/ConfirmDialog";
|
||||
import { useSettingsQuery } from "@/lib/query";
|
||||
import {
|
||||
CLAUDE_DEFAULT_CONFIG,
|
||||
CODEX_DEFAULT_CONFIG,
|
||||
@@ -141,6 +143,22 @@ export function ProviderForm({
|
||||
}: ProviderFormProps) {
|
||||
const { t } = useTranslation();
|
||||
const isEditMode = Boolean(initialData);
|
||||
const queryClient = useQueryClient();
|
||||
const { data: settingsData } = useSettingsQuery();
|
||||
const showCommonConfigNotice =
|
||||
settingsData != null && settingsData.commonConfigConfirmed !== true;
|
||||
|
||||
const handleCommonConfigConfirm = async () => {
|
||||
try {
|
||||
if (settingsData) {
|
||||
const { webdavSync: _, ...rest } = settingsData;
|
||||
await settingsApi.save({ ...rest, commonConfigConfirmed: true });
|
||||
await queryClient.invalidateQueries({ queryKey: ["settings"] });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to save commonConfigConfirmed:", error);
|
||||
}
|
||||
};
|
||||
|
||||
const [selectedPresetId, setSelectedPresetId] = useState<string | null>(
|
||||
initialData ? null : "custom",
|
||||
@@ -1342,7 +1360,8 @@ export function ProviderForm({
|
||||
);
|
||||
|
||||
return (
|
||||
<Form {...form}>
|
||||
<>
|
||||
<Form {...form}>
|
||||
<form
|
||||
id="provider-form"
|
||||
onSubmit={form.handleSubmit(handleSubmit)}
|
||||
@@ -1836,8 +1855,19 @@ export function ProviderForm({
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</form>
|
||||
</Form>
|
||||
</form>
|
||||
</Form>
|
||||
|
||||
<ConfirmDialog
|
||||
isOpen={showCommonConfigNotice}
|
||||
variant="info"
|
||||
title={t("confirm.commonConfig.title")}
|
||||
message={t("confirm.commonConfig.message")}
|
||||
confirmText={t("confirm.commonConfig.confirm")}
|
||||
onConfirm={() => void handleCommonConfigConfirm()}
|
||||
onCancel={() => void handleCommonConfigConfirm()}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -232,6 +232,11 @@
|
||||
"title": "Enable Auto Sync",
|
||||
"message": "When auto sync is enabled, every database change will be automatically uploaded to the WebDAV server.\n\nThis may result in significant network traffic. Please ensure your network and WebDAV service can handle frequent data transfers.",
|
||||
"confirm": "I understand, enable"
|
||||
},
|
||||
"commonConfig": {
|
||||
"title": "About Common Config",
|
||||
"message": "The \"Common Config Snippet\" lets you share plugins, environment variables, and other settings across different providers — so they won't be lost when you switch.\n\nHow to use:\n① Edit a provider → click \"Edit Common Config\" → \"Extract from Editor\"\n② When creating a new provider, check \"Write Common Config\" (enabled by default)\n\nIf you've newly installed plugins or hooks, re-extract the common config to keep them in sync.",
|
||||
"confirm": "Got it"
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
|
||||
@@ -232,6 +232,11 @@
|
||||
"title": "自動同期を有効にする",
|
||||
"message": "自動同期を有効にすると、データベースの変更ごとに WebDAV サーバーへ自動アップロードされます。\n\nネットワークトラフィックが大幅に増加する可能性があります。ネットワーク環境と WebDAV サービスが頻繁なデータ転送に対応できることをご確認ください。",
|
||||
"confirm": "理解しました、有効にする"
|
||||
},
|
||||
"commonConfig": {
|
||||
"title": "共通設定について",
|
||||
"message": "「共通設定スニペット」を使うと、プラグインや環境変数などの設定を異なるプロバイダー間で共有でき、切り替え時に失われることがありません。\n\n使い方:\n① プロバイダーを編集 →「共通設定を編集」→「編集内容から抽出」\n② 新規プロバイダー作成時に「共通設定を書き込む」をチェック(デフォルトでオン)\n\n新しいプラグインや Hook をインストールした場合は、共通設定を再抽出してください。",
|
||||
"confirm": "わかりました"
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
|
||||
@@ -232,6 +232,11 @@
|
||||
"title": "开启自动同步",
|
||||
"message": "开启自动同步后,每次数据库变更都会自动上传到 WebDAV 服务器。\n\n这可能会产生较高的网络流量消耗,请确保您的网络环境和 WebDAV 服务支持频繁的数据传输。",
|
||||
"confirm": "我已了解,继续开启"
|
||||
},
|
||||
"commonConfig": {
|
||||
"title": "关于通用配置",
|
||||
"message": "「通用配置片段」可以在不同供应商之间共享插件、环境变量等配置,避免切换供应商时丢失这些设置。\n\n使用方法:\n① 编辑供应商时点击「编辑通用配置」→「从编辑内容提取」\n② 新建供应商时勾选「写入通用配置」(默认已勾选)\n\n如果您新安装了插件或 Hook,请重新提取一次通用配置。",
|
||||
"confirm": "我知道了"
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
|
||||
@@ -268,6 +268,8 @@ export interface Settings {
|
||||
firstRunNoticeConfirmed?: boolean;
|
||||
// User has confirmed the auto-sync traffic warning
|
||||
autoSyncConfirmed?: boolean;
|
||||
// User has confirmed the common config first-run notice
|
||||
commonConfigConfirmed?: boolean;
|
||||
// 首选语言(可选,默认中文)
|
||||
language?: "en" | "zh" | "ja";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user