From 8583a16f6882f9dfa7ea163408fb0746fc08a10c Mon Sep 17 00:00:00 2001 From: Josmar Soares Trigueiro Junior Date: Wed, 30 Oct 2024 14:42:09 -0300 Subject: [PATCH 1/2] fix: update the get organization by email endpoint to get active organization by email --- react/components/UserWidget.tsx | 28 +++++++++++++++------------ react/graphql/userWidgetQuery.graphql | 3 ++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/react/components/UserWidget.tsx b/react/components/UserWidget.tsx index 19ef2412..9ab2f28f 100644 --- a/react/components/UserWidget.tsx +++ b/react/components/UserWidget.tsx @@ -284,7 +284,7 @@ const UserWidget: VtexFunctionComponent = ({ ...organizationsState, organizationInput: text, organizationOptions: - userWidgetData?.getOrganizationsByEmail + userWidgetData?.getActiveOrganizationsByEmail ?.filter((organization: any) => { return organization?.organizationName ?.toLowerCase() @@ -322,14 +322,16 @@ const UserWidget: VtexFunctionComponent = ({ } useEffect(() => { - if (!userWidgetData?.getOrganizationsByEmail) { + if (!userWidgetData?.getActiveOrganizationsByEmail) { return } const uiSettings = userWidgetData?.getB2BSettings?.uiSettings if (uiSettings?.showModal) { - const totalCompanies = userWidgetData?.getOrganizationsByEmail?.length + const totalCompanies = + userWidgetData?.getActiveOrganizationsByEmail?.length + const storageShowModal = sessionStorage.getItem( SESSION_STORAGE_SHOW_MODAL ) @@ -348,16 +350,16 @@ const UserWidget: VtexFunctionComponent = ({ ...organizationsState, costCenterInput: userWidgetData?.getCostCenterByIdStorefront?.name, organizationInput: userWidgetData?.getOrganizationByIdStorefront?.name, - organizationOptions: userWidgetData?.getOrganizationsByEmail + organizationOptions: userWidgetData?.getActiveOrganizationsByEmail .slice(0, 15) .map((organization: { orgId: string; organizationName: string }) => ({ value: organization.orgId, label: organization.organizationName, })), - currentRoleName: userWidgetData?.getOrganizationsByEmail?.find( + currentRoleName: userWidgetData?.getActiveOrganizationsByEmail?.find( (organizations: any) => organizations.costId === currentCostCenter )?.role?.name, - costCenterOptions: userWidgetData?.getOrganizationsByEmail + costCenterOptions: userWidgetData?.getActiveOrganizationsByEmail .filter( (organization: { orgId: string }) => organization.orgId === currentOrganization @@ -368,10 +370,10 @@ const UserWidget: VtexFunctionComponent = ({ })), currentOrganization, currentCostCenter, - dataList: userWidgetData?.getOrganizationsByEmail?.sort( + dataList: userWidgetData?.getActiveOrganizationsByEmail?.sort( sortOrganizations ), - totalDataList: userWidgetData?.getOrganizationsByEmail?.length, + totalDataList: userWidgetData?.getActiveOrganizationsByEmail?.length, currentOrganizationStatus: userWidgetData?.getOrganizationByIdStorefront?.status, }) @@ -413,7 +415,7 @@ const UserWidget: VtexFunctionComponent = ({ ...organizationsState, costCenterInput: '', currentOrganization: itemSelected.value, - costCenterOptions: userWidgetData?.getOrganizationsByEmail + costCenterOptions: userWidgetData?.getActiveOrganizationsByEmail .filter( (organization: { orgId: string }) => organization.orgId === itemSelected.value @@ -465,11 +467,13 @@ const UserWidget: VtexFunctionComponent = ({ setSearchTerm(e.target.value) - dataList = userWidgetData?.getOrganizationsByEmail?.sort(sortOrganizations) + dataList = userWidgetData?.getActiveOrganizationsByEmail?.sort( + sortOrganizations + ) if (value.trim() !== '') { dataList = - userWidgetData?.getOrganizationsByEmail + userWidgetData?.getActiveOrganizationsByEmail ?.filter((organization: any) => { return ( organization.organizationName @@ -615,7 +619,7 @@ const UserWidget: VtexFunctionComponent = ({ }`}
- {userWidgetData?.getOrganizationsByEmail?.length > 1 && ( + {userWidgetData?.getActiveOrganizationsByEmail?.length > 1 && ( diff --git a/react/graphql/userWidgetQuery.graphql b/react/graphql/userWidgetQuery.graphql index b815a6ec..4e82b437 100644 --- a/react/graphql/userWidgetQuery.graphql +++ b/react/graphql/userWidgetQuery.graphql @@ -1,5 +1,6 @@ query userWidgetQuery($orgId: ID) { - getOrganizationsByEmail @context(provider: "vtex.b2b-organizations-graphql") { + getActiveOrganizationsByEmail + @context(provider: "vtex.b2b-organizations-graphql") { id costCenterName costId From 7f2adc727cc47e03a2199954510aa15dc8c4e631 Mon Sep 17 00:00:00 2001 From: Josmar Soares Trigueiro Junior Date: Wed, 30 Oct 2024 14:49:49 -0300 Subject: [PATCH 2/2] doc: updated changelog file with new change --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 619d5898..ba52fc0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed + +- Change `getOrganizationsByEmail` to `getActiveOrganizationsByEmail` to only allow listings from active organizations ## [1.38.0] - 2024-12-09 ### Added