Skip to content

Commit 11f32e9

Browse files
committed
fix: display streaming navigation item conditionally
1 parent 0a29488 commit 11f32e9

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/components/v5/shared/Navigation/Sidebar/sidebars/ColonyPageSidebar/partials/SidebarRoutesSection.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import React from 'react';
22

33
import SidebarRouteItem from '~v5/shared/Navigation/Sidebar/partials/SidebarRouteItem/index.ts';
44

5-
import { sidebarNavigationScheme } from '../consts.ts';
5+
import { useSidebarRoutesScheme } from './hooks.ts';
66

77
export const SidebarRoutesSection = () => {
8+
const { sidebarScheme: sidebarNavigationScheme } = useSidebarRoutesScheme();
9+
810
return (
911
<section className="flex w-full flex-col gap-0 md:gap-0.5">
1012
{sidebarNavigationScheme.map((scheme) => (
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Extension } from '@colony/colony-js';
2+
3+
import { useColonyContext } from '~context/ColonyContext/ColonyContext.ts';
4+
import { useSearchActionsQuery } from '~gql';
5+
import useExtensionData from '~hooks/useExtensionData.ts';
6+
import { COLONY_STREAMING_PAYMENTS_ROUTE } from '~routes';
7+
import { isInstalledExtensionData } from '~utils/extensions.ts';
8+
9+
import { sidebarNavigationScheme } from '../consts.ts';
10+
11+
export const useSidebarRoutesScheme = () => {
12+
const { colony } = useColonyContext();
13+
14+
const { colonyAddress } = colony;
15+
16+
const { data } = useSearchActionsQuery({
17+
variables: {
18+
filter: {
19+
colonyId: { eq: colonyAddress },
20+
type: { eq: 'CREATE_STREAMING_PAYMENT' },
21+
},
22+
limit: 5,
23+
},
24+
});
25+
26+
const excludeSubitemsPaths = (subitemsPathsToExclude: string[]) =>
27+
sidebarNavigationScheme.map((item) => {
28+
return {
29+
...item,
30+
subItems: item.subItems?.filter(
31+
(subItem) => !subitemsPathsToExclude.includes(subItem.path),
32+
),
33+
};
34+
});
35+
36+
const hasStreamings = !!data?.searchColonyActions?.items.length;
37+
38+
const { extensionData } = useExtensionData(Extension.StreamingPayments);
39+
const isStreamingPaymentsInstalled =
40+
extensionData && isInstalledExtensionData(extensionData);
41+
42+
const isStreamingsRouteVisible =
43+
isStreamingPaymentsInstalled || hasStreamings;
44+
45+
const sidebarScheme = excludeSubitemsPaths(
46+
isStreamingsRouteVisible ? [] : [COLONY_STREAMING_PAYMENTS_ROUTE],
47+
);
48+
49+
return {
50+
sidebarScheme,
51+
};
52+
};

0 commit comments

Comments
 (0)