mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-28 08:44:41 +08:00
fix(ui): add close button to all success toasts
This commit is contained in:
@@ -32,7 +32,7 @@ export function DeepLinkImportDialog() {
|
||||
|
||||
// 容错判断:MCP 导入结果可能缺少 type 字段
|
||||
const isMcpImportResult = (
|
||||
value: unknown
|
||||
value: unknown,
|
||||
): value is {
|
||||
importedCount: number;
|
||||
importedIds: string[];
|
||||
@@ -59,7 +59,7 @@ export function DeepLinkImportDialog() {
|
||||
if (event.payload.config || event.payload.configUrl) {
|
||||
try {
|
||||
const mergedRequest = await deeplinkApi.mergeDeeplinkConfig(
|
||||
event.payload
|
||||
event.payload,
|
||||
);
|
||||
console.log("Config merged successfully:", mergedRequest);
|
||||
setRequest(mergedRequest);
|
||||
@@ -77,7 +77,7 @@ export function DeepLinkImportDialog() {
|
||||
}
|
||||
|
||||
setIsOpen(true);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Listen for deep link error events
|
||||
@@ -128,6 +128,7 @@ export function DeepLinkImportDialog() {
|
||||
description: t("deeplink.mcpImportSuccessDescription", {
|
||||
count: summary.importedCount,
|
||||
}),
|
||||
closeButton: true,
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -142,18 +143,20 @@ export function DeepLinkImportDialog() {
|
||||
description: t("deeplink.importSuccessDescription", {
|
||||
name: request.name,
|
||||
}),
|
||||
closeButton: true,
|
||||
});
|
||||
} else if (result.type === "prompt") {
|
||||
// Prompts don't use React Query, trigger a custom event for refresh
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("prompt-imported", {
|
||||
detail: { app: request.app },
|
||||
})
|
||||
}),
|
||||
);
|
||||
toast.success(t("deeplink.promptImportSuccess"), {
|
||||
description: t("deeplink.promptImportSuccessDescription", {
|
||||
name: request.name,
|
||||
}),
|
||||
closeButton: true,
|
||||
});
|
||||
} else if (result.type === "mcp") {
|
||||
await refreshMcp(result);
|
||||
@@ -171,6 +174,7 @@ export function DeepLinkImportDialog() {
|
||||
description: t("deeplink.skillImportSuccessDescription", {
|
||||
repo: request.repo,
|
||||
}),
|
||||
closeButton: true,
|
||||
});
|
||||
}
|
||||
} else if (isMcpImportResult(result)) {
|
||||
@@ -185,6 +189,7 @@ export function DeepLinkImportDialog() {
|
||||
description: t("deeplink.importSuccessDescription", {
|
||||
name: request.name,
|
||||
}),
|
||||
closeButton: true,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -279,7 +284,7 @@ export function DeepLinkImportDialog() {
|
||||
const maskValue = (key: string, value: string): string => {
|
||||
const sensitiveKeys = ["TOKEN", "KEY", "SECRET", "PASSWORD"];
|
||||
const isSensitive = sensitiveKeys.some((k) =>
|
||||
key.toUpperCase().includes(k)
|
||||
key.toUpperCase().includes(k),
|
||||
);
|
||||
if (isSensitive && value.length > 8) {
|
||||
return `${value.substring(0, 8)}${"*".repeat(12)}`;
|
||||
@@ -521,7 +526,7 @@ export function DeepLinkImportDialog() {
|
||||
{maskValue(key, String(value))}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
@@ -548,7 +553,7 @@ export function DeepLinkImportDialog() {
|
||||
{maskValue(key, String(value))}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
@@ -584,7 +589,7 @@ export function DeepLinkImportDialog() {
|
||||
{maskValue(key, String(value))}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -234,7 +234,9 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
|
||||
try {
|
||||
const formatted = formatJSON(currentValue);
|
||||
onChange(formatted);
|
||||
toast.success(t("common.formatSuccess", { defaultValue: "格式化成功" }));
|
||||
toast.success(t("common.formatSuccess", { defaultValue: "格式化成功" }), {
|
||||
closeButton: true,
|
||||
});
|
||||
} catch (error) {
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : String(error);
|
||||
|
||||
@@ -227,6 +227,7 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
||||
.join(", ");
|
||||
toast.success(`${t("usageScript.testSuccess")}${summary}`, {
|
||||
duration: 3000,
|
||||
closeButton: true,
|
||||
});
|
||||
} else {
|
||||
toast.error(
|
||||
@@ -259,7 +260,10 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
||||
printWidth: 80,
|
||||
});
|
||||
setScript({ ...script, code: formatted.trim() });
|
||||
toast.success(t("usageScript.formatSuccess"), { duration: 1000 });
|
||||
toast.success(t("usageScript.formatSuccess"), {
|
||||
duration: 1000,
|
||||
closeButton: true,
|
||||
});
|
||||
} catch (error: any) {
|
||||
toast.error(
|
||||
`${t("usageScript.formatFailed")}: ${error?.message || t("jsonEditor.invalidJson")}`,
|
||||
|
||||
+1
@@ -79,6 +79,7 @@ export function EnvWarningBanner({
|
||||
path: backupInfo.backupPath,
|
||||
}),
|
||||
duration: 5000,
|
||||
closeButton: true,
|
||||
});
|
||||
|
||||
// 清空选择并通知父组件
|
||||
|
||||
@@ -391,7 +391,7 @@ const McpFormModal: React.FC<McpFormModalProps> = ({
|
||||
}
|
||||
|
||||
await upsertMutation.mutateAsync(entry);
|
||||
toast.success(t("common.success"));
|
||||
toast.success(t("common.success"), { closeButton: true });
|
||||
await onSave();
|
||||
} catch (error: any) {
|
||||
const detail = extractErrorMessage(error);
|
||||
|
||||
@@ -99,7 +99,7 @@ const UnifiedMcpPanel = React.forwardRef<
|
||||
try {
|
||||
await deleteServerMutation.mutateAsync(id);
|
||||
setConfirmDialog(null);
|
||||
toast.success(t("common.success"));
|
||||
toast.success(t("common.success"), { closeButton: true });
|
||||
} catch (error) {
|
||||
toast.error(t("common.error"), {
|
||||
description: String(error),
|
||||
|
||||
@@ -59,7 +59,7 @@ export function ProviderActions({
|
||||
// 代理接管模式下启用按钮使用绿色
|
||||
!isCurrent &&
|
||||
isProxyTakeover &&
|
||||
"bg-emerald-500 hover:bg-emerald-600 dark:bg-emerald-600 dark:hover:bg-emerald-700"
|
||||
"bg-emerald-500 hover:bg-emerald-600 dark:bg-emerald-600 dark:hover:bg-emerald-700",
|
||||
)}
|
||||
>
|
||||
{isCurrent ? (
|
||||
@@ -158,7 +158,7 @@ export function ProviderActions({
|
||||
className={cn(
|
||||
iconButtonClass,
|
||||
!isCurrent && "hover:text-red-500 dark:hover:text-red-400",
|
||||
isCurrent && "opacity-40 cursor-not-allowed text-muted-foreground"
|
||||
isCurrent && "opacity-40 cursor-not-allowed text-muted-foreground",
|
||||
)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
|
||||
@@ -111,6 +111,7 @@ export function ProviderCard({
|
||||
t("provider.circuitBreakerReset", {
|
||||
defaultValue: "熔断器已重置",
|
||||
}),
|
||||
{ closeButton: true },
|
||||
);
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
@@ -183,7 +184,9 @@ export function ProviderCard({
|
||||
"relative overflow-hidden rounded-xl border border-border p-4 transition-all duration-300",
|
||||
"bg-card text-card-foreground group",
|
||||
// 代理接管模式下 hover 使用绿色边框,否则使用蓝色
|
||||
isProxyTakeover ? "hover:border-emerald-500/50" : "hover:border-border-active",
|
||||
isProxyTakeover
|
||||
? "hover:border-emerald-500/50"
|
||||
: "hover:border-border-active",
|
||||
// 代理接管模式下当前供应商使用绿色边框
|
||||
isProxyTakeover && isCurrent
|
||||
? "border-emerald-500/60 shadow-sm shadow-emerald-500/10"
|
||||
@@ -194,12 +197,16 @@ export function ProviderCard({
|
||||
"cursor-grabbing border-primary shadow-lg scale-105 z-10",
|
||||
)}
|
||||
>
|
||||
<div className={cn(
|
||||
"absolute inset-0 bg-gradient-to-r to-transparent transition-opacity duration-500 pointer-events-none",
|
||||
// 代理接管模式下使用绿色渐变,否则使用蓝色主色调
|
||||
isProxyTakeover && isCurrent ? "from-emerald-500/10" : "from-primary/10",
|
||||
isCurrent ? "opacity-100" : "opacity-0"
|
||||
)} />
|
||||
<div
|
||||
className={cn(
|
||||
"absolute inset-0 bg-gradient-to-r to-transparent transition-opacity duration-500 pointer-events-none",
|
||||
// 代理接管模式下使用绿色渐变,否则使用蓝色主色调
|
||||
isProxyTakeover && isCurrent
|
||||
? "from-emerald-500/10"
|
||||
: "from-primary/10",
|
||||
isCurrent ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
/>
|
||||
<div className="relative flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="flex flex-1 items-center gap-2">
|
||||
<button
|
||||
|
||||
@@ -54,6 +54,7 @@ export function AutoFailoverConfigPanel({
|
||||
});
|
||||
toast.success(
|
||||
t("proxy.autoFailover.configSaved", "自动故障转移配置已保存"),
|
||||
{ closeButton: true },
|
||||
);
|
||||
} catch (e) {
|
||||
toast.error(
|
||||
|
||||
@@ -34,7 +34,7 @@ export function CircuitBreakerConfigPanel() {
|
||||
const handleSave = async () => {
|
||||
try {
|
||||
await updateConfig.mutateAsync(formData);
|
||||
toast.success("熔断器配置已保存");
|
||||
toast.success("熔断器配置已保存", { closeButton: true });
|
||||
} catch (error) {
|
||||
toast.error("保存失败: " + String(error));
|
||||
}
|
||||
|
||||
@@ -73,10 +73,8 @@ export function FailoverQueueManager({
|
||||
isLoading: isQueueLoading,
|
||||
error: queueError,
|
||||
} = useFailoverQueue(appType);
|
||||
const {
|
||||
data: availableProviders,
|
||||
isLoading: isProvidersLoading,
|
||||
} = useAvailableProvidersForFailover(appType);
|
||||
const { data: availableProviders, isLoading: isProvidersLoading } =
|
||||
useAvailableProvidersForFailover(appType);
|
||||
|
||||
// Mutations
|
||||
const addToQueue = useAddToFailoverQueue();
|
||||
@@ -122,6 +120,7 @@ export function FailoverQueueManager({
|
||||
await reorderQueue.mutateAsync({ appType, providerIds });
|
||||
toast.success(
|
||||
t("proxy.failoverQueue.reorderSuccess", "队列顺序已更新"),
|
||||
{ closeButton: true },
|
||||
);
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
@@ -144,7 +143,10 @@ export function FailoverQueueManager({
|
||||
providerId: selectedProviderId,
|
||||
});
|
||||
setSelectedProviderId("");
|
||||
toast.success(t("proxy.failoverQueue.addSuccess", "已添加到故障转移队列"));
|
||||
toast.success(
|
||||
t("proxy.failoverQueue.addSuccess", "已添加到故障转移队列"),
|
||||
{ closeButton: true },
|
||||
);
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
t("proxy.failoverQueue.addFailed", "添加失败") + ": " + String(error),
|
||||
@@ -158,10 +160,13 @@ export function FailoverQueueManager({
|
||||
await removeFromQueue.mutateAsync({ appType, providerId });
|
||||
toast.success(
|
||||
t("proxy.failoverQueue.removeSuccess", "已从故障转移队列移除"),
|
||||
{ closeButton: true },
|
||||
);
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
t("proxy.failoverQueue.removeFailed", "移除失败") + ": " + String(error),
|
||||
t("proxy.failoverQueue.removeFailed", "移除失败") +
|
||||
": " +
|
||||
String(error),
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -242,9 +247,7 @@ export function FailoverQueueManager({
|
||||
</Select>
|
||||
<Button
|
||||
onClick={handleAddProvider}
|
||||
disabled={
|
||||
disabled || !selectedProviderId || addToQueue.isPending
|
||||
}
|
||||
disabled={disabled || !selectedProviderId || addToQueue.isPending}
|
||||
size="icon"
|
||||
variant="outline"
|
||||
>
|
||||
@@ -386,9 +389,7 @@ function SortableQueueItem({
|
||||
{/* 启用开关 */}
|
||||
<Switch
|
||||
checked={item.enabled}
|
||||
onCheckedChange={(checked) =>
|
||||
onToggleEnabled(item.providerId, checked)
|
||||
}
|
||||
onCheckedChange={(checked) => onToggleEnabled(item.providerId, checked)}
|
||||
disabled={disabled || isToggling}
|
||||
aria-label={t("proxy.failoverQueue.toggleEnabled", "启用/禁用")}
|
||||
/>
|
||||
|
||||
@@ -51,7 +51,7 @@ export function ProxyPanel() {
|
||||
navigator.clipboard.writeText(
|
||||
`http://${status.address}:${status.port}`,
|
||||
);
|
||||
toast.success("地址已复制");
|
||||
toast.success("地址已复制", { closeButton: true });
|
||||
}}
|
||||
>
|
||||
复制
|
||||
|
||||
@@ -142,7 +142,7 @@ export function AboutSection({ isPortable }: AboutSectionProps) {
|
||||
try {
|
||||
const available = await checkUpdate();
|
||||
if (!available) {
|
||||
toast.success(t("settings.upToDate"));
|
||||
toast.success(t("settings.upToDate"), { closeButton: true });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("[AboutSection] Check update failed", error);
|
||||
|
||||
@@ -136,7 +136,7 @@ export function SettingsPage({
|
||||
const handleRestartNow = useCallback(async () => {
|
||||
setShowRestartPrompt(false);
|
||||
if (import.meta.env.DEV) {
|
||||
toast.success(t("settings.devModeRestartHint"));
|
||||
toast.success(t("settings.devModeRestartHint"), { closeButton: true });
|
||||
closeAfterSave();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,9 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
||||
const handleInstall = async (directory: string) => {
|
||||
try {
|
||||
await skillsApi.install(directory, selectedApp);
|
||||
toast.success(t("skills.installSuccess", { name: directory }));
|
||||
toast.success(t("skills.installSuccess", { name: directory }), {
|
||||
closeButton: true,
|
||||
});
|
||||
await loadSkills();
|
||||
} catch (error) {
|
||||
const errorMessage =
|
||||
@@ -132,7 +134,9 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
||||
const handleUninstall = async (directory: string) => {
|
||||
try {
|
||||
await skillsApi.uninstall(directory, selectedApp);
|
||||
toast.success(t("skills.uninstallSuccess", { name: directory }));
|
||||
toast.success(t("skills.uninstallSuccess", { name: directory }), {
|
||||
closeButton: true,
|
||||
});
|
||||
await loadSkills();
|
||||
} catch (error) {
|
||||
const errorMessage =
|
||||
@@ -180,12 +184,15 @@ export const SkillsPage = forwardRef<SkillsPageHandle, SkillsPageProps>(
|
||||
name: repo.name,
|
||||
count: repoSkillCount,
|
||||
}),
|
||||
{ closeButton: true },
|
||||
);
|
||||
};
|
||||
|
||||
const handleRemoveRepo = async (owner: string, name: string) => {
|
||||
await skillsApi.removeRepo(owner, name);
|
||||
toast.success(t("skills.repo.removeSuccess", { owner, name }));
|
||||
toast.success(t("skills.repo.removeSuccess", { owner, name }), {
|
||||
closeButton: true,
|
||||
});
|
||||
await Promise.all([loadRepos(), loadSkills()]);
|
||||
};
|
||||
|
||||
|
||||
@@ -47,7 +47,9 @@ export function ModelTestConfigPanel() {
|
||||
try {
|
||||
setIsSaving(true);
|
||||
await saveStreamCheckConfig(config);
|
||||
toast.success(t("streamCheck.configSaved", "健康检查配置已保存"));
|
||||
toast.success(t("streamCheck.configSaved", "健康检查配置已保存"), {
|
||||
closeButton: true,
|
||||
});
|
||||
} catch (e) {
|
||||
toast.error(
|
||||
t("streamCheck.configSaveFailed", "保存失败") + ": " + String(e),
|
||||
|
||||
@@ -76,6 +76,7 @@ export function PricingEditModal({
|
||||
isNew
|
||||
? t("usage.pricingAdded", "定价已添加")
|
||||
: t("usage.pricingUpdated", "定价已更新"),
|
||||
{ closeButton: true },
|
||||
);
|
||||
|
||||
onClose();
|
||||
|
||||
Reference in New Issue
Block a user