From decc3f019524643f45d592745a93514b3e82b029 Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Fri, 3 Apr 2026 10:08:13 -0400 Subject: [PATCH] fix: toast theme & error msgs --- frontend/src/components/Toast.tsx | 18 ++++++++--------- frontend/src/pages/AdminUsersPage.tsx | 28 +++++++++++++++++++++++---- frontend/src/pages/SettingsPage.tsx | 24 +++++++++++++++++------ 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/Toast.tsx b/frontend/src/components/Toast.tsx index 5880aa7..60588a6 100644 --- a/frontend/src/components/Toast.tsx +++ b/frontend/src/components/Toast.tsx @@ -16,21 +16,21 @@ const getToastStyles = (_type: ToastType) => { 'flex items-center gap-3 rounded-lg border-l-4 p-4 shadow-lg transition-all duration-300'; const typeStyles = { - info: 'border-secondary-500 bg-secondary-50 dark:bg-secondary-100/20', - warning: 'border-yellow-500 bg-yellow-50 dark:bg-yellow-100/20', - error: 'border-red-500 bg-red-50 dark:bg-red-100/20', + info: 'border-secondary-500 bg-secondary-100', + warning: 'border-yellow-500 bg-yellow-100', + error: 'border-red-500 bg-red-100', }; const iconStyles = { - info: 'text-secondary-600 dark:text-secondary-500', - warning: 'text-yellow-700 dark:text-yellow-500', - error: 'text-red-600 dark:text-red-400', + info: 'text-secondary-700', + warning: 'text-yellow-700', + error: 'text-red-700', }; const textStyles = { - info: 'text-secondary-900 dark:text-secondary-700', - warning: 'text-yellow-900 dark:text-yellow-700', - error: 'text-red-900 dark:text-red-700', + info: 'text-secondary-900', + warning: 'text-yellow-900', + error: 'text-red-900', }; return { baseStyles, typeStyles, iconStyles, textStyles }; diff --git a/frontend/src/pages/AdminUsersPage.tsx b/frontend/src/pages/AdminUsersPage.tsx index 7597193..6d07f49 100644 --- a/frontend/src/pages/AdminUsersPage.tsx +++ b/frontend/src/pages/AdminUsersPage.tsx @@ -31,7 +31,12 @@ export default function AdminUsersPage() { }, }, { - onSuccess: () => { + onSuccess: response => { + if (response.status < 200 || response.status >= 300) { + showError('Failed to create user: ' + getErrorMessage(response.data)); + return; + } + showInfo('User created successfully'); setShowAddForm(false); setNewUsername(''); @@ -50,7 +55,12 @@ export default function AdminUsersPage() { data: { operation: 'DELETE', user: userId }, }, { - onSuccess: () => { + onSuccess: response => { + if (response.status < 200 || response.status >= 300) { + showError('Failed to delete user: ' + getErrorMessage(response.data)); + return; + } + showInfo('User deleted successfully'); refetch(); }, @@ -67,7 +77,12 @@ export default function AdminUsersPage() { data: { operation: 'UPDATE', user: userId, password }, }, { - onSuccess: () => { + onSuccess: response => { + if (response.status < 200 || response.status >= 300) { + showError('Failed to update password: ' + getErrorMessage(response.data)); + return; + } + showInfo('Password updated successfully'); refetch(); }, @@ -82,7 +97,12 @@ export default function AdminUsersPage() { data: { operation: 'UPDATE', user: userId, is_admin: isAdmin }, }, { - onSuccess: () => { + onSuccess: response => { + if (response.status < 200 || response.status >= 300) { + showError('Failed to update admin status: ' + getErrorMessage(response.data)); + return; + } + showInfo(`User permissions updated to ${isAdmin ? 'admin' : 'user'}`); refetch(); }, diff --git a/frontend/src/pages/SettingsPage.tsx b/frontend/src/pages/SettingsPage.tsx index 4109d6f..510c309 100644 --- a/frontend/src/pages/SettingsPage.tsx +++ b/frontend/src/pages/SettingsPage.tsx @@ -40,15 +40,21 @@ export default function SettingsPage() { } try { - await updateSettings.mutateAsync({ + const response = await updateSettings.mutateAsync({ data: { password, new_password: newPassword, }, }); - showInfo('Password updated successfully'); - setPassword(''); - setNewPassword(''); + + if (response.status >= 200 && response.status < 300) { + showInfo('Password updated successfully'); + setPassword(''); + setNewPassword(''); + return; + } + + showError('Failed to update password: ' + getErrorMessage(response.data)); } catch (error) { showError('Failed to update password: ' + getErrorMessage(error)); } @@ -58,12 +64,18 @@ export default function SettingsPage() { e.preventDefault(); try { - await updateSettings.mutateAsync({ + const response = await updateSettings.mutateAsync({ data: { timezone, }, }); - showInfo('Timezone updated successfully'); + + if (response.status >= 200 && response.status < 300) { + showInfo('Timezone updated successfully'); + return; + } + + showError('Failed to update timezone: ' + getErrorMessage(response.data)); } catch (error) { showError('Failed to update timezone: ' + getErrorMessage(error)); }