♻️ refactor(ui): use global toast system in SettingsPage
- Replace local message state with global showSuccess/showError - Remove inline message display component from SettingsPage - Center toast notifications for better visibility Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -73,7 +73,7 @@ export function Toast() {
|
|||||||
if (toasts.length === 0) return null
|
if (toasts.length === 0) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed bottom-4 right-4 z-50 flex flex-col gap-2">
|
<div className="fixed bottom-4 left-1/2 -translate-x-1/2 z-50 flex flex-col gap-2">
|
||||||
{toasts.map((toast) => (
|
{toasts.map((toast) => (
|
||||||
<ToastItem
|
<ToastItem
|
||||||
key={toast.id}
|
key={toast.id}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import { Settings as SettingsIcon, Save, User, Key } from 'lucide-react'
|
import { Settings as SettingsIcon, Save, User, Key } from 'lucide-react'
|
||||||
|
import { showSuccess, showError } from '../stores/useAppStore'
|
||||||
|
|
||||||
interface ErpCredentials {
|
interface ErpCredentials {
|
||||||
username: string
|
username: string
|
||||||
@@ -13,10 +14,6 @@ const SettingsPage: React.FC = () => {
|
|||||||
})
|
})
|
||||||
const [isModified, setIsModified] = useState(false)
|
const [isModified, setIsModified] = useState(false)
|
||||||
const [isLoading, setIsLoading] = useState(true)
|
const [isLoading, setIsLoading] = useState(true)
|
||||||
const [message, setMessage] = useState<{
|
|
||||||
type: 'success' | 'error' | 'info'
|
|
||||||
text: string
|
|
||||||
} | null>(null)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadCredentials()
|
loadCredentials()
|
||||||
@@ -38,21 +35,16 @@ const SettingsPage: React.FC = () => {
|
|||||||
password: config.erp.password || ''
|
password: config.erp.password || ''
|
||||||
})
|
})
|
||||||
} else if (!response.success) {
|
} else if (!response.success) {
|
||||||
showMessage('error', response.error || '加载 ERP 配置失败')
|
showError(response.error || '加载 ERP 配置失败')
|
||||||
}
|
}
|
||||||
setIsModified(false)
|
setIsModified(false)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showMessage('error', '加载 ERP 配置失败')
|
showError('加载 ERP 配置失败')
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const showMessage = (type: 'success' | 'error' | 'info', text: string) => {
|
|
||||||
setMessage({ type, text })
|
|
||||||
setTimeout(() => setMessage(null), 3000)
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleSaveCredentials = async () => {
|
const handleSaveCredentials = async () => {
|
||||||
try {
|
try {
|
||||||
// Save ERP credentials to database (current user's config)
|
// Save ERP credentials to database (current user's config)
|
||||||
@@ -68,12 +60,12 @@ const SettingsPage: React.FC = () => {
|
|||||||
|
|
||||||
if (result.success && saveData?.success !== false) {
|
if (result.success && saveData?.success !== false) {
|
||||||
setIsModified(false)
|
setIsModified(false)
|
||||||
showMessage('success', 'ERP 账号密码保存成功')
|
showSuccess('ERP 账号密码保存成功')
|
||||||
} else {
|
} else {
|
||||||
showMessage('error', result.error || saveData?.error || '保存失败')
|
showError(result.error || saveData?.error || '保存失败')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showMessage('error', '保存配置时发生错误')
|
showError('保存配置时发生错误')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,18 +82,6 @@ const SettingsPage: React.FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex justify-center animate-in fade-in slide-in-from-bottom-4 duration-500 mt-6">
|
<div className="flex justify-center animate-in fade-in slide-in-from-bottom-4 duration-500 mt-6">
|
||||||
{message && (
|
|
||||||
<div
|
|
||||||
className={`fixed top-5 left-1/2 -translate-x-1/2 px-6 py-3 rounded-lg shadow-lg z-[10000] text-sm font-medium transition-all ${
|
|
||||||
message.type === 'success'
|
|
||||||
? 'bg-emerald-50 text-emerald-600 border border-emerald-200'
|
|
||||||
: 'bg-red-50 text-red-600 border border-red-200'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
{message.text}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="w-full max-w-xl bg-white rounded-xl shadow-sm border border-slate-200 overflow-hidden">
|
<div className="w-full max-w-xl bg-white rounded-xl shadow-sm border border-slate-200 overflow-hidden">
|
||||||
<div className="border-b border-slate-100 bg-slate-50 px-6 py-5">
|
<div className="border-b border-slate-100 bg-slate-50 px-6 py-5">
|
||||||
<h2 className="text-lg font-semibold flex items-center gap-2 text-slate-800">
|
<h2 className="text-lg font-semibold flex items-center gap-2 text-slate-800">
|
||||||
|
|||||||
Reference in New Issue
Block a user