fix: Settings page API endpoints and data handling

- Fixed handleSave to use separate /gmail and /telegram endpoints
- Changed /test-mail to /test-gmail endpoint
- Added proper null checks in loadSettings to prevent uncontrolled input warnings
- Settings now properly saved to backend with correct endpoint structure
This commit is contained in:
salvacybersec
2025-11-10 19:22:27 +03:00
parent 64c7c392bc
commit 37e9745a4d

View File

@@ -35,7 +35,13 @@ function Settings() {
const response = await axios.get(`${API_URL}/api/settings`, {
withCredentials: true,
});
setSettings(response.data.data);
const data = response.data.data || {};
setSettings({
gmail_user: data.gmail_user || '',
gmail_app_password: data.gmail_app_password || '',
telegram_bot_token: data.telegram_bot_token || '',
telegram_chat_id: data.telegram_chat_id || '',
});
} catch (error) {
console.error('Failed to load settings:', error);
} finally {
@@ -45,9 +51,16 @@ function Settings() {
const handleSave = async () => {
try {
await axios.put(`${API_URL}/api/settings`, settings, {
withCredentials: true,
});
await Promise.all([
axios.put(`${API_URL}/api/settings/gmail`, {
gmail_user: settings.gmail_user,
gmail_app_password: settings.gmail_app_password,
}, { withCredentials: true }),
axios.put(`${API_URL}/api/settings/telegram`, {
telegram_bot_token: settings.telegram_bot_token,
telegram_chat_id: settings.telegram_chat_id,
}, { withCredentials: true }),
]);
alert('Ayarlar kaydedildi!');
} catch (error) {
console.error('Failed to save settings:', error);
@@ -59,7 +72,7 @@ function Settings() {
setTestLoading({ ...testLoading, mail: true });
try {
const response = await axios.post(
`${API_URL}/api/settings/test-mail`,
`${API_URL}/api/settings/test-gmail`,
{},
{ withCredentials: true }
);