Skip to content

Commit

Permalink
Merge pull request #181 from Josmar-jr/fix/change-get-organizations-b…
Browse files Browse the repository at this point in the history
…y-email-endpoint

Fix/change get organizations by email endpoint
  • Loading branch information
ataideverton authored Dec 9, 2024
2 parents 78991e3 + 7f2adc7 commit dbc8086
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 16 additions & 12 deletions react/components/UserWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ const UserWidget: VtexFunctionComponent<UserWidgetProps> = ({
...organizationsState,
organizationInput: text,
organizationOptions:
userWidgetData?.getOrganizationsByEmail
userWidgetData?.getActiveOrganizationsByEmail
?.filter((organization: any) => {
return organization?.organizationName
?.toLowerCase()
Expand Down Expand Up @@ -322,14 +322,16 @@ const UserWidget: VtexFunctionComponent<UserWidgetProps> = ({
}

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
)
Expand All @@ -348,16 +350,16 @@ const UserWidget: VtexFunctionComponent<UserWidgetProps> = ({
...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
Expand All @@ -368,10 +370,10 @@ const UserWidget: VtexFunctionComponent<UserWidgetProps> = ({
})),
currentOrganization,
currentCostCenter,
dataList: userWidgetData?.getOrganizationsByEmail?.sort(
dataList: userWidgetData?.getActiveOrganizationsByEmail?.sort(
sortOrganizations
),
totalDataList: userWidgetData?.getOrganizationsByEmail?.length,
totalDataList: userWidgetData?.getActiveOrganizationsByEmail?.length,
currentOrganizationStatus:
userWidgetData?.getOrganizationByIdStorefront?.status,
})
Expand Down Expand Up @@ -413,7 +415,7 @@ const UserWidget: VtexFunctionComponent<UserWidgetProps> = ({
...organizationsState,
costCenterInput: '',
currentOrganization: itemSelected.value,
costCenterOptions: userWidgetData?.getOrganizationsByEmail
costCenterOptions: userWidgetData?.getActiveOrganizationsByEmail
.filter(
(organization: { orgId: string }) =>
organization.orgId === itemSelected.value
Expand Down Expand Up @@ -465,11 +467,13 @@ const UserWidget: VtexFunctionComponent<UserWidgetProps> = ({

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
Expand Down Expand Up @@ -615,7 +619,7 @@ const UserWidget: VtexFunctionComponent<UserWidgetProps> = ({
}`}
</div>
<div className="ml-auto">
{userWidgetData?.getOrganizationsByEmail?.length > 1 && (
{userWidgetData?.getActiveOrganizationsByEmail?.length > 1 && (
<Button variant="primary" onClick={() => setShowModal(true)}>
{formatMessage(messages.changeOrganization)}
</Button>
Expand Down
3 changes: 2 additions & 1 deletion react/graphql/userWidgetQuery.graphql
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit dbc8086

Please sign in to comment.