4
4
* See License.AGPL.txt in the project root for license information.
5
5
*/
6
6
7
- import { OrganizationSettings } from "@gitpod/public-api/lib/gitpod/v1/organization_pb" ;
7
+ import { OnboardingSettings_WelcomeMessage } from "@gitpod/public-api/lib/gitpod/v1/organization_pb" ;
8
8
import { Button } from "@podkit/buttons/Button" ;
9
9
import { useCallback , useEffect , useMemo , useState } from "react" ;
10
10
import { Modal , ModalBody , ModalFooter , ModalHeader } from "../../components/Modal" ;
11
11
import { storageAvailable } from "../../utils" ;
12
12
import { WelcomeMessagePreview } from "./WelcomeMessagePreview" ;
13
+ import { User } from "@gitpod/public-api/lib/gitpod/v1/user_pb" ;
13
14
14
15
type Props = {
15
- orgSettings : OrganizationSettings ;
16
+ user : User ;
17
+ welcomeMessage : OnboardingSettings_WelcomeMessage ;
16
18
} ;
17
- export const OrganizationJoinModal = ( { orgSettings } : Props ) => {
19
+ export const OrganizationJoinModal = ( { welcomeMessage , user } : Props ) => {
18
20
const initialOrgOnboardingPending = useMemo ( ( ) => {
19
- if ( storageAvailable ( "localStorage" ) ) {
20
- return localStorage . getItem ( "newUserOnboardingPending" ) === "true" ;
21
+ if ( ! storageAvailable ( "localStorage" ) ) {
22
+ return false ;
21
23
}
22
- } , [ ] ) ;
23
- const dismissOrgOnboardingPending = useCallback ( ( ) => {
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 ( ( ) => {
24
37
if ( storageAvailable ( "localStorage" ) ) {
25
- localStorage . removeItem ( "newUserOnboardingPending ") ;
38
+ localStorage . setItem ( "newUserOnboardingDone" , "true ") ;
26
39
}
27
40
28
41
setOrgOnboardingPending ( false ) ;
@@ -31,27 +44,27 @@ export const OrganizationJoinModal = ({ orgSettings }: Props) => {
31
44
32
45
// if the org-wide welcome message is not enabled, prevent showing it in the future
33
46
useEffect ( ( ) => {
34
- if ( ! orgSettings ?. onboardingSettings ?. welcomeMessage ? .enabled ) {
35
- dismissOrgOnboardingPending ( ) ;
47
+ if ( ! welcomeMessage . enabled ) {
48
+ dismissOrgOnboarding ( ) ;
36
49
}
37
- } , [ orgSettings ?. onboardingSettings ?. welcomeMessage ? .enabled , dismissOrgOnboardingPending ] ) ;
50
+ } , [ welcomeMessage . enabled , dismissOrgOnboarding ] ) ;
38
51
39
- if ( ! orgSettings ?. onboardingSettings ?. welcomeMessage ? .enabled ) {
52
+ if ( ! welcomeMessage . enabled || ! orgOnboardingPending ) {
40
53
return null ;
41
54
}
42
55
43
56
return (
44
57
< Modal
45
58
visible = { orgOnboardingPending }
46
- onClose = { dismissOrgOnboardingPending }
59
+ onClose = { dismissOrgOnboarding }
47
60
containerClassName = "min-[576px]:max-w-[650px]"
48
61
>
49
62
< ModalHeader > Welcome to Gitpod</ ModalHeader >
50
63
< ModalBody >
51
64
< WelcomeMessagePreview hideHeader />
52
65
</ ModalBody >
53
66
< ModalFooter >
54
- < Button onClick = { dismissOrgOnboardingPending } > Get Started</ Button >
67
+ < Button onClick = { dismissOrgOnboarding } > Get Started</ Button >
55
68
</ ModalFooter >
56
69
</ Modal >
57
70
) ;
0 commit comments