mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
feat: add socker connection between client and server
This commit is contained in:
@@ -14,6 +14,7 @@ import GlobalHotkeys from './GlobalHotkeys';
|
||||
import DashboardProvider from './DashboardProvider';
|
||||
import DrawersContainer from '@/components/DrawersContainer';
|
||||
import AlertsContainer from '@/containers/AlertsContainer';
|
||||
import { DashboardSockets } from './DashboardSockets';
|
||||
|
||||
/**
|
||||
* Dashboard preferences.
|
||||
@@ -50,6 +51,7 @@ export default function Dashboard() {
|
||||
<Route path="/" component={DashboardAnyPage} />
|
||||
</Switch>
|
||||
|
||||
<DashboardSockets />
|
||||
<DashboardUniversalSearch />
|
||||
<GlobalHotkeys />
|
||||
<DialogsContainer />
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { useQueryClient } from 'react-query';
|
||||
import { io } from 'socket.io-client';
|
||||
import t from '@/hooks/query/types';
|
||||
import { AppToaster } from '@/components';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
|
||||
export function DashboardSockets() {
|
||||
const socket = useRef<any>();
|
||||
const client = useQueryClient();
|
||||
|
||||
useEffect(() => {
|
||||
socket.current = io('ws://localhost:4000');
|
||||
|
||||
socket.current.on('NEW_TRANSACTIONS_DATA', () => {
|
||||
client.invalidateQueries(t.ACCOUNTS);
|
||||
client.invalidateQueries(t.ACCOUNT_TRANSACTION);
|
||||
client.invalidateQueries(t.CASH_FLOW_ACCOUNTS);
|
||||
client.invalidateQueries(t.CASH_FLOW_TRANSACTIONS);
|
||||
|
||||
AppToaster.show({
|
||||
message: 'The Plaid connected accounts have been updated.',
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
});
|
||||
return () => {
|
||||
socket.current.removeAllListeners();
|
||||
socket.current.close();
|
||||
};
|
||||
}, []);
|
||||
}
|
||||
Reference in New Issue
Block a user