44 * See License.AGPL.txt in the project root for license information.
55 */
66
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" ;
88import { Button } from "@podkit/buttons/Button" ;
99import { useCallback , useEffect , useMemo , useState } from "react" ;
1010import { Modal , ModalBody , ModalFooter , ModalHeader } from "../../components/Modal" ;
1111import { storageAvailable } from "../../utils" ;
1212import { WelcomeMessagePreview } from "./WelcomeMessagePreview" ;
13+ import { User } from "@gitpod/public-api/lib/gitpod/v1/user_pb" ;
1314
1415type Props = {
15- orgSettings : OrganizationSettings ;
16+ user : User ;
17+ welcomeMessage : OnboardingSettings_WelcomeMessage ;
1618} ;
17- export const OrganizationJoinModal = ( { orgSettings } : Props ) => {
19+ export const OrganizationJoinModal = ( { welcomeMessage , user } : Props ) => {
1820 const initialOrgOnboardingPending = useMemo ( ( ) => {
19- if ( storageAvailable ( "localStorage" ) ) {
20- return localStorage . getItem ( "newUserOnboardingPending" ) === "true" ;
21+ if ( ! storageAvailable ( "localStorage" ) ) {
22+ return false ;
2123 }
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 ( ( ) => {
2437 if ( storageAvailable ( "localStorage" ) ) {
25- localStorage . removeItem ( "newUserOnboardingPending ") ;
38+ localStorage . setItem ( "newUserOnboardingDone" , "true ") ;
2639 }
2740
2841 setOrgOnboardingPending ( false ) ;
@@ -31,27 +44,27 @@ export const OrganizationJoinModal = ({ orgSettings }: Props) => {
3144
3245 // if the org-wide welcome message is not enabled, prevent showing it in the future
3346 useEffect ( ( ) => {
34- if ( ! orgSettings ?. onboardingSettings ?. welcomeMessage ? .enabled ) {
35- dismissOrgOnboardingPending ( ) ;
47+ if ( ! welcomeMessage . enabled ) {
48+ dismissOrgOnboarding ( ) ;
3649 }
37- } , [ orgSettings ?. onboardingSettings ?. welcomeMessage ? .enabled , dismissOrgOnboardingPending ] ) ;
50+ } , [ welcomeMessage . enabled , dismissOrgOnboarding ] ) ;
3851
39- if ( ! orgSettings ?. onboardingSettings ?. welcomeMessage ? .enabled ) {
52+ if ( ! welcomeMessage . enabled || ! orgOnboardingPending ) {
4053 return null ;
4154 }
4255
4356 return (
4457 < Modal
4558 visible = { orgOnboardingPending }
46- onClose = { dismissOrgOnboardingPending }
59+ onClose = { dismissOrgOnboarding }
4760 containerClassName = "min-[576px]:max-w-[650px]"
4861 >
4962 < ModalHeader > Welcome to Gitpod</ ModalHeader >
5063 < ModalBody >
5164 < WelcomeMessagePreview hideHeader />
5265 </ ModalBody >
5366 < ModalFooter >
54- < Button onClick = { dismissOrgOnboardingPending } > Get Started</ Button >
67+ < Button onClick = { dismissOrgOnboarding } > Get Started</ Button >
5568 </ ModalFooter >
5669 </ Modal >
5770 ) ;
0 commit comments