Skip to content

Commit

Permalink
fix: fix the number of requested trust relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
samwel141 committed May 7, 2024
1 parent c11c1d4 commit 267930e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
5 changes: 2 additions & 3 deletions src/components/Routes/ClientRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ const ClientRoutes = () => {
path="/trust-relationship"
exact
element={
<TrustRelationshipsProvider>
<Layout>
<TrustRelationshipsProvider>
<TrustRelationship />
</TrustRelationshipsProvider>

</Layout>
</TrustRelationshipsProvider>
}
/>
<Route
Expand Down
3 changes: 0 additions & 3 deletions src/components/layout/Menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as React from 'react';
import MenuItem from './MenuItem/MenuItem';
import { DrawerHeaderStyled, DrawerStyled } from './MenuStyled';
import TopMenu from './TopMenu/TopMenu';
import { TrustRelationshipsProvider } from '../../../store/TrustRelationshipsContext';

const Menu = ({ open, handleDrawerClose, handleDrawerOpen }) => {
const theme = useTheme();
Expand All @@ -24,9 +23,7 @@ const Menu = ({ open, handleDrawerClose, handleDrawerOpen }) => {
)}
</IconButton>
</DrawerHeaderStyled>
<TrustRelationshipsProvider>
<MenuItem open={open} />
</TrustRelationshipsProvider>
</DrawerStyled>
</>
);
Expand Down
19 changes: 4 additions & 15 deletions src/components/layout/Menu/MenuItem/MenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,12 @@ import DriveFileMoveIcon from '@mui/icons-material/DriveFileMove';
import * as React from 'react';
import LinkItem from './LinkItem';
import { useTrustRelationshipsContext } from '../../../../store/TrustRelationshipsContext';
import { useState, useEffect } from 'react';
import { useState } from 'react';

const MenuItem = ({ open }) => {
const [isHovered, setIsHovered] = useState(false);
const [pendingCount, setPendingCount] = useState(0);
const { tableRows } = useTrustRelationshipsContext();
const { count } = useTrustRelationshipsContext();

useEffect(() => {
let count = 0;

for (let i = 0; i < tableRows.length; i++) {
if (tableRows[i].state === 'requested') {
count++;
}
}
setPendingCount(count);
}, [tableRows]);
return (
<>
<LinkItem
Expand Down Expand Up @@ -54,7 +43,7 @@ const MenuItem = ({ open }) => {
isActive={location.pathname === '/list-wallets'}
open={open}
/>
{pendingCount > 0 && open ? (
{count > 0 && open ? (
<div
style={{
display: 'flex',
Expand All @@ -70,7 +59,7 @@ const MenuItem = ({ open }) => {
itemIcon={<HandshakeIcon />}
isActive={location.pathname === '/trust-relationship'}
open={open}
pendingCount={pendingCount}
pendingCount={count}
/>
</div>
) : (
Expand Down
9 changes: 9 additions & 0 deletions src/store/TrustRelationshipsContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const TrustRelationshipsProvider = ({ children }) => {
const [searchString, setSearchString] = useState('');

const [refetch, setRefetch] = useState(false);
const [count, setCount] = useState(0);

// Loader
const [isLoading, setIsLoading] = useState(false);
Expand Down Expand Up @@ -188,6 +189,13 @@ const TrustRelationshipsProvider = ({ children }) => {
sorting,
});

let local_count = 0;
for (const item of data.trust_relationships) {
if (item.state === 'requested') {
local_count++;
}
}
setCount(local_count);
const preparedRows = prepareRows(await data.trust_relationships);

setTableRows(preparedRows);
Expand All @@ -206,6 +214,7 @@ const TrustRelationshipsProvider = ({ children }) => {
}, [pagination, filter, sorting, refetch]);

const value = {
count,
pagination,
setPagination,
isLoading,
Expand Down

0 comments on commit 267930e

Please # to comment.