From a21482981cfe39f6e8245f8420508954808e8b1e Mon Sep 17 00:00:00 2001 From: Yashwin Date: Thu, 24 Oct 2024 10:32:20 +0530 Subject: [PATCH] Update Partner Directory permission check --- .../sidebar-menu/hooks/use-main-menu-items.ts | 22 ++++++++----------- .../partner-directory/partner-directory.tsx | 13 +---------- .../state/a8c-for-agencies/agency/actions.ts | 2 +- client/state/a8c-for-agencies/types.ts | 5 ++++- 4 files changed, 15 insertions(+), 27 deletions(-) diff --git a/client/a8c-for-agencies/components/sidebar-menu/hooks/use-main-menu-items.ts b/client/a8c-for-agencies/components/sidebar-menu/hooks/use-main-menu-items.ts index b2903c4a729a9..ef253fed95178 100644 --- a/client/a8c-for-agencies/components/sidebar-menu/hooks/use-main-menu-items.ts +++ b/client/a8c-for-agencies/components/sidebar-menu/hooks/use-main-menu-items.ts @@ -137,19 +137,15 @@ const useMainMenuItems = ( path: string ) => { }, ] : [] ), - ...( config.isEnabled( 'a4a-partner-directory' ) - ? [ - { - icon: commentAuthorAvatar, - path: '/dashboard', - link: A4A_PARTNER_DIRECTORY_DASHBOARD_LINK, - title: translate( 'Partner Directory' ), - trackEventProps: { - menu_item: 'Automattic for Agencies / Partner Directory', - }, - }, - ] - : [] ), + { + icon: commentAuthorAvatar, + path: '/dashboard', + link: A4A_PARTNER_DIRECTORY_DASHBOARD_LINK, + title: translate( 'Partner Directory' ), + trackEventProps: { + menu_item: 'Automattic for Agencies / Partner Directory', + }, + }, ...( isSectionNameEnabled( 'a8c-for-agencies-settings' ) ? [ { diff --git a/client/a8c-for-agencies/sections/partner-directory/partner-directory.tsx b/client/a8c-for-agencies/sections/partner-directory/partner-directory.tsx index 5ee19cb242b97..547ecd23fda4f 100644 --- a/client/a8c-for-agencies/sections/partner-directory/partner-directory.tsx +++ b/client/a8c-for-agencies/sections/partner-directory/partner-directory.tsx @@ -1,4 +1,3 @@ -import page from '@automattic/calypso-router'; import clsx from 'clsx'; import { useTranslate } from 'i18n-calypso'; import { ReactNode, useMemo } from 'react'; @@ -10,10 +9,7 @@ import LayoutHeader, { } from 'calypso/a8c-for-agencies/components/layout/header'; import LayoutTop from 'calypso/a8c-for-agencies/components/layout/top'; import MobileSidebarNavigation from 'calypso/a8c-for-agencies/components/sidebar/mobile-sidebar-navigation'; -import { - A4A_OVERVIEW_LINK, - A4A_PARTNER_DIRECTORY_LINK, -} from 'calypso/a8c-for-agencies/components/sidebar-menu/lib/constants'; +import { A4A_PARTNER_DIRECTORY_LINK } from 'calypso/a8c-for-agencies/components/sidebar-menu/lib/constants'; import { Item as BreadcrumbItem } from 'calypso/components/breadcrumb'; import { useSelector } from 'calypso/state'; import { @@ -102,13 +98,6 @@ export default function PartnerDirectory( { selectedSection }: Props ) { return null; } - // Check if the Partner Directory is allowed for the agency - if ( ! agency?.partner_directory_allowed ) { - // Redirect user to the Overview page - page.redirect( A4A_OVERVIEW_LINK ); - return; - } - // Set the selected section const section: Section = sections[ selectedSection ]; diff --git a/client/state/a8c-for-agencies/agency/actions.ts b/client/state/a8c-for-agencies/agency/actions.ts index f3f16bc5b26b0..610d114e7f01a 100644 --- a/client/state/a8c-for-agencies/agency/actions.ts +++ b/client/state/a8c-for-agencies/agency/actions.ts @@ -57,7 +57,7 @@ export function receiveAgencies( agencies: Agency[] ): AgencyThunkAction { dispatch( setActiveAgency( newAgency ) ); // Enable the Partner Directory section - if ( ! config.isEnabled( 'a4a-partner-directory' ) && newAgency.partner_directory_allowed ) { + if ( ! config.isEnabled( 'a4a-partner-directory' ) && newAgency.partner_directory.allowed ) { config.enable( 'a4a-partner-directory' ); } } diff --git a/client/state/a8c-for-agencies/types.ts b/client/state/a8c-for-agencies/types.ts index 2ac77c50475e6..483c59f9a45e3 100644 --- a/client/state/a8c-for-agencies/types.ts +++ b/client/state/a8c-for-agencies/types.ts @@ -70,7 +70,10 @@ export interface Agency { is_published?: boolean; }; }; - partner_directory_allowed: boolean; + partner_directory: { + allowed: boolean; + directories: 'wordpress' | 'jetpack' | 'woocommerce' | 'pressable'[]; + }; user: { role: 'a4a_administrator' | 'a4a_manager'; capabilities: string[];