11import 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' ;
33import {
4- QuestionCircleOutlined
4+ QuestionCircleOutlined ,
5+ SaveOutlined
56} from '@ant-design/icons' ;
67import useGenericSettings from '@app/hooks/useGenericSettings' ;
78import { SettingsGroupType } from '@app/types/settings.types' ;
9+ import { LiquidBlueButton } from '@app/components/common/LiquidBlueButton' ;
810
911const 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