4
4
* See License-AGPL.txt in the project root for license information.
5
5
*/
6
6
7
+ import dayjs from "dayjs" ;
8
+ import deepMerge from "deepmerge" ;
7
9
import { useCallback , useEffect , useState } from "react" ;
8
10
import Alert , { AlertType } from "./components/Alert" ;
9
- import dayjs from "dayjs" ;
10
11
import { useUserLoader } from "./hooks/use-user-loader" ;
11
12
import { getGitpodService } from "./service/service" ;
12
- import deepMerge from "deepmerge" ;
13
+ import { isGitpodIo } from "./utils" ;
14
+ import { trackEvent } from "./Analytics" ;
13
15
14
16
const KEY_APP_DISMISSED_NOTIFICATIONS = "gitpod-app-notifications-dismissed" ;
15
17
const PRIVACY_POLICY_LAST_UPDATED = "2023-10-17" ;
@@ -27,9 +29,23 @@ const UPDATED_PRIVACY_POLICY: Notification = {
27
29
type : "info" ,
28
30
preventDismiss : true ,
29
31
onClose : async ( ) => {
30
- const userUpdates = { additionalData : { profile : { acceptedPrivacyPolicyDate : dayjs ( ) . toISOString ( ) } } } ;
31
- const previousUser = await getGitpodService ( ) . server . getLoggedInUser ( ) ;
32
- await getGitpodService ( ) . server . updateLoggedInUser ( deepMerge ( previousUser , userUpdates ) ) ;
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
+ }
33
49
} ,
34
50
message : (
35
51
< span className = "text-md" >
@@ -48,10 +64,10 @@ export function AppNotifications() {
48
64
49
65
useEffect ( ( ) => {
50
66
const notifications = [ ] ;
51
- if ( ! loading && user ?. additionalData ?. profile ) {
67
+ if ( ! loading && isGitpodIo ( ) ) {
52
68
if (
53
- ! user . additionalData . profile . acceptedPrivacyPolicyDate ||
54
- new Date ( PRIVACY_POLICY_LAST_UPDATED ) > new Date ( user . additionalData . profile ? .acceptedPrivacyPolicyDate )
69
+ ! user ? .additionalData ? .profile ? .acceptedPrivacyPolicyDate ||
70
+ new Date ( PRIVACY_POLICY_LAST_UPDATED ) > new Date ( user . additionalData . profile . acceptedPrivacyPolicyDate )
55
71
) {
56
72
notifications . push ( UPDATED_PRIVACY_POLICY ) ;
57
73
}
0 commit comments