22 Content ,
33 Notification ,
44 ProfileModal ,
5+ Skeleton ,
56 useToast ,
67} from '@appquality/unguess-design-system' ;
78import { useEffect } from 'react' ;
@@ -22,6 +23,10 @@ import i18n from 'src/i18n';
2223import styled from 'styled-components' ;
2324import { Header } from '../../common/components/navigation/header/header' ;
2425import { usePathWithoutLocale } from './usePathWithoutLocale' ;
26+ import {
27+ useGetUsersMePreferencesQuery ,
28+ usePutUsersMePreferencesByPrefidMutation ,
29+ } from '../api' ;
2530
2631const StyledContent = styled ( Content ) `
2732 height: 100%;
@@ -44,7 +49,41 @@ export const Navigation = ({
4449 const { activeWorkspace } = useActiveWorkspace ( ) ;
4550 const { addToast } = useToast ( ) ;
4651
47- // Set isSidebarOpen to false for specific routes
52+ const {
53+ data : preferences ,
54+ isLoading : isLoadingPrefs ,
55+ isFetching : isFetchingPrefs ,
56+ isError,
57+ } = useGetUsersMePreferencesQuery ( ) ;
58+
59+ const notificationsPreference = preferences ?. items ?. find (
60+ ( preference ) => preference ?. name === 'notifications_enabled'
61+ ) ;
62+
63+ const [ updatePreference ] = usePutUsersMePreferencesByPrefidMutation ( ) ;
64+
65+ const onSetSettings = async ( value : number ) => {
66+ await updatePreference ( {
67+ prefid : `${ notificationsPreference ?. preference_id } ` ,
68+ body : { value } ,
69+ } )
70+ . unwrap ( )
71+ . then ( ( ) => {
72+ addToast (
73+ ( { close } ) => (
74+ < Notification
75+ onClose = { close }
76+ type = "success"
77+ message = { t ( '__PROFILE_MODAL_NOTIFICATIONS_UPDATED' ) }
78+ closeText = { t ( '__TOAST_CLOSE_TEXT' ) }
79+ isPrimary
80+ />
81+ ) ,
82+ { placement : 'top' }
83+ ) ;
84+ } ) ;
85+ } ;
86+
4887 useEffect ( ( ) => {
4988 switch ( route ) {
5089 case 'service' :
@@ -111,6 +150,22 @@ export const Navigation = ({
111150 title : t ( '__PROFILE_MODAL_PRIVACY_ITEM_LABEL' ) ,
112151 url : 'https://www.iubenda.com/privacy-policy/833252/full-legal' ,
113152 } ,
153+ settingValue : notificationsPreference ?. value ,
154+ i18n : {
155+ settingsTitle : t ( '__PROFILE_MODAL_NOTIFICATIONS_TITLE' ) ,
156+ settingsIntroText : t ( '__PROFILE_MODAL_NOTIFICATIONS_INTRO' ) ,
157+ settingsOutroText : {
158+ paragraph_1 : t ( '__PROFILE_MODAL_NOTIFICATIONS_OUTRO_P_1' ) ,
159+ paragraph_2 : t ( '__PROFILE_MODAL_NOTIFICATIONS_OUTRO_P_2' ) ,
160+ paragraph_3 : t ( '__PROFILE_MODAL_NOTIFICATIONS_OUTRO_P_3' ) ,
161+ } ,
162+ settingsToggle : {
163+ title : t ( '__PROFILE_MODAL_NOTIFICATIONS_TOGGLE_TITLE' ) ,
164+ on : t ( '__PROFILE_MODAL_NOTIFICATIONS_TOGGLE_ON' ) ,
165+ off : t ( '__PROFILE_MODAL_NOTIFICATIONS_TOGGLE_OFF' ) ,
166+ } ,
167+ } ,
168+ onSetSettings,
114169 onSelectLanguage : ( lang : string ) => {
115170 if ( pathWithoutLocale === false ) return ;
116171 if ( lang === i18n . language ) return ;
@@ -158,9 +213,19 @@ export const Navigation = ({
158213
159214 if ( ! activeWorkspace ) return null ;
160215
216+ if ( isLoadingPrefs ) {
217+ return < Skeleton /> ;
218+ }
219+ if ( isError || ! preferences ) {
220+ return null ;
221+ }
161222 return (
162223 < >
163- < Header { ...( isMinimal && { style : { display : 'none' } } ) } />
224+ < Header
225+ { ...( isMinimal && {
226+ style : { display : 'none' , opacity : isFetchingPrefs ? 0.5 : 1 } ,
227+ } ) }
228+ />
164229 { isProfileModalOpen && (
165230 < ProfileModal onClose = { onProfileModalClose } menuArgs = { profileModal } />
166231 ) }
0 commit comments