-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement welcome banner for agency dashboard (#63949)
* Implement welcome banner for agency dashboard * Minor code cleanup
- Loading branch information
Showing
6 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
client/jetpack-cloud/sections/agency-dashboard/sites-overview/site-welcome-banner/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { useTranslate } from 'i18n-calypso'; | ||
import { ReactElement, useCallback, useEffect } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import tipIcon from 'calypso/assets/images/jetpack/tip-icon.svg'; | ||
import Banner from 'calypso/components/banner'; | ||
import { | ||
JETPACK_DASHBOARD_WELCOME_BANNER_PREFERENCE, | ||
JETPACK_DASHBOARD_WELCOME_BANNER_PREFERENCE_HOME_PAGE as homePagePreferenceName, | ||
getJetpackDashboardWelcomeBannerPreference as getPreference, | ||
} from 'calypso/state/partner-portal/agency-dashboard/selectors'; | ||
import { savePreference } from 'calypso/state/preferences/actions'; | ||
import type { PreferenceType } from '../types'; | ||
|
||
export default function SiteWelcomeBanner( { | ||
isDashboardView, | ||
bannerKey, | ||
}: { | ||
isDashboardView?: boolean; | ||
bannerKey?: string; | ||
} ): ReactElement | null { | ||
const translate = useTranslate(); | ||
const dispatch = useDispatch(); | ||
|
||
const preferenceName = isDashboardView | ||
? homePagePreferenceName | ||
: `${ JETPACK_DASHBOARD_WELCOME_BANNER_PREFERENCE }-${ bannerKey }`; | ||
const preference = useSelector( ( state ) => getPreference( state, preferenceName ) ); | ||
const homePagePreference = useSelector( ( state ) => | ||
getPreference( state, homePagePreferenceName ) | ||
); | ||
|
||
const savePreferenceType = useCallback( | ||
( type: PreferenceType ) => { | ||
dispatch( savePreference( preferenceName, { ...preference, [ type ]: true } ) ); | ||
}, | ||
[ dispatch, preference, preferenceName ] | ||
); | ||
|
||
const isDismissed = preference?.dismiss; | ||
const hideBanner = ! isDashboardView && homePagePreference?.view; | ||
|
||
useEffect( () => { | ||
if ( ! isDismissed && ! hideBanner ) { | ||
savePreferenceType( 'view' ); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [] ); | ||
|
||
const dismissBanner = useCallback( () => { | ||
savePreferenceType( 'dismiss' ); | ||
}, [ savePreferenceType ] ); | ||
|
||
// Hide the banner if the banner is already viewed | ||
// on the dashboard page or the banner is dismissed | ||
if ( isDismissed || hideBanner ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Banner | ||
title={ translate( 'A new way to manage all your Jetpack sites in one spot' ) } | ||
description={ | ||
isDashboardView | ||
? translate( | ||
'Manage features and discover issues with any of your sites, which are automatically added when Jetpack is connected.' | ||
) | ||
: translate( | ||
'Manage features and discover issues with any of your sites within your new dashboard.' | ||
) | ||
} | ||
disableCircle | ||
horizontal | ||
iconPath={ tipIcon } | ||
callToAction={ isDashboardView ? translate( 'Got it' ) : translate( 'View' ) } | ||
href={ isDashboardView ? '' : '/dashboard' } | ||
onClick={ isDashboardView && dismissBanner } | ||
dismissTemporary={ ! isDashboardView } | ||
onDismiss={ dismissBanner } | ||
dismissPreferenceName={ isDashboardView ? '' : preferenceName } | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { DefaultRootState } from 'react-redux'; | ||
import { Preference } from 'calypso/jetpack-cloud/sections/agency-dashboard/sites-overview/types'; | ||
import { getPreference } from 'calypso/state/preferences/selectors'; | ||
|
||
export const JETPACK_DASHBOARD_WELCOME_BANNER_PREFERENCE = | ||
'jetpack-dashboard-welcome-banner-preference'; | ||
|
||
export const JETPACK_DASHBOARD_WELCOME_BANNER_PREFERENCE_HOME_PAGE = | ||
'jetpack-dashboard-welcome-banner-preference-home-page'; | ||
|
||
/** | ||
* Returns preference associated with the welcome banner. | ||
* | ||
*/ | ||
export function getJetpackDashboardWelcomeBannerPreference( | ||
state: DefaultRootState, | ||
key: string | ||
): Preference { | ||
const preference = getPreference( state, key ); | ||
return preference; | ||
} |