diff --git a/src/components/app/data/queries/utils.js b/src/components/app/data/queries/utils.js index 246685e0a..bacfb0d97 100644 --- a/src/components/app/data/queries/utils.js +++ b/src/components/app/data/queries/utils.js @@ -1,6 +1,5 @@ import { matchPath } from 'react-router-dom'; import { queryEnterpriseLearnerDashboardBFF } from './queries'; -import { isBFFEnabled } from '../utils'; /** * Resolves the appropriate BFF query function to use for the current route. @@ -12,9 +11,9 @@ export function resolveBFFQuery(pathname, options = {}) { const { enterpriseCustomerUuid, enterpriseFeatures } = options; // Exit early if BFF is not enabled for the enterprise customer and/or request user - if (!isBFFEnabled(enterpriseCustomerUuid, enterpriseFeatures)) { - return null; - } + // if (!isBFFEnabled(enterpriseCustomerUuid, enterpriseFeatures)) { + // return null; + // } // Define route patterns and their corresponding query functions const routeToBFFQueryMap = [ diff --git a/src/components/app/data/services/enterpriseCustomerUser.js b/src/components/app/data/services/enterpriseCustomerUser.js index 3c629fe54..124a9e753 100644 --- a/src/components/app/data/services/enterpriseCustomerUser.js +++ b/src/components/app/data/services/enterpriseCustomerUser.js @@ -71,7 +71,6 @@ export async function fetchEnterpriseLearnerData(username, enterpriseSlug, optio response: enterpriseCustomerUsersResponse, } = await fetchPaginatedData(url); const { enterpriseFeatures } = enterpriseCustomerUsersResponse; - // Transform enterprise customer user results const transformedEnterpriseCustomersUsers = enterpriseCustomersUsers.map( enterpriseCustomerUser => ({ @@ -113,6 +112,9 @@ export async function fetchEnterpriseLearnerData(username, enterpriseSlug, optio foundEnterpriseCustomerUserForCurrentSlug, staffEnterpriseCustomer, }); + + // shouldUpdateActiveEnterpriseCustomer should always be null since its generated primarily from the BFF + // layer to act as a flag on whether to update the active enterprise customer return { enterpriseCustomer, enterpriseCustomerUserRoleAssignments: roleAssignments, @@ -121,6 +123,7 @@ export async function fetchEnterpriseLearnerData(username, enterpriseSlug, optio allLinkedEnterpriseCustomerUsers: transformedEnterpriseCustomersUsers, enterpriseFeatures, staffEnterpriseCustomer, + shouldUpdateActiveEnterpriseCustomer: null, }; } catch (error) { logError(error); @@ -132,6 +135,7 @@ export async function fetchEnterpriseLearnerData(username, enterpriseSlug, optio allLinkedEnterpriseCustomerUsers: [], enterpriseFeatures: {}, staffEnterpriseCustomer: null, + shouldUpdateActiveEnterpriseCustomer: null, }; } } diff --git a/src/components/app/data/utils.js b/src/components/app/data/utils.js index 68ddb7f8a..7fe155eb0 100644 --- a/src/components/app/data/utils.js +++ b/src/components/app/data/utils.js @@ -940,6 +940,7 @@ export function isBFFEnabled(enterpriseCustomerUuid, enterpriseFeatures) { // Check the following conditions: // 1. BFF is enabled for the enterprise customer. // 2. BFF is enabled for the request user via Waffle flag (supporting percentage-based rollout) + return true; const isBFFEnabledForCustomer = isBFFEnabledForEnterpriseCustomer(enterpriseCustomerUuid); if (isBFFEnabledForCustomer || enterpriseFeatures?.enterpriseLearnerBffEnabled) { return true; diff --git a/src/components/app/routes/loaders/rootLoader.ts b/src/components/app/routes/loaders/rootLoader.ts index cf792b6d0..863f4eb67 100644 --- a/src/components/app/routes/loaders/rootLoader.ts +++ b/src/components/app/routes/loaders/rootLoader.ts @@ -1,4 +1,4 @@ -import { queryEnterpriseLearner } from '../../data'; +import { queryEnterpriseLearner, resolveBFFQuery, updateUserActiveEnterprise } from '../../data'; import { ensureActiveEnterpriseCustomerUser, ensureAuthenticatedUser, @@ -23,33 +23,55 @@ const makeRootLoader: Types.MakeRouteLoaderFunctionWithQueryClient = function ma // Retrieve linked enterprise customers for the current user from query cache // or fetch from the server if not available. - const enterpriseLearnerData = await queryClient.ensureQueryData( - queryEnterpriseLearner(username, enterpriseSlug), + const matchedBFFQuery = resolveBFFQuery( + requestUrl.pathname, ); + let enterpriseLearnerData; + if (matchedBFFQuery) { + enterpriseLearnerData = await queryClient.ensureQueryData( + matchedBFFQuery({ enterpriseSlug }), + ); + } else { + enterpriseLearnerData = await queryClient.ensureQueryData( + // @ts-ignore + queryEnterpriseLearner(username, enterpriseSlug), + ); + } + let { enterpriseCustomer, activeEnterpriseCustomer, allLinkedEnterpriseCustomerUsers, } = enterpriseLearnerData; - const { staffEnterpriseCustomer, enterpriseFeatures } = enterpriseLearnerData; + const { staffEnterpriseCustomer, enterpriseFeatures, shouldUpdateActiveEnterpriseCustomer } = enterpriseLearnerData; // User has no active, linked enterprise customer and no staff-only customer metadata exists; return early. if (!enterpriseCustomer) { return null; } + let updateActiveEnterpriseCustomerUserResult: { + enterpriseCustomer: any; updatedLinkedEnterpriseCustomerUsers: any; + } | null = null; // Ensure the active enterprise customer user is updated, when applicable (e.g., the // current enterprise slug in the URL does not match the active enterprise customer's slug). - const updateActiveEnterpriseCustomerUserResult = await ensureActiveEnterpriseCustomerUser({ - enterpriseSlug, - activeEnterpriseCustomer, - staffEnterpriseCustomer, - allLinkedEnterpriseCustomerUsers, - requestUrl, - }); + // The logic to ensure active enterprise customer user is done in the BFF, but updating the + // active enterprise customer is still required + if (matchedBFFQuery && shouldUpdateActiveEnterpriseCustomer) { + await updateUserActiveEnterprise({ enterpriseCustomer }); + } else { + updateActiveEnterpriseCustomerUserResult = await ensureActiveEnterpriseCustomerUser({ + enterpriseSlug, + activeEnterpriseCustomer, + staffEnterpriseCustomer, + allLinkedEnterpriseCustomerUsers, + requestUrl, + }); + } + // If the active enterprise customer user was updated, override the previous active // enterprise customer user data with the new active enterprise customer user data - // for subsequent queries. + // for subsequent queries. This action is already completed in the BFF. if (updateActiveEnterpriseCustomerUserResult) { const { enterpriseCustomer: nextActiveEnterpriseCustomer, diff --git a/src/types.d.ts b/src/types.d.ts index 9c0c4f9e7..40e791316 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -55,6 +55,7 @@ export interface EnterpriseLearnerData { allLinkedEnterpriseCustomerUsers: any[]; staffEnterpriseCustomer: Types.EnterpriseCustomer; enterpriseFeatures: Types.EnterpriseFeatures; + shouldUpdateActiveEnterpriseCustomer: boolean; } interface EnrollmentDueDate {