From cfefe6b52a3a3c7d6f577601bafe82dedd510edc Mon Sep 17 00:00:00 2001 From: Jason Date: Thu, 16 Oct 2025 16:32:50 +0800 Subject: [PATCH] refactor: migrate UsageScriptModal to shadcn/ui Dialog component Migrate the usage script configuration modal from custom modal implementation to shadcn/ui Dialog component to maintain consistent styling across the entire application. ## Changes ### UsageScriptModal.tsx - Replace custom modal structure (fixed positioning, backdrop) with Dialog component - Remove X icon import (Dialog includes built-in close button) - Add Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter imports - Add Button component import for action buttons - Update props interface to include isOpen boolean prop - Restructure component layout: - Use DialogHeader with DialogTitle for header section - Apply -mx-6 px-6 pattern for full-width scrollable content - Use DialogFooter with flex-col sm:flex-row sm:justify-between layout - Convert custom buttons to Button components: - Test/Format buttons: variant="outline" size="sm" - Cancel button: variant="ghost" size="sm" - Save button: variant="default" size="sm" - Maintain all existing functionality (preset templates, JSON editor, validation, testing, formatting) ### App.tsx - Update UsageScriptModal usage to pass isOpen prop - Use Boolean(usageProvider) to control dialog open state ## Benefits - **Consistent styling**: All dialogs now use the same shadcn/ui Dialog component - **Better accessibility**: Automatic focus management, ESC key handling, ARIA attributes - **Code maintainability**: Reduced custom modal boilerplate, easier to update styling globally - **User experience**: Unified look and feel across settings, providers, MCP, and usage script dialogs All TypeScript type checks and Prettier formatting checks pass. --- src/App.tsx | 1 + src/components/UsageScriptModal.tsx | 73 ++++++++++++++--------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 90e4e5b..ccf1367 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -304,6 +304,7 @@ function App() { setUsageProvider(null)} onSave={(script) => { void handleSaveUsageScript(usageProvider, script); diff --git a/src/components/UsageScriptModal.tsx b/src/components/UsageScriptModal.tsx index c08c8ea..d6d2c02 100644 --- a/src/components/UsageScriptModal.tsx +++ b/src/components/UsageScriptModal.tsx @@ -1,15 +1,24 @@ import React, { useState } from "react"; -import { X, Play, Wand2 } from "lucide-react"; +import { Play, Wand2 } from "lucide-react"; import { Provider, UsageScript } from "../types"; import { usageApi, type AppType } from "@/lib/api"; import JsonEditor from "./JsonEditor"; import * as prettier from "prettier/standalone"; import * as parserBabel from "prettier/parser-babel"; import * as pluginEstree from "prettier/plugins/estree"; +import { + Dialog, + DialogContent, + DialogHeader, + DialogTitle, + DialogFooter, +} from "@/components/ui/dialog"; +import { Button } from "@/components/ui/button"; interface UsageScriptModalProps { provider: Provider; appType: AppType; + isOpen: boolean; onClose: () => void; onSave: (script: UsageScript) => void; onNotify?: ( @@ -79,6 +88,7 @@ const PRESET_TEMPLATES: Record = { const UsageScriptModal: React.FC = ({ provider, appType, + isOpen, onClose, onSave, onNotify, @@ -162,23 +172,14 @@ const UsageScriptModal: React.FC = ({ }; return ( -
-
- {/* Header */} -
-

- 配置用量查询 - {provider.name} -

- -
+ !open && onClose()}> + + + 配置用量查询 - {provider.name} + - {/* Content */} -
+ {/* Content - Scrollable */} +
{/* 启用开关 */}
{/* Footer */} -
+ + {/* Left side - Test and Format buttons */}
- - +
+ {/* Right side - Cancel and Save buttons */}
- - + +
-
-
-
+ + + ); };