55 */
66
77import dayjs from "dayjs" ;
8- import deepMerge from "deepmerge" ;
98import { useCallback , useEffect , useState } from "react" ;
109import Alert , { AlertType } from "./components/Alert" ;
1110import { useUserLoader } from "./hooks/use-user-loader" ;
12- import { getGitpodService } from "./service/service" ;
1311import { isGitpodIo } from "./utils" ;
1412import { trackEvent } from "./Analytics" ;
13+ import { useUpdateCurrentUserMutation } from "./data/current-user/update-mutation" ;
14+ import { User as UserProtocol } from "@gitpod/gitpod-protocol" ;
15+ import { User } from "@gitpod/public-api/lib/gitpod/v1/user_pb" ;
1516
1617const KEY_APP_DISMISSED_NOTIFICATIONS = "gitpod-app-notifications-dismissed" ;
1718const PRIVACY_POLICY_LAST_UPDATED = "2023-10-17" ;
@@ -24,59 +25,60 @@ interface Notification {
2425 onClose ?: ( ) => void ;
2526}
2627
27- const UPDATED_PRIVACY_POLICY : Notification = {
28- id : "privacy-policy-update" ,
29- type : "info " ,
30- preventDismiss : true ,
31- onClose : async ( ) => {
32- let dismissSuccess = false ;
33- try {
34- const userUpdates = { additionalData : { profile : { acceptedPrivacyPolicyDate : dayjs ( ) . toISOString ( ) } } } ;
35- const previousUser = await getGitpodService ( ) . server . getLoggedInUser ( ) ;
36- const updatedUser = await getGitpodService ( ) . server . updateLoggedInUser (
37- deepMerge ( previousUser , userUpdates ) ,
38- ) ;
39- dismissSuccess = ! ! updatedUser ;
40- } catch ( err ) {
41- console . error ( "Failed to update user's privacy policy acceptance date" , err ) ;
42- dismissSuccess = false ;
43- } finally {
44- trackEvent ( "privacy_policy_update_accepted" , {
45- path : window . location . pathname ,
46- success : dismissSuccess ,
47- } ) ;
48- }
49- } ,
50- message : (
51- < span className = "text-md" >
52- We've updated our Privacy Policy. You can review it { " " }
53- < a className = "gp-link" href = "https://www.gitpod.io/privacy" target = "_blank" rel = "noreferrer" >
54- here
55- </ a >
56- .
57- </ span >
58- ) ,
28+ const UPDATED_PRIVACY_POLICY = ( updateUser : ( user : Partial < UserProtocol > ) => Promise < User > ) => {
29+ return {
30+ id : "privacy-policy-update " ,
31+ type : "info" ,
32+ preventDismiss : true ,
33+ onClose : async ( ) => {
34+ let dismissSuccess = false ;
35+ try {
36+ const updatedUser = await updateUser ( {
37+ additionalData : { profile : { acceptedPrivacyPolicyDate : dayjs ( ) . toISOString ( ) } } ,
38+ } ) ;
39+ dismissSuccess = ! ! updatedUser ;
40+ } catch ( err ) {
41+ console . error ( "Failed to update user's privacy policy acceptance date" , err ) ;
42+ dismissSuccess = false ;
43+ } finally {
44+ trackEvent ( "privacy_policy_update_accepted" , {
45+ path : window . location . pathname ,
46+ success : dismissSuccess ,
47+ } ) ;
48+ }
49+ } ,
50+ message : (
51+ < span className = "text-md" >
52+ We've updated our Privacy Policy. You can review it { " " }
53+ < a className = "gp-link" href = "https://www.gitpod.io/privacy" target = "_blank" rel = "noreferrer" >
54+ here
55+ </ a >
56+ .
57+ </ span >
58+ ) ,
59+ } as Notification ;
5960} ;
6061
6162export function AppNotifications ( ) {
6263 const [ topNotification , setTopNotification ] = useState < Notification | undefined > ( undefined ) ;
6364 const { user, loading } = useUserLoader ( ) ;
65+ const updateUser = useUpdateCurrentUserMutation ( ) ;
6466
6567 useEffect ( ( ) => {
6668 const notifications = [ ] ;
6769 if ( ! loading && isGitpodIo ( ) ) {
6870 if (
69- ! user ?. additionalData ?. profile ?. acceptedPrivacyPolicyDate ||
70- new Date ( PRIVACY_POLICY_LAST_UPDATED ) > new Date ( user . additionalData . profile . acceptedPrivacyPolicyDate )
71+ ! user ?. profile ?. acceptedPrivacyPolicyDate ||
72+ new Date ( PRIVACY_POLICY_LAST_UPDATED ) > new Date ( user . profile . acceptedPrivacyPolicyDate )
7173 ) {
72- notifications . push ( UPDATED_PRIVACY_POLICY ) ;
74+ notifications . push ( UPDATED_PRIVACY_POLICY ( ( u : Partial < UserProtocol > ) => updateUser . mutateAsync ( u ) ) ) ;
7375 }
7476 }
7577
7678 const dismissedNotifications = getDismissedNotifications ( ) ;
7779 const topNotification = notifications . find ( ( n ) => ! dismissedNotifications . includes ( n . id ) ) ;
7880 setTopNotification ( topNotification ) ;
79- } , [ loading , setTopNotification , user ] ) ;
81+ } , [ loading , updateUser , setTopNotification , user ] ) ;
8082
8183 const dismissNotification = useCallback ( ( ) => {
8284 if ( ! topNotification ) {
0 commit comments