Skip to content

Commit 1f5e9f6

Browse files
committed
Update user
1 parent af27780 commit 1f5e9f6

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

components/dashboard/src/AppNotifications.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import utc from "dayjs/plugin/utc";
1111
import timezone from "dayjs/plugin/timezone";
1212
import advancedFormat from "dayjs/plugin/advancedFormat";
1313
import { useUserLoader } from "./hooks/use-user-loader";
14+
import { getGitpodService } from "./service/service";
15+
import { deepMerge } from "./utils";
1416

1517
const KEY_APP_DISMISSED_NOTIFICATIONS = "gitpod-app-notifications-dismissed";
16-
const PRIVACY_POLICY_LAST_UPDATED = "09/25/2023";
18+
const PRIVACY_POLICY_LAST_UPDATED = "2023-09-26";
1719

1820
interface Notification {
1921
id: string;
@@ -33,16 +35,21 @@ export function localizedTime(dateStr: string): JSX.Element {
3335
}
3436

3537
function formatDate(dateString: string): JSX.Element {
36-
const formatted = dayjs.utc(dateString).local().format("LL");
38+
const formatted = dayjs.utc(dateString).local().format("MMMM D, YYYY");
3739
return <time dateTime={dateString}>{formatted}</time>;
3840
}
3941

4042
const UPDATED_PRIVACY_POLICY: Notification = {
4143
id: "privacy-policy-update",
4244
type: "info",
4345
preventDismiss: true,
44-
onClose: () => {
46+
onClose: async () => {
4547
console.error("Well... happy for you");
48+
const userUpdates = { additionalData: { profile: { acceptedPrivacyPolicyDate: dayjs().toISOString() } } };
49+
const previousUser = await getGitpodService().server.getLoggedInUser();
50+
const user = await getGitpodService().server.updateLoggedInUser(deepMerge(previousUser, userUpdates));
51+
52+
console.log(user);
4653
},
4754
message: (
4855
<span className="text-md">
@@ -61,8 +68,11 @@ export function AppNotifications() {
6168

6269
useEffect(() => {
6370
const notifications = [];
64-
if (!loading && user?.additionalData) {
65-
if (new Date(PRIVACY_POLICY_LAST_UPDATED) > new Date(user.additionalData.acceptedPrivacyPoliceDate)) {
71+
if (!loading && user?.additionalData?.profile) {
72+
if (
73+
!user.additionalData.profile.acceptedPrivacyPolicyDate ||
74+
new Date(PRIVACY_POLICY_LAST_UPDATED) > new Date(user.additionalData.profile?.acceptedPrivacyPolicyDate)
75+
) {
6676
notifications.push(UPDATED_PRIVACY_POLICY);
6777
}
6878
}

components/dashboard/src/utils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,31 @@ export function getURLHash() {
8585
return window.location.hash.replace(/^[#/]+/, "");
8686
}
8787

88+
export type DeepPartial<T> = {
89+
[P in keyof T]?: DeepPartial<T[P]> | T[P];
90+
};
91+
92+
function isObject(item: any): item is Record<string, any> {
93+
return item && typeof item === "object" && !Array.isArray(item);
94+
}
95+
96+
export function deepMerge<T>(target: T, source: DeepPartial<T>): T {
97+
for (let key in source) {
98+
if (source.hasOwnProperty(key)) {
99+
const currentKey = key as keyof T;
100+
if (isObject(source[currentKey]) && isObject(target[currentKey])) {
101+
target[currentKey] = deepMerge(
102+
target[currentKey],
103+
source[currentKey] as DeepPartial<T[keyof T]>,
104+
) as T[keyof T];
105+
} else {
106+
target[currentKey] = source[currentKey] as T[keyof T];
107+
}
108+
}
109+
}
110+
return target;
111+
}
112+
88113
export function isWebsiteSlug(pathName: string) {
89114
const slugs = [
90115
"about",

components/gitpod-protocol/src/protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export interface ProfileDetails {
303303
// when was the last time the user updated their profile information or has been nudged to do so.
304304
lastUpdatedDetailsNudge?: string;
305305
// when was the last time the user has accepted our privacy policy
306-
acceptedPrivacyPoliceDate?: string;
306+
acceptedPrivacyPolicyDate?: string;
307307
// the user's company name
308308
companyName?: string;
309309
// the user's email

0 commit comments

Comments
 (0)