From 6189ec161717b923da43558a45a04770dd1ae85d Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 9 Mar 2022 14:27:27 +0100 Subject: [PATCH] improve user communication on subscription required portal --- docker/nginx/libs/skynet/account.lua | 3 +- .../src/components/Uploader/Uploader.js | 48 ++++++++++++++++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/docker/nginx/libs/skynet/account.lua b/docker/nginx/libs/skynet/account.lua index 7be6013f..e7ff9033 100644 --- a/docker/nginx/libs/skynet/account.lua +++ b/docker/nginx/libs/skynet/account.lua @@ -78,7 +78,8 @@ function _M.has_subscription() end function _M.is_auth_required() - return os.getenv("ACCOUNTS_LIMIT_ACCESS") == "authenticated" + -- authentication is required if mode is set to "authenticated" or "subscription" + return os.getenv("ACCOUNTS_LIMIT_ACCESS") == "authenticated" or _M.is_subscription_required() end function _M.is_subscription_required() diff --git a/packages/website/src/components/Uploader/Uploader.js b/packages/website/src/components/Uploader/Uploader.js index 40ecb19a..5a48a811 100644 --- a/packages/website/src/components/Uploader/Uploader.js +++ b/packages/website/src/components/Uploader/Uploader.js @@ -47,15 +47,37 @@ const LogInLink = () => { ); }; +const SubscribeLink = () => { + const createAccountsUrl = useAccountsUrl(); + + return ( + + available plans + + ); +}; + const Uploader = () => { const [mode, setMode] = React.useState("file"); const [uploads, setUploads] = React.useState([]); const { data: accounts } = useAccounts(); - const showAccountFeatures = - accounts && accounts.enabled !== false && !accounts?.auth_required && !accounts?.authenticated; - const disabledComponent = - accounts && accounts.enabled !== false && accounts?.auth_required && !accounts?.authenticated; + + // variables extracted from useAccounts response + const isAccountsEnabled = accounts?.enabled === true; + const isSubscriptionRequired = accounts?.subscription_required === true; + const isAuthRequired = isSubscriptionRequired || accounts?.auth_required === true; + const isAuthenticated = accounts?.authenticated === true; + const hasSubscription = accounts?.subscription === true; + + // derive current app state and extract it into variables + const showAccountFeatures = isAccountsEnabled && !isAuthRequired && !isAuthenticated; + const showAuthenticationRequired = isAccountsEnabled && isAuthRequired && !isAuthenticated; + const showSubscriptionRequired = isAccountsEnabled && isAuthenticated && isSubscriptionRequired && !hasSubscription; + const isComponentDisabled = showAuthenticationRequired || showSubscriptionRequired; const onUploadStateChange = React.useCallback((id, state) => { setUploads((uploads) => { @@ -104,7 +126,7 @@ const Uploader = () => { }, [inputElement, mode]); return ( -
+
- {!disabledComponent && ( + {!isComponentDisabled && (
@@ -204,7 +226,7 @@ const Uploader = () => {
)} - {disabledComponent && ( + {showAuthenticationRequired && (
@@ -215,6 +237,18 @@ const Uploader = () => {
)} + + {showSubscriptionRequired && ( +
+
+
+

+ Active subscription required - +

+
+
+
+ )}
); };