Skip to content

Commit

Permalink
fix: reload subscription state after event (#727)
Browse files Browse the repository at this point in the history
* fix: reload subscription state after event

* chore: yarn.lock

* chore: lint

* fix: hook exhaustive deps
  • Loading branch information
Mo authored Nov 10, 2021
1 parent 8c3271b commit 73b91e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { NoSubscription } from './NoSubscription';
import { Text } from '@/preferences/components';
import { observer } from 'mobx-react-lite';
import { FunctionComponent } from 'preact';
import { ApplicationEvent } from '@standardnotes/snjs';

type Props = {
application: WebApplication;
Expand Down Expand Up @@ -58,6 +59,20 @@ export const Subscription: FunctionComponent<Props> = observer(({
}
}, [getSubscription, getSubscriptions]);

useEffect(() => {
const removeUserRoleObserver = application.addEventObserver(
async () => {
await getSubscription();
await getSubscriptions();
},
ApplicationEvent.UserRolesChanged
);

return () => {
removeUserRoleObserver();
};
}, [application, getSubscription, getSubscriptions]);

useEffect(() => {
if (application.hasAccount()) {
getSubscriptionInfo();
Expand All @@ -77,7 +92,7 @@ export const Subscription: FunctionComponent<Props> = observer(({
) : loading ? (
<Text>Loading subscription information...</Text>
) : userSubscription && userSubscription.endsAt > now ? (
<SubscriptionInformation subscriptionState={subscriptionState} application={application}/>
<SubscriptionInformation subscriptionState={subscriptionState} application={application} />
) : (
<NoSubscription application={application} />
)}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@reach/listbox": "^0.16.2",
"@standardnotes/features": "1.8.1",
"@standardnotes/sncrypto-web": "1.5.3",
"@standardnotes/snjs": "2.17.2",
"@standardnotes/snjs": "2.17.4",
"mobx": "^6.3.5",
"mobx-react-lite": "^3.2.1",
"preact": "^10.5.15",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2192,10 +2192,10 @@
buffer "^6.0.3"
libsodium-wrappers "^0.7.9"

"@standardnotes/[email protected].2":
version "2.17.2"
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.17.2.tgz#69a54769291495fe0f4062892a7defaf6b22c0ed"
integrity sha512-JSvCwfcDqphWiGSUD5rAbQSMBAd0nmuzeCTnEU2Ee916/nxpNXuiovPPx2xbnxh1hNgBa6cY4nbUsw6szuhCMA==
"@standardnotes/[email protected].4":
version "2.17.4"
resolved "https://registry.yarnpkg.com/@standardnotes/snjs/-/snjs-2.17.4.tgz#ebf9d59a297ee7d87db1631e8850ba53dd9e7bea"
integrity sha512-ucxhSG8scDZd+JguK0bPLNwSg99w+jpYnCM+RZpd6GTkVjHBy3DEFnM06KrDzubLAtbKE8b7I50DOI+5C4p2rg==
dependencies:
"@standardnotes/auth" "^3.8.1"
"@standardnotes/common" "^1.2.1"
Expand Down

0 comments on commit 73b91e5

Please sign in to comment.