Skip to content

Commit

Permalink
Update Partner Directory permission check
Browse files Browse the repository at this point in the history
  • Loading branch information
yashwin committed Oct 24, 2024
1 parent df4754b commit a214829
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
? [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import page from '@automattic/calypso-router';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import { ReactNode, useMemo } from 'react';
Expand All @@ -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 {
Expand Down Expand Up @@ -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 ];

Expand Down
2 changes: 1 addition & 1 deletion client/state/a8c-for-agencies/agency/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
}
Expand Down
5 changes: 4 additions & 1 deletion client/state/a8c-for-agencies/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down

0 comments on commit a214829

Please sign in to comment.