From 6f18664564be8d64ba8ea1c3c96dc6b9fb796f43 Mon Sep 17 00:00:00 2001 From: Gorjan Petrovski Date: Mon, 11 Oct 2021 17:29:41 +0200 Subject: [PATCH] feat(preferences): no-subscription for non logged in users (#676) * feat(preferences): no-subscription for non logged in users * fix: check if user has account using application.hasAccount() --- .../components/AccountMenu/Authentication.tsx | 4 +--- .../components/AccountMenu/Footer.tsx | 4 +--- .../preferences/panes/AccountPreferences.tsx | 5 ++-- .../preferences/panes/account/SignOutView.tsx | 3 +-- .../account/subscription/NoSubscription.tsx | 23 ++++++++++--------- .../account/subscription/Subscription.tsx | 2 +- 6 files changed, 18 insertions(+), 23 deletions(-) diff --git a/app/assets/javascripts/components/AccountMenu/Authentication.tsx b/app/assets/javascripts/components/AccountMenu/Authentication.tsx index cc401159a..3687f0865 100644 --- a/app/assets/javascripts/components/AccountMenu/Authentication.tsx +++ b/app/assets/javascripts/components/AccountMenu/Authentication.tsx @@ -43,8 +43,6 @@ const Authentication = observer(({ application, appState }: Props) => { closeAccountMenu, } = appState.accountMenu; - const user = application.getUser(); - useEffect(() => { if (isEmailFocused) { emailInputRef.current.focus(); @@ -207,7 +205,7 @@ const Authentication = observer(({ application, appState }: Props) => { return ( <> - {!user && !showSignIn && !showRegister && ( + {!application.hasAccount() && !showSignIn && !showRegister && (
diff --git a/app/assets/javascripts/components/AccountMenu/Footer.tsx b/app/assets/javascripts/components/AccountMenu/Footer.tsx index c5c291342..ac4b67f9d 100644 --- a/app/assets/javascripts/components/AccountMenu/Footer.tsx +++ b/app/assets/javascripts/components/AccountMenu/Footer.tsx @@ -17,8 +17,6 @@ const Footer = observer(({ application, appState }: Props) => { setSigningOut, } = appState.accountMenu; - const user = application.getUser(); - const { showBetaWarning, disableBetaWarning: disableAppStateBetaWarning } = appState; @@ -62,7 +60,7 @@ const Footer = observer(({ application, appState }: Props) => { )} {!showSignIn && !showRegister && ( - {user ? 'Sign out' : 'Clear session data'} + {application.hasAccount() ? 'Sign out' : 'Clear session data'} )}
diff --git a/app/assets/javascripts/preferences/panes/AccountPreferences.tsx b/app/assets/javascripts/preferences/panes/AccountPreferences.tsx index 1523e9a0f..90161807a 100644 --- a/app/assets/javascripts/preferences/panes/AccountPreferences.tsx +++ b/app/assets/javascripts/preferences/panes/AccountPreferences.tsx @@ -17,12 +17,12 @@ type Props = { export const AccountPreferences = observer( ({ application, appState }: Props) => { - const isLoggedIn = application.getUser(); - if (!isLoggedIn) { + if (!application.hasAccount()) { return ( + ); @@ -32,7 +32,6 @@ export const AccountPreferences = observer( - ); diff --git a/app/assets/javascripts/preferences/panes/account/SignOutView.tsx b/app/assets/javascripts/preferences/panes/account/SignOutView.tsx index 725e8b7f3..3c713dc04 100644 --- a/app/assets/javascripts/preferences/panes/account/SignOutView.tsx +++ b/app/assets/javascripts/preferences/panes/account/SignOutView.tsx @@ -96,8 +96,7 @@ export const SignOutWrapper: FunctionComponent<{ application: WebApplication; appState: AppState; }> = observer(({ application, appState }) => { - const isLoggedIn = application.getUser() != undefined; - if (!isLoggedIn) + if (!application.hasAccount()) return ( ); diff --git a/app/assets/javascripts/preferences/panes/account/subscription/NoSubscription.tsx b/app/assets/javascripts/preferences/panes/account/subscription/NoSubscription.tsx index 071331823..ca5a1c953 100644 --- a/app/assets/javascripts/preferences/panes/account/subscription/NoSubscription.tsx +++ b/app/assets/javascripts/preferences/panes/account/subscription/NoSubscription.tsx @@ -1,5 +1,5 @@ import { FunctionalComponent } from "preact"; -import { Text } from '@/preferences/components'; +import { LinkButton, Text } from '@/preferences/components'; import { Button } from '@/components/Button'; import { WebApplication } from "@/ui_models/application"; import { useState } from "preact/hooks"; @@ -44,18 +44,19 @@ export const NoSubscription: FunctionalComponent<{ )}
-
); diff --git a/app/assets/javascripts/preferences/panes/account/subscription/Subscription.tsx b/app/assets/javascripts/preferences/panes/account/subscription/Subscription.tsx index 0e9ce9126..780af8c8c 100644 --- a/app/assets/javascripts/preferences/panes/account/subscription/Subscription.tsx +++ b/app/assets/javascripts/preferences/panes/account/subscription/Subscription.tsx @@ -71,7 +71,7 @@ export const Subscription: FunctionComponent = observer(({
Subscription {error ? ( - No subscription information available. + ) : loading ? ( Loading subscription information... ) : userSubscription && userSubscription.endsAt > now ? (