Skip to content

Commit caad4a2

Browse files
committed
Add save button to Push Notifications section in advanced settings
1 parent 88eea6c commit caad4a2

2 files changed

Lines changed: 50 additions & 19 deletions

File tree

src/components/settings/SettingsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import OllamaSettings from './OllamaSettings';
77
import WalletSettings from './WalletSettings';
88
import GeneralSettings from './GeneralSettings';
99
import RelayInfoSettings from './RelayInfoSettings';
10-
import PushNotificationSettings from './PushNotificationSettings';
10+
import PushNotificationPanel from './panels/PushNotificationPanel';
1111
import * as S from '@app/pages/DashboardPages/DashboardPage.styles';
1212
import * as PageStyles from '@app/pages/uiComponentsPages/UIComponentsPage.styles';
1313
import { CollapsibleSection } from '@app/components/relay-settings/shared/CollapsibleSection/CollapsibleSection';
@@ -50,7 +50,7 @@ const SettingsPage: React.FC = () => {
5050
</CollapsibleSection>
5151

5252
<CollapsibleSection header="Push Notifications">
53-
<PushNotificationSettings />
53+
<PushNotificationPanel />
5454
</CollapsibleSection>
5555
</S.LeftSideCol>
5656

src/components/settings/panels/PushNotificationPanel.tsx

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,78 @@
11
import React, { useEffect, useState } from 'react';
2-
import { Form, Input, InputNumber, Switch, Tooltip, Alert, Spin, Divider } from 'antd';
2+
import { Form, Input, InputNumber, Switch, Tooltip, Alert, Spin, Divider, Button } from 'antd';
33
import {
4-
QuestionCircleOutlined
4+
QuestionCircleOutlined,
5+
SaveOutlined
56
} from '@ant-design/icons';
67
import useGenericSettings from '@app/hooks/useGenericSettings';
78
import { SettingsGroupType } from '@app/types/settings.types';
9+
import { LiquidBlueButton } from '@app/components/common/LiquidBlueButton';
810

911
const PushNotificationPanel: React.FC = () => {
10-
console.log('PushNotificationPanel - Component rendering');
11-
1212
const {
1313
settings,
1414
loading,
1515
error,
1616
updateSettings,
17-
// saveSettings is not used in panels - they use the global save
17+
saveSettings,
1818
} = useGenericSettings('push_notifications');
1919

2020
const [form] = Form.useForm();
2121
const [isUserEditing, setIsUserEditing] = useState(false);
22-
23-
console.log('PushNotificationPanel - Hook result:', { settings, loading, error });
22+
const [saveLoading, setSaveLoading] = useState(false);
2423

25-
// Listen for global save event
24+
// Listen for global save event and push notification specific save event
2625
useEffect(() => {
2726
const handleGlobalSave = () => {
2827
setTimeout(() => {
2928
setIsUserEditing(false);
3029
}, 200);
3130
};
3231

32+
const handlePushNotificationSave = () => {
33+
setTimeout(() => {
34+
setIsUserEditing(false);
35+
}, 200);
36+
};
37+
3338
document.addEventListener('settings-saved', handleGlobalSave);
39+
document.addEventListener('push-notifications-saved', handlePushNotificationSave);
3440

3541
return () => {
3642
document.removeEventListener('settings-saved', handleGlobalSave);
43+
document.removeEventListener('push-notifications-saved', handlePushNotificationSave);
3744
};
3845
}, []);
3946

4047
// Update form values when settings change, but only if user isn't actively editing
4148
useEffect(() => {
4249
if (settings && !isUserEditing) {
43-
console.log('PushNotificationPanel - Received settings:', settings);
44-
4550
// The useGenericSettings hook returns the settings data
4651
const settingsObj = settings as Record<string, any>;
4752

48-
console.log('PushNotificationPanel - Setting form values directly:', settingsObj);
49-
5053
// Set form values directly
5154
form.setFieldsValue(settingsObj);
52-
console.log('PushNotificationPanel - Form values after set:', form.getFieldsValue());
5355
}
5456
}, [settings, form, isUserEditing]);
5557

5658
// Handle form value changes
5759
const handleValuesChange = (changedValues: Partial<SettingsGroupType<'push_notifications'>>) => {
5860
setIsUserEditing(true); // Mark that user is currently editing
59-
console.log('PushNotificationPanel - changedValues:', changedValues);
60-
console.log('PushNotificationPanel - current form values:', form.getFieldsValue());
6161
updateSettings(changedValues);
6262
};
6363

64+
const handleSave = async () => {
65+
setSaveLoading(true);
66+
try {
67+
await saveSettings();
68+
setIsUserEditing(false);
69+
} catch (error) {
70+
console.error('Error saving push notification settings:', error);
71+
} finally {
72+
setSaveLoading(false);
73+
}
74+
};
75+
6476
return (
6577
<>
6678
{error && (
@@ -79,8 +91,7 @@ const PushNotificationPanel: React.FC = () => {
7991
layout="vertical"
8092
onValuesChange={handleValuesChange}
8193
initialValues={settings || {}}
82-
onFinish={(values) => {
83-
console.log('Form submitted with values:', values);
94+
onFinish={() => {
8495
setIsUserEditing(false);
8596
}}
8697
style={{
@@ -344,6 +355,26 @@ const PushNotificationPanel: React.FC = () => {
344355
placeholder="e.g., /path/to/firebase-service-account.json"
345356
/>
346357
</Form.Item>
358+
359+
{/* Save Button at bottom like other sections */}
360+
<Form.Item style={{ marginTop: '2rem', marginBottom: 0 }}>
361+
<div style={{
362+
display: 'flex',
363+
justifyContent: 'flex-end',
364+
paddingTop: '1rem',
365+
borderTop: '1px solid rgba(82, 196, 255, 0.2)'
366+
}}>
367+
<LiquidBlueButton
368+
variant="primary"
369+
icon={<SaveOutlined />}
370+
onClick={handleSave}
371+
loading={saveLoading}
372+
disabled={loading}
373+
>
374+
Save
375+
</LiquidBlueButton>
376+
</div>
377+
</Form.Item>
347378
</Form>
348379
</Spin>
349380
</>

0 commit comments

Comments
 (0)