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/search list many orgs modal #164

Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Adjust search list many organations at change organization modal

## [1.31.11] - 2024-07-05

## [1.31.10] - 2024-07-03
Expand Down
62 changes: 37 additions & 25 deletions react/components/UserWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,27 +321,6 @@ const UserWidget: VtexFunctionComponent<UserWidgetProps> = ({
value: organizationsState.costCenterInput,
}

useEffect(() => {
const dataList = userWidgetData?.getOrganizationsByEmail
?.filter((organization: any) => {
return (
organization.organizationName
.toLowerCase()
.includes(searchTerm.toLowerCase()) ||
organization.costCenterName
.toLowerCase()
.includes(searchTerm.toLowerCase())
)
})
.sort(sortOrganizations)

setOrganizationsState({
...organizationsState,
dataList,
totalDataList: dataList?.length,
})
}, [searchTerm])

useEffect(() => {
if (!userWidgetData?.getOrganizationsByEmail) {
return
Expand Down Expand Up @@ -480,6 +459,37 @@ const UserWidget: VtexFunctionComponent<UserWidgetProps> = ({
)
return null

const handleSearchOrganizations = (e: any) => {
const { value }: { value: string } = e.target
let dataList

setSearchTerm(e.target.value)

dataList = userWidgetData?.getOrganizationsByEmail?.sort(sortOrganizations)

if (value.trim() !== '') {
dataList =
userWidgetData?.getOrganizationsByEmail
?.filter((organization: any) => {
return (
organization.organizationName
.toLowerCase()
.includes(value.toLowerCase()) ||
organization.costCenterName
.toLowerCase()
.includes(value.toLowerCase())
)
})
?.slice(0, 15) ?? []
}

setOrganizationsState({
...organizationsState,
dataList,
totalDataList: dataList?.length,
})
}

return (
<div
className={`${handles.userWidgetContainer} w-100 flex flex-column mv3 bg-base--inverted`}
Expand All @@ -498,13 +508,15 @@ const UserWidget: VtexFunctionComponent<UserWidgetProps> = ({
</h1>
<div className={`${handles.userWidgetModalInput} flex`}>
<Input
onChange={(e: any) => setSearchTerm(e.target.value)}
onChange={handleSearchOrganizations}
value={searchTerm}
placeholder={`${formatMessage(messages.search)}...`}
/>
<Button variation="primary">
{formatMessage(messages.search)}
</Button>
<div className="ml4">
<Button variation="primary">
{formatMessage(messages.search)}
</Button>
</div>
</div>
<div className={`${handles.userWidgetModalTotal} pt4 mb4`}>
{organizationsState?.totalDataList}{' '}
Expand Down
Loading