diff --git a/src/people/widgetViews/WorkspaceDetails.tsx b/src/people/widgetViews/WorkspaceDetails.tsx index 17873cad..c2a64e81 100644 --- a/src/people/widgetViews/WorkspaceDetails.tsx +++ b/src/people/widgetViews/WorkspaceDetails.tsx @@ -3,14 +3,7 @@ import React, { useCallback, useEffect, useState } from 'react'; import { useStores } from 'store'; import { EuiGlobalToastList } from '@elastic/eui'; import { Button } from 'components/common'; -import { - BountyRoles, - defaultWorkspaceBudget, - Workspace, - WorkspaceBudget, - PaymentHistory, - Person -} from 'store/interface'; +import { BountyRoles, Workspace, PaymentHistory, Person } from 'store/interface'; import MaterialIcon from '@material/react-material-icon'; import { Route, Router, Switch, useRouteMatch } from 'react-router-dom'; import { userHasRole } from 'helpers'; @@ -60,7 +53,6 @@ const WorkspaceDetails = (props: { const [isOpenHistory, setIsOpenHistory] = useState(false); const [isOpenEditWorkspace, setIsOpenEditWorkspace] = useState(false); const [showDeleteModal, setShowDeleteModal] = useState(false); - const [orgBudget, setWorkspaceBudget] = useState(defaultWorkspaceBudget); const [paymentsHistory, setPaymentsHistory] = useState([]); const [disableFormButtons, setDisableFormButtons] = useState(false); const [users, setUsers] = useState([]); @@ -145,8 +137,7 @@ const WorkspaceDetails = (props: { const getWorkspaceBudget = useCallback(async () => { if (!viewReportDisabled) { - const workspaceBudget = await main.getWorkspaceBudget(uuid); - setWorkspaceBudget(workspaceBudget); + main.getWorkspaceBudget(uuid); } }, [main, uuid, viewReportDisabled]); diff --git a/src/people/widgetViews/WorkspaceFeature.tsx b/src/people/widgetViews/WorkspaceFeature.tsx index c7dbe234..f1c2231d 100644 --- a/src/people/widgetViews/WorkspaceFeature.tsx +++ b/src/people/widgetViews/WorkspaceFeature.tsx @@ -378,7 +378,7 @@ const WorkspaceFeature = () => { if (featureData?.workspace_uuid && ui.meInfo) { getUserRoles(ui.meInfo); } - }, [getUserRoles]); + }, [getUserRoles, ui.meInfo]); const submitField = async ( field: string, diff --git a/src/people/widgetViews/WorkspaceView.tsx b/src/people/widgetViews/WorkspaceView.tsx index 289dc0b2..7f13dbbc 100644 --- a/src/people/widgetViews/WorkspaceView.tsx +++ b/src/people/widgetViews/WorkspaceView.tsx @@ -158,6 +158,8 @@ const WorkspaceActionWrap = styled.div` } `; +let interval; + const Workspaces = (props: { person: Person }) => { const [loading, setIsLoading] = useState(true); const [isOpen, setIsOpen] = useState(false); @@ -190,6 +192,40 @@ const Workspaces = (props: { person: Person }) => { setDetailsOpen(false); }; + const pollAllInvoices = useCallback(async () => { + let i = 0; + interval = setInterval(async () => { + try { + await main.pollAllUserWorkspaceBudget(); + + const count = await main.allUserWorkspaceInvoiceCount(); + if (count === 0) { + getUserWorkspaces(); + clearInterval(interval); + } + + i++; + if (i > 15) { + if (interval) { + getUserWorkspaces(); + clearInterval(interval); + } + } + } catch (e) { + console.warn('Poll invoices error', e); + } + }, 2000); + }, []); + + useEffect(() => { + if (!detailsOpen) { + pollAllInvoices(); + } + return () => { + clearInterval(interval); + }; + }, [pollAllInvoices, detailsOpen]); + // renders org as list item const orgUi = (org: any, key: number) => { const btnDisabled = (!org.bounty_count && org.bount_count !== 0) || !org.uuid; diff --git a/src/store/main.ts b/src/store/main.ts index 72a85199..72cdfe9e 100644 --- a/src/store/main.ts +++ b/src/store/main.ts @@ -2598,6 +2598,25 @@ export class MainStore { } } + async pollAllUserWorkspaceBudget(): Promise { + try { + if (!uiStore.meInfo) return undefined; + const info = uiStore.meInfo; + + const r: any = await fetch(`${TribesURL}/workspaces/poll/user/invoices`, { + method: 'GET', + mode: 'cors', + headers: { + 'x-jwt': info.tribe_jwt, + 'Content-Type': 'application/json' + } + }); + return r; + } catch (e) { + console.error('Error pollAllUserWorkspaceBudget', e); + } + } + async workspaceInvoiceCount(workspace_uuid: string): Promise { try { if (!uiStore.meInfo) return 0; @@ -2617,6 +2636,25 @@ export class MainStore { } } + async allUserWorkspaceInvoiceCount(): Promise { + try { + if (!uiStore.meInfo) return 0; + const info = uiStore.meInfo; + const r: any = await fetch(`${TribesURL}/workspaces/user/invoices/count`, { + method: 'GET', + mode: 'cors', + headers: { + 'x-jwt': info.tribe_jwt, + 'Content-Type': 'application/json' + } + }); + + return r.json(); + } catch (e) { + console.error('Error pollInvoice', e); + } + } + async workspaceDelete(org_uuid: string): Promise { try { if (!uiStore.meInfo) return 0;