mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
feat(subscription): invalidate subscription cache
This commit is contained in:
@@ -117,6 +117,7 @@ import { DisconnectPlaidItemOnAccountDeleted } from '@/services/Banking/BankAcco
|
|||||||
import { LoopsEventsSubscriber } from '@/services/Loops/LoopsEventsSubscriber';
|
import { LoopsEventsSubscriber } from '@/services/Loops/LoopsEventsSubscriber';
|
||||||
import { DeleteUncategorizedTransactionsOnAccountDeleting } from '@/services/Banking/BankAccounts/events/DeleteUncategorizedTransactionsOnAccountDeleting';
|
import { DeleteUncategorizedTransactionsOnAccountDeleting } from '@/services/Banking/BankAccounts/events/DeleteUncategorizedTransactionsOnAccountDeleting';
|
||||||
import { SeedInitialDemoAccountDataOnOrgBuild } from '@/services/OneClickDemo/events/SeedInitialDemoAccountData';
|
import { SeedInitialDemoAccountDataOnOrgBuild } from '@/services/OneClickDemo/events/SeedInitialDemoAccountData';
|
||||||
|
import { TriggerInvalidateCacheOnSubscriptionChange } from '@/services/Subscription/events/TriggerInvalidateCacheOnSubscriptionChange';
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
return new EventPublisher();
|
return new EventPublisher();
|
||||||
@@ -247,8 +248,10 @@ export const susbcribers = () => {
|
|||||||
DeleteCashflowTransactionOnUncategorize,
|
DeleteCashflowTransactionOnUncategorize,
|
||||||
PreventDeleteTransactionOnDelete,
|
PreventDeleteTransactionOnDelete,
|
||||||
|
|
||||||
|
// Subscription
|
||||||
SubscribeFreeOnSignupCommunity,
|
SubscribeFreeOnSignupCommunity,
|
||||||
SendVerfiyMailOnSignUp,
|
SendVerfiyMailOnSignUp,
|
||||||
|
TriggerInvalidateCacheOnSubscriptionChange,
|
||||||
|
|
||||||
// Attachments
|
// Attachments
|
||||||
AttachmentsOnSaleInvoiceCreated,
|
AttachmentsOnSaleInvoiceCreated,
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import events from '@/subscribers/events';
|
||||||
|
import Container from 'typedi';
|
||||||
|
|
||||||
|
export class TriggerInvalidateCacheOnSubscriptionChange {
|
||||||
|
/**
|
||||||
|
* Attaches events with handlers.
|
||||||
|
*/
|
||||||
|
public attach = (bus) => {
|
||||||
|
bus.subscribe(
|
||||||
|
events.subscription.onSubscriptionCancelled,
|
||||||
|
this.triggerInvalidateCache.bind(this)
|
||||||
|
);
|
||||||
|
bus.subscribe(
|
||||||
|
events.subscription.onSubscriptionResumed,
|
||||||
|
this.triggerInvalidateCache.bind(this)
|
||||||
|
);
|
||||||
|
bus.subscribe(
|
||||||
|
events.subscription.onSubscriptionPlanChanged,
|
||||||
|
this.triggerInvalidateCache.bind(this)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
private triggerInvalidateCache() {
|
||||||
|
const io = Container.get('socket');
|
||||||
|
|
||||||
|
// Notify the frontend to reflect the new transactions changes.
|
||||||
|
io.emit('SUBSCRIPTION_CHANGED', { subscriptionSlug: 'main' });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,9 @@ export function DashboardSockets() {
|
|||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
socket.current.on('SUBSCRIPTION_CHANGED', () => {
|
||||||
|
client.invalidateQueries('GetSubscriptions');
|
||||||
|
});
|
||||||
return () => {
|
return () => {
|
||||||
socket.current.removeAllListeners();
|
socket.current.removeAllListeners();
|
||||||
socket.current.close();
|
socket.current.close();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import useApiRequest from '../useRequest';
|
|||||||
import { transformToCamelCase } from '@/utils';
|
import { transformToCamelCase } from '@/utils';
|
||||||
|
|
||||||
const QueryKeys = {
|
const QueryKeys = {
|
||||||
Subscriptions: 'Subscriptions',
|
Subscriptions: 'GetSubscriptions',
|
||||||
};
|
};
|
||||||
|
|
||||||
interface CancelMainSubscriptionValues {}
|
interface CancelMainSubscriptionValues {}
|
||||||
|
|||||||
Reference in New Issue
Block a user