fix: reload subscription state after event (#727)
* fix: reload subscription state after event * chore: yarn.lock * chore: lint * fix: hook exhaustive deps
This commit is contained in:
@@ -11,6 +11,7 @@ import { NoSubscription } from './NoSubscription';
|
|||||||
import { Text } from '@/preferences/components';
|
import { Text } from '@/preferences/components';
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import { FunctionComponent } from 'preact';
|
import { FunctionComponent } from 'preact';
|
||||||
|
import { ApplicationEvent } from '@standardnotes/snjs';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication;
|
application: WebApplication;
|
||||||
@@ -58,6 +59,20 @@ export const Subscription: FunctionComponent<Props> = observer(({
|
|||||||
}
|
}
|
||||||
}, [getSubscription, getSubscriptions]);
|
}, [getSubscription, getSubscriptions]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const removeUserRoleObserver = application.addEventObserver(
|
||||||
|
async () => {
|
||||||
|
await getSubscription();
|
||||||
|
await getSubscriptions();
|
||||||
|
},
|
||||||
|
ApplicationEvent.UserRolesChanged
|
||||||
|
);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
removeUserRoleObserver();
|
||||||
|
};
|
||||||
|
}, [application, getSubscription, getSubscriptions]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (application.hasAccount()) {
|
if (application.hasAccount()) {
|
||||||
getSubscriptionInfo();
|
getSubscriptionInfo();
|
||||||
@@ -77,7 +92,7 @@ export const Subscription: FunctionComponent<Props> = observer(({
|
|||||||
) : loading ? (
|
) : loading ? (
|
||||||
<Text>Loading subscription information...</Text>
|
<Text>Loading subscription information...</Text>
|
||||||
) : userSubscription && userSubscription.endsAt > now ? (
|
) : userSubscription && userSubscription.endsAt > now ? (
|
||||||
<SubscriptionInformation subscriptionState={subscriptionState} application={application}/>
|
<SubscriptionInformation subscriptionState={subscriptionState} application={application} />
|
||||||
) : (
|
) : (
|
||||||
<NoSubscription application={application} />
|
<NoSubscription application={application} />
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
"@reach/listbox": "^0.16.2",
|
"@reach/listbox": "^0.16.2",
|
||||||
"@standardnotes/features": "1.8.1",
|
"@standardnotes/features": "1.8.1",
|
||||||
"@standardnotes/sncrypto-web": "1.5.3",
|
"@standardnotes/sncrypto-web": "1.5.3",
|
||||||
"@standardnotes/snjs": "2.17.2",
|
"@standardnotes/snjs": "2.17.4",
|
||||||
"mobx": "^6.3.5",
|
"mobx": "^6.3.5",
|
||||||
"mobx-react-lite": "^3.2.1",
|
"mobx-react-lite": "^3.2.1",
|
||||||
"preact": "^10.5.15",
|
"preact": "^10.5.15",
|
||||||
|
|||||||
@@ -2192,10 +2192,10 @@
|
|||||||
buffer "^6.0.3"
|
buffer "^6.0.3"
|
||||||
libsodium-wrappers "^0.7.9"
|
libsodium-wrappers "^0.7.9"
|
||||||
|
|
||||||
"@standardnotes/snjs@2.17.2":
|
"@standardnotes/snjs@2.17.4":
|
||||||
version "2.17.2"
|
version "2.17.4"
|
||||||
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.17.2.tgz#69a54769291495fe0f4062892a7defaf6b22c0ed"
|
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.17.4.tgz#ebf9d59a297ee7d87db1631e8850ba53dd9e7bea"
|
||||||
integrity sha512-JSvCwfcDqphWiGSUD5rAbQSMBAd0nmuzeCTnEU2Ee916/nxpNXuiovPPx2xbnxh1hNgBa6cY4nbUsw6szuhCMA==
|
integrity sha512-ucxhSG8scDZd+JguK0bPLNwSg99w+jpYnCM+RZpd6GTkVjHBy3DEFnM06KrDzubLAtbKE8b7I50DOI+5C4p2rg==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@standardnotes/auth" "^3.8.1"
|
"@standardnotes/auth" "^3.8.1"
|
||||||
"@standardnotes/common" "^1.2.1"
|
"@standardnotes/common" "^1.2.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user