Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/change get organizations by email endpoint #181

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading