forked from SOS-RS/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: melhoria na UI de lista de itens para evitar duplicação (SOS-RS…
…#275) ## Related Issue Closes SOS-RS#254 ## Overall Este PR tem como objetivo alterar a forma como é feita a busca de itens na tela de abrigo para evitar a duplicação de itens. As alterações propostas incluem: - Remove o botão de cadastrar novo item no topo da página - Adiciona autocomplete para busca de itens - Adiciona opção de cadastrar novo item no autocomplete ## Screen recording https://github.com/SOS-RS/frontend/assets/8760873/74db3fa0-c45c-4b7a-afb2-d3d5279c0106
- Loading branch information
Showing
5 changed files
with
155 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
81 changes: 81 additions & 0 deletions
81
src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx
This file contains 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,81 @@ | ||
import { Input } from '@/components/ui/input'; | ||
import { IUseSuppliesData } from '@/hooks/useSupplies/types'; | ||
import { Search, PlusCircle, X } from 'lucide-react'; | ||
import { useState } from 'react'; | ||
import { Fragment } from 'react/jsx-runtime'; | ||
import {ISupplySearchProps} from './types'; | ||
|
||
export const SupplySearch = ({ | ||
supplyItems, | ||
limit = 10, | ||
onSearch, | ||
onSelectItem, | ||
onAddNewItem | ||
}: ISupplySearchProps) => { | ||
const [searchValue, setSearchValue] = useState<string>(''); | ||
const [selectedItem, setSelectedItem] = useState<IUseSuppliesData | null>(null); | ||
|
||
function onChangeInputHandler(event: React.ChangeEvent<HTMLInputElement>) { | ||
setSearchValue(event.target.value); | ||
onSearch(event.target.value); | ||
} | ||
|
||
function onSelectItemHandler(item: IUseSuppliesData) { | ||
setSearchValue(item.name); | ||
setSelectedItem(item); | ||
onSelectItem(item); | ||
} | ||
|
||
function onAddNewItemHandler() { | ||
setSelectedItem(null); | ||
onAddNewItem(); | ||
} | ||
|
||
function onClearClickHandler() { | ||
setSelectedItem(null); | ||
setSearchValue(''); | ||
onSearch(''); | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
<div | ||
className="flex items-center rounded-md border border-input px-3 h-10" | ||
cmdk-input-wrapper="" | ||
> | ||
<Search className="mr-2 h-4 w-4 shrink-0 opacity-50" /> | ||
<Input | ||
type="text" | ||
className="outline-none border-none focus-visible:ring-transparent h-8" | ||
placeholder="Buscar itens..." | ||
value={searchValue} | ||
onChange={onChangeInputHandler} | ||
/> | ||
<X className="h-4 w-4 ml-2 hover:cursor-pointer" onClick={onClearClickHandler} /> | ||
</div> | ||
|
||
{!!searchValue && !selectedItem ? ( | ||
<div className="flex-col items-center rounded-md border border-input p-3 bg-slate-50 mt-1"> | ||
{supplyItems.slice(0, limit).map((item) => ( | ||
<div | ||
key={item.id} | ||
className="h-10 flex items-center rounded-md p-2 hover:bg-slate-100 hover:cursor-pointer" | ||
onClick={() => onSelectItemHandler(item)} | ||
> | ||
<span className="text-sm">{item.name}</span> | ||
</div> | ||
))} | ||
<div | ||
className="h-10 flex items-center rounded-md p-2 hover:bg-slate-100 hover:cursor-pointer" | ||
onClick={onAddNewItemHandler} | ||
> | ||
<div className="flex gap-2 items-center"> | ||
<PlusCircle size={16} color="#0284c7" /> | ||
<span className="text-sm text-sky-600">Cadastrar novo item</span> | ||
</div> | ||
</div> | ||
</div> | ||
) : null} | ||
</Fragment> | ||
); | ||
}; |
This file contains 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,3 @@ | ||
import { SupplySearch } from './SupplySearch'; | ||
|
||
export { SupplySearch }; |
This file contains 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,9 @@ | ||
import { IUseSuppliesData } from "@/hooks/useSupplies/types"; | ||
|
||
export interface ISupplySearchProps { | ||
supplyItems: IUseSuppliesData[]; | ||
limit?: number; | ||
onSearch: (value: string) => void; | ||
onSelectItem: (item: IUseSuppliesData) => void; | ||
onAddNewItem: () => void; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { SupplyRow } from './SupplyRow'; | ||
import { SupplyRowInfo } from './SupplyRowInfo'; | ||
import { SupplySearch } from './SupplySearch'; | ||
|
||
export { SupplyRowInfo, SupplyRow }; | ||
export { SupplyRowInfo, SupplyRow, SupplySearch }; |