feat: Add mock mode for UI-only development
- Created mock API implementation in src/api/mock.ts - Added isMockMode toggle to useStore - Implemented switching between real and mock API in client.ts - Added Mock Mode toggle to Login page - Added 'npm run dev:mock' command Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import { useNavigate } from 'react-router-dom';
|
||||
import { api } from '../api/client';
|
||||
|
||||
export const Login: React.FC = () => {
|
||||
const { apiDomain, apiKey, setApiDomain, setApiKey } = useStore();
|
||||
const { apiDomain, apiKey, isMockMode, setApiDomain, setApiKey, setMockMode } = useStore();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const navigate = useNavigate();
|
||||
@@ -16,10 +16,14 @@ export const Login: React.FC = () => {
|
||||
|
||||
try {
|
||||
// Basic validation
|
||||
if (!apiDomain || !apiKey) {
|
||||
if (!isMockMode && (!apiDomain || !apiKey)) {
|
||||
throw new Error('Please fill all fields');
|
||||
}
|
||||
|
||||
if (isMockMode && !apiKey) {
|
||||
setApiKey('mock-session');
|
||||
}
|
||||
|
||||
// Check health
|
||||
await api.checkHealth();
|
||||
|
||||
@@ -44,6 +48,7 @@ export const Login: React.FC = () => {
|
||||
placeholder="API Domain (e.g. https://api.example.com)"
|
||||
value={apiDomain}
|
||||
onChange={(e) => setApiDomain(e.target.value)}
|
||||
disabled={isMockMode}
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
@@ -51,7 +56,22 @@ export const Login: React.FC = () => {
|
||||
placeholder="API Key"
|
||||
value={apiKey}
|
||||
onChange={(e) => setApiKey(e.target.value)}
|
||||
disabled={isMockMode}
|
||||
/>
|
||||
|
||||
<div style={{ marginBottom: '16px', display: 'flex', alignItems: 'center' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="mockMode"
|
||||
checked={isMockMode}
|
||||
onChange={(e) => setMockMode(e.target.checked)}
|
||||
style={{ marginRight: '8px' }}
|
||||
/>
|
||||
<label htmlFor="mockMode" style={{ fontSize: '14px', cursor: 'pointer' }}>
|
||||
Enable Mock Mode (UI Only)
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<p style={{ color: 'var(--md-sys-color-error)', marginBottom: '16px' }}>
|
||||
{error}
|
||||
|
||||
Reference in New Issue
Block a user