From 4f00604ed435142f3778d20862a2b41906fe88d6 Mon Sep 17 00:00:00 2001 From: Rish Date: Thu, 24 Sep 2020 15:43:39 +0530 Subject: [PATCH] Added helpers to generate portal link for pages no issue - Adds new helpers to create portal links on existing site url paths - Updates retry links for signin and signup to use new helpers - Helps preventing any unwanted bugs with Portal links by providing consistent link creation --- ghost/portal/src/components/Notification.js | 7 +++++-- ghost/portal/src/utils/helpers.js | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ghost/portal/src/components/Notification.js b/ghost/portal/src/components/Notification.js index f82fe8c1a8..5d47450e5b 100644 --- a/ghost/portal/src/components/Notification.js +++ b/ghost/portal/src/components/Notification.js @@ -3,6 +3,7 @@ import AppContext from '../AppContext'; import NotificationStyle from './Notification.styles'; import {ReactComponent as CloseIcon} from '../images/icons/close.svg'; import NotificationParser, {clearURLParams} from '../utils/notifications'; +import { getPortalLink } from '../utils/helpers'; const React = require('react'); @@ -24,6 +25,8 @@ const Styles = () => { }; const NotificationText = ({type, status, context}) => { + const signinPortalLink = getPortalLink({page: 'signin', siteUrl: context.site.url}); + const singupPortalLink = getPortalLink({page: 'signup', siteUrl: context.site.url}); if (type === 'signin' && status === 'success') { return (

@@ -33,7 +36,7 @@ const NotificationText = ({type, status, context}) => { } else if (type === 'signin' && status === 'error') { return (

- Could not sign in! Login link expired. Click here to retry + Could not sign in! Login link expired. Click here to retry

); } else if (type === 'signup' && status === 'success') { @@ -45,7 +48,7 @@ const NotificationText = ({type, status, context}) => { } else if (type === 'signup' && status === 'error') { return (

- Could not sign up! Invalid sign up link. Click here to retry + Could not sign up! Invalid sign up link. Click here to retry

); } else if (type === 'stripe:checkout' && status === 'success') { diff --git a/ghost/portal/src/utils/helpers.js b/ghost/portal/src/utils/helpers.js index dd257655c7..39ae3e0d95 100644 --- a/ghost/portal/src/utils/helpers.js +++ b/ghost/portal/src/utils/helpers.js @@ -1,5 +1,26 @@ import CalculateDiscount from './discount'; +export function getPortalLinkPath({page}) { + const Links = { + 'default': '#/portal', + 'signin': '#/portal/signin', + 'signup': '#/portal/signup', + 'account': '#/portal/account', + 'account-plans': '#/portal/account/plans', + 'account-profile': '#/portal/account/profile', + }; + if (Object.keys(Links).includes(page)) { + return Links[page]; + } + return Links.default; +} + +export function getPortalLink({page, siteUrl}) { + const url = siteUrl || `${window.location.protocol}//${window.location.host}${window.location.pathname}`; + const portalLinkPath = getPortalLinkPath({page}); + return `${url}${portalLinkPath}`; +} + export function isCookiesDisabled() { return !(navigator && navigator.cookieEnabled); }