fix: show subscription info for logged in user and avoid making api call if no account
This commit is contained in:
@@ -32,6 +32,7 @@ export const AccountPreferences = observer(
|
|||||||
<PreferencesPane>
|
<PreferencesPane>
|
||||||
<Credentials application={application} />
|
<Credentials application={application} />
|
||||||
<Sync application={application} />
|
<Sync application={application} />
|
||||||
|
<SubscriptionWrapper application={application} />
|
||||||
<SignOutWrapper application={application} appState={appState} />
|
<SignOutWrapper application={application} appState={appState} />
|
||||||
</PreferencesPane>
|
</PreferencesPane>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export const Subscription: FunctionComponent<Props> = observer(({
|
|||||||
application,
|
application,
|
||||||
subscriptionState,
|
subscriptionState,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
|
|
||||||
const { userSubscription } = subscriptionState;
|
const { userSubscription } = subscriptionState;
|
||||||
@@ -59,8 +59,10 @@ export const Subscription: FunctionComponent<Props> = observer(({
|
|||||||
}, [getSubscription, getSubscriptions]);
|
}, [getSubscription, getSubscriptions]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getSubscriptionInfo();
|
if (application.hasAccount()) {
|
||||||
}, [getSubscriptionInfo]);
|
getSubscriptionInfo();
|
||||||
|
}
|
||||||
|
}, [application, getSubscriptionInfo]);
|
||||||
|
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
|
|
||||||
@@ -71,7 +73,7 @@ export const Subscription: FunctionComponent<Props> = observer(({
|
|||||||
<div className="flex-grow flex flex-col">
|
<div className="flex-grow flex flex-col">
|
||||||
<Title>Subscription</Title>
|
<Title>Subscription</Title>
|
||||||
{error ? (
|
{error ? (
|
||||||
<NoSubscription application={application} />
|
<Text>No subscription information available.</Text>
|
||||||
) : loading ? (
|
) : loading ? (
|
||||||
<Text>Loading subscription information...</Text>
|
<Text>Loading subscription information...</Text>
|
||||||
) : userSubscription && userSubscription.endsAt > now ? (
|
) : userSubscription && userSubscription.endsAt > now ? (
|
||||||
|
|||||||
Reference in New Issue
Block a user