-
Notifications
You must be signed in to change notification settings - Fork 75
feat: order list placed by filter-SFS-2702 #2988
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
496fa26
feat: add placed by filter to my account order list slider
artursantiago 345efe8
feat: add placed by tag
artursantiago c73684f
feat: add TODO comments
artursantiago 51f9af8
feat: add hook useShopperSuggestions
artursantiago 96a9b27
feat: place placedByTag first
artursantiago ebcec13
refactor: use data-attr in MyAccountSelectedTags
artursantiago 53940af
fix: add aria-label to shopper dropdown
artursantiago d20b034
feat: remove useImperativeHandle
artursantiago File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
172 changes: 172 additions & 0 deletions
172
...rders/MyAccountFilterSlider/MyAccountFilterFacetPlacedBy/MyAccountFilterFacetPlacedBy.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| import { useEffect, useMemo, useRef, useState } from 'react' | ||
| import { Input, IconButton, Icon, Loader } from '@faststore/ui' | ||
| import type { SelectedFacet } from 'src/sdk/search/useMyAccountFilter' | ||
| import useShopperSuggestions from 'src/sdk/account/useShopperSuggestions' | ||
| import type { Shopper } from 'src/sdk/account/useShopperSuggestions' | ||
|
|
||
| export interface MyAccountFilterFacetPlacedByProps { | ||
| /** | ||
| * Current selected facets from filter context | ||
| */ | ||
| selected: SelectedFacet[] | ||
| /** | ||
| * Dispatch from filter context | ||
| */ | ||
| dispatch: (action: { type: 'toggleFacet' | 'setFacet'; payload: any }) => void | ||
| } | ||
|
|
||
| function MyAccountFilterFacetPlacedBy({ | ||
| selected, | ||
| dispatch, | ||
| }: MyAccountFilterFacetPlacedByProps) { | ||
| const inputRef = useRef<HTMLInputElement>(null) | ||
| const [query, setQuery] = useState('') | ||
| const [selectedShopper, setSelectedShopper] = useState<Shopper | null>(null) | ||
| const [isOpen, setIsOpen] = useState(false) | ||
|
|
||
| // Use the new hook for shoppers suggestions | ||
| const { data, isLoading, findShopperById } = useShopperSuggestions(query) | ||
|
|
||
| // Get the filtered shoppers from hook data | ||
| const filteredShoppers = data?.shoppers || [] | ||
|
|
||
| const selectedId = useMemo( | ||
| () => selected.find((f) => f.key === 'purchaseAgentId')?.value, | ||
| [selected] | ||
| ) | ||
|
Comment on lines
+33
to
+36
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just 1 so far, after we can select multiple.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, i have done as in the figma for now |
||
|
|
||
| const clearAll = () => { | ||
| setQuery('') | ||
| setSelectedShopper(null) | ||
| if (inputRef.current) inputRef.current.value = '' | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| if (selectedId && !selectedShopper) { | ||
| const found = findShopperById(selectedId) | ||
| if (found) setSelectedShopper(found) | ||
| } else if (!selectedId) { | ||
| clearAll() | ||
| } | ||
| }, [selectedId, selectedShopper]) | ||
|
|
||
| function handleSearchOnChange(value: string) { | ||
| setQuery(value) | ||
| setIsOpen(true) | ||
| } | ||
|
|
||
| const isSearchEmpty = useMemo( | ||
| () => !isLoading && query && filteredShoppers.length === 0, | ||
| [isLoading, query, filteredShoppers] | ||
| ) | ||
|
|
||
| function handleSelect(shopper: Shopper) { | ||
| setSelectedShopper(shopper) | ||
| setIsOpen(false) | ||
| dispatch({ | ||
| type: 'setFacet', | ||
| payload: { | ||
| facet: { key: 'purchaseAgentId', value: shopper.purchase_agent_id }, | ||
| unique: true, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| function handleClearTag() { | ||
| if (selectedShopper) { | ||
| // Using toggleFacet here removes the purchaseAgentId from selected facets | ||
| // because toggleFacet will remove the facet if it already exists in the selected facets | ||
| dispatch({ | ||
| type: 'toggleFacet', | ||
| payload: { | ||
| key: 'purchaseAgentId', | ||
| value: selectedShopper.purchase_agent_id, | ||
| }, | ||
| }) | ||
| } | ||
| clearAll() | ||
| } | ||
|
|
||
| return ( | ||
| <div data-fs-list-orders-filters-placed-by> | ||
| <div data-fs-list-orders-filters-placed-by-input> | ||
| <Input | ||
| id="placed-by-input" | ||
| placeholder="Enter the shopper's name..." | ||
| ref={inputRef} | ||
| value={selectedShopper ? selectedShopper.name : query} | ||
| readOnly={Boolean(selectedShopper)} | ||
| onFocus={() => { | ||
| if (!selectedShopper) setIsOpen(true) | ||
| }} | ||
| onChange={(e) => { | ||
| if (selectedShopper) return | ||
| handleSearchOnChange(e.target.value) | ||
| }} | ||
| onBlur={() => { | ||
| // delay close to allow click selection | ||
| setTimeout(() => { | ||
| setIsOpen(false) | ||
| if (!selectedShopper) { | ||
| setQuery('') | ||
| if (inputRef.current) inputRef.current.value = '' | ||
| } | ||
| }, 100) | ||
| }} | ||
| type="text" | ||
| inputMode="text" | ||
| /> | ||
| {isLoading && ( | ||
| <div data-fs-list-orders-filters-placed-by-loader> | ||
| <Loader /> | ||
| </div> | ||
| )} | ||
| {selectedShopper && ( | ||
| <IconButton | ||
| size="small" | ||
| aria-label="Clear shopper" | ||
| data-fs-list-orders-filters-placed-by-clear | ||
| icon={<Icon name="X" />} | ||
| onClick={handleClearTag} | ||
| /> | ||
| )} | ||
| </div> | ||
|
|
||
| {isOpen && isSearchEmpty && ( | ||
| <div | ||
| data-fs-list-orders-filters-placed-by-dropdown | ||
| data-fs-list-orders-filters-placed-by-empty | ||
| aria-label="No shoppers found with query" | ||
| > | ||
| <p>No shoppers found with "{query}"</p> | ||
| </div> | ||
| )} | ||
|
|
||
| {isOpen && filteredShoppers.length > 0 && ( | ||
| <div | ||
| data-fs-list-orders-filters-placed-by-dropdown | ||
| aria-label="Shopper selection dropdown" | ||
| > | ||
| <ul> | ||
| {filteredShoppers.map((s) => ( | ||
| <li key={s.purchase_agent_id}> | ||
| <button | ||
| type="button" | ||
| onMouseDown={(e) => e.preventDefault()} | ||
| onClick={() => handleSelect(s)} | ||
| data-fs-list-orders-filters-placed-by-option | ||
| > | ||
| <span data-fs-list-orders-filters-placed-by-option-name> | ||
| {s.name} | ||
| </span> | ||
| </button> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default MyAccountFilterFacetPlacedBy | ||
2 changes: 2 additions & 0 deletions
2
...nt/orders/MyAccountListOrders/MyAccountFilterSlider/MyAccountFilterFacetPlacedBy/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { default } from './MyAccountFilterFacetPlacedBy' | ||
| export type { MyAccountFilterFacetPlacedByProps } from './MyAccountFilterFacetPlacedBy' |
96 changes: 96 additions & 0 deletions
96
...orders/MyAccountListOrders/MyAccountFilterSlider/MyAccountFilterFacetPlacedBy/styles.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| [data-fs-list-orders-filters-placed-by] { | ||
| --fs-list-orders-filters-placed-by-dropdown-bkg : var(--fs-color-neutral-0); | ||
| --fs-list-orders-filters-placed-by-dropdown-border : 1px solid var(--fs-border-color-light); | ||
| --fs-list-orders-filters-placed-by-dropdown-radius : var(--fs-border-radius); | ||
| --fs-list-orders-filters-placed-by-option-padding : var(--fs-spacing-2) var(--fs-spacing-3); | ||
| --fs-list-orders-filters-placed-by-selected-height : var(--fs-control-height); | ||
| --fs-list-orders-filters-placed-by-selected-padding : 0 var(--fs-spacing-3); | ||
| --fs-list-orders-filters-placed-by-selected-border : var(--fs-input-border-width) solid var(--fs-input-border-color); | ||
| --fs-list-orders-filters-placed-by-selected-radius : var(--fs-input-border-radius); | ||
| --fs-list-orders-filters-placed-by-empty-text-color : var(--fs-color-text-light); | ||
| --fs-list-orders-filters-placed-by-loader-size : 1.25rem; | ||
| --fs-list-orders-filters-placed-by-dropdown-shadow : 0 2px 8px rgb(0 0 0 / 10%); | ||
|
|
||
| position: relative; | ||
|
|
||
| // Clear icon inside input when actionable | ||
| [data-fs-list-orders-filters-placed-by-input] { | ||
| position: relative; | ||
|
|
||
| [data-fs-input] { | ||
| width: 100%; | ||
| } | ||
|
|
||
| [data-fs-icon-button] { | ||
| position: absolute; | ||
| top: 50%; | ||
| right: var(--fs-spacing-2); | ||
| transform: translateY(-50%); | ||
| } | ||
|
|
||
| [data-fs-list-orders-filters-placed-by-loader] { | ||
| position: absolute; | ||
| top: 50%; | ||
| right: var(--fs-spacing-2); | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| transform: translateY(-50%); | ||
|
|
||
| [data-fs-loader] { | ||
| width: var(--fs-list-orders-filters-placed-by-loader-size); | ||
| height: var(--fs-list-orders-filters-placed-by-loader-size); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [data-fs-list-orders-filters-placed-by-dropdown] { | ||
| position: absolute; | ||
| z-index: 10; | ||
| width: 100%; | ||
| margin-top: var(--fs-spacing-1); | ||
| background: var(--fs-list-orders-filters-placed-by-dropdown-bkg); | ||
| border: var(--fs-list-orders-filters-placed-by-dropdown-border); | ||
| border-radius: var(--fs-list-orders-filters-placed-by-dropdown-radius); | ||
| box-shadow: var(--fs-list-orders-filters-placed-by-dropdown-shadow); | ||
|
|
||
| &[data-fs-list-orders-filters-placed-by-empty] { | ||
| padding: var(--fs-spacing-3); | ||
|
|
||
| p { | ||
| margin: 0; | ||
| font-size: var(--fs-text-size-body); | ||
| font-style: italic; | ||
| color: var(--fs-list-orders-filters-placed-by-empty-text-color); | ||
| text-align: center; | ||
| } | ||
| } | ||
|
|
||
| ul { | ||
artursantiago marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| max-height: 220px; | ||
| padding: 0; | ||
| margin: 0; | ||
| overflow: auto; | ||
| list-style: none; | ||
| } | ||
|
|
||
| [data-fs-list-orders-filters-placed-by-option] { | ||
| display: flex; | ||
| justify-content: flex-start; | ||
| width: 100%; | ||
| padding: var(--fs-list-orders-filters-placed-by-option-padding); | ||
| text-align: left; | ||
| cursor: pointer; | ||
| background: transparent; | ||
| border: 0; | ||
|
|
||
| &:hover, &:focus { | ||
| background: var(--fs-color-neutral-bkg); | ||
| } | ||
|
|
||
| [data-fs-list-orders-filters-placed-by-option-name] { | ||
| font-weight: var(--fs-text-weight-regular); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.