Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/teams/onboarding/OrganizationJoinModal.tsx
2501 views
1
/**
2
* Copyright (c) 2025 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { OnboardingSettings_WelcomeMessage } from "@gitpod/public-api/lib/gitpod/v1/organization_pb";
8
import { Button } from "@podkit/buttons/Button";
9
import { useCallback, useEffect, useMemo, useState } from "react";
10
import { Modal, ModalBody, ModalFooter, ModalHeader } from "../../components/Modal";
11
import { storageAvailable } from "../../utils";
12
import { WelcomeMessagePreview } from "./WelcomeMessagePreview";
13
import { User } from "@gitpod/public-api/lib/gitpod/v1/user_pb";
14
15
type Props = {
16
user: User;
17
welcomeMessage: OnboardingSettings_WelcomeMessage;
18
};
19
export const OrganizationJoinModal = ({ welcomeMessage, user }: Props) => {
20
const initialOrgOnboardingPending = useMemo(() => {
21
if (!storageAvailable("localStorage")) {
22
return false;
23
}
24
25
const alreadyOnboarded = localStorage.getItem("newUserOnboardingDone") === "true";
26
if (alreadyOnboarded) {
27
return false;
28
}
29
30
// We want to show this message to users who just signed up, so we select the "new-ish" users here
31
const oneWeekSeconds = 7 * 24 * 60 * 60;
32
const userCreatedWithinLast7Days =
33
user.createdAt && user.createdAt.seconds >= Date.now() / 1000 - oneWeekSeconds;
34
return userCreatedWithinLast7Days;
35
}, [user.createdAt]);
36
const dismissOrgOnboarding = useCallback(() => {
37
if (storageAvailable("localStorage")) {
38
localStorage.setItem("newUserOnboardingDone", "true");
39
}
40
41
setOrgOnboardingPending(false);
42
}, []);
43
const [orgOnboardingPending, setOrgOnboardingPending] = useState(initialOrgOnboardingPending ?? false);
44
45
// if the org-wide welcome message is not enabled, prevent showing it in the future
46
useEffect(() => {
47
if (!welcomeMessage.enabled) {
48
dismissOrgOnboarding();
49
}
50
}, [welcomeMessage.enabled, dismissOrgOnboarding]);
51
52
if (!welcomeMessage.enabled || !orgOnboardingPending) {
53
return null;
54
}
55
56
return (
57
<Modal
58
visible={orgOnboardingPending}
59
onClose={dismissOrgOnboarding}
60
containerClassName="min-[576px]:max-w-[650px]"
61
>
62
<ModalHeader>Welcome to Gitpod</ModalHeader>
63
<ModalBody>
64
<WelcomeMessagePreview hideHeader />
65
</ModalBody>
66
<ModalFooter>
67
<Button onClick={dismissOrgOnboarding}>Get Started</Button>
68
</ModalFooter>
69
</Modal>
70
);
71
};
72
73