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:
@@ -35,7 +35,13 @@ function Settings() {
|
|||||||
const response = await axios.get(`${API_URL}/api/settings`, {
|
const response = await axios.get(`${API_URL}/api/settings`, {
|
||||||
withCredentials: true,
|
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) {
|
} catch (error) {
|
||||||
console.error('Failed to load settings:', error);
|
console.error('Failed to load settings:', error);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -45,9 +51,16 @@ function Settings() {
|
|||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = async () => {
|
||||||
try {
|
try {
|
||||||
await axios.put(`${API_URL}/api/settings`, settings, {
|
await Promise.all([
|
||||||
withCredentials: true,
|
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!');
|
alert('Ayarlar kaydedildi!');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to save settings:', error);
|
console.error('Failed to save settings:', error);
|
||||||
@@ -59,7 +72,7 @@ function Settings() {
|
|||||||
setTestLoading({ ...testLoading, mail: true });
|
setTestLoading({ ...testLoading, mail: true });
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
`${API_URL}/api/settings/test-mail`,
|
`${API_URL}/api/settings/test-gmail`,
|
||||||
{},
|
{},
|
||||||
{ withCredentials: true }
|
{ withCredentials: true }
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user