Skip to content

Commit

Permalink
fix: display streaming navigation item conditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-strzelec committed Jan 14, 2025
1 parent 4458356 commit 213c22d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React from 'react';

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

import { sidebarNavigationScheme } from '../consts.ts';
import { useSidebarRoutesScheme } from './hooks.ts';

export const SidebarRoutesSection = () => {
const { sidebarScheme: sidebarNavigationScheme } = useSidebarRoutesScheme();

return (
<section className="flex w-full flex-col gap-0 md:gap-0.5">
{sidebarNavigationScheme.map((scheme) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Extension } from '@colony/colony-js';

import { useColonyContext } from '~context/ColonyContext/ColonyContext.ts';
import { useSearchActionsQuery } from '~gql';
import useExtensionData from '~hooks/useExtensionData.ts';
import { COLONY_STREAMING_PAYMENTS_ROUTE } from '~routes';
import { isInstalledExtensionData } from '~utils/extensions.ts';

import { sidebarNavigationScheme } from '../consts.ts';

export const useSidebarRoutesScheme = () => {
const { colony } = useColonyContext();

const { colonyAddress } = colony;

const { data } = useSearchActionsQuery({
variables: {
filter: {
colonyId: { eq: colonyAddress },
type: { eq: 'CREATE_STREAMING_PAYMENT' },
},
limit: 5,
},
});

const excludeSubitemsPaths = (subitemsPathsToExclude: string[]) =>
sidebarNavigationScheme.map((item) => {
return {
...item,
subItems: item.subItems?.filter(
(subItem) => !subitemsPathsToExclude.includes(subItem.path),
),
};
});

const hasStreamings = !!data?.searchColonyActions?.items.length;

const { extensionData } = useExtensionData(Extension.StreamingPayments);
const isStreamingPaymentsInstalled =
extensionData && isInstalledExtensionData(extensionData);

const isStreamingsRouteVisible =
isStreamingPaymentsInstalled || hasStreamings;

const sidebarScheme = excludeSubitemsPaths(
isStreamingsRouteVisible ? [] : [COLONY_STREAMING_PAYMENTS_ROUTE],
);

return {
sidebarScheme,
};
};

0 comments on commit 213c22d

Please sign in to comment.