This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into feature/create-sid…
…ebar
- Loading branch information
Showing
73 changed files
with
1,637 additions
and
377 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
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
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,31 @@ | ||
'use client'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { IUserProtectedResponse } from '@teameights/types'; | ||
import { API } from '@/shared/api'; | ||
import { API_USERS } from '@/shared/constant'; | ||
|
||
interface IQueryParams { | ||
page?: number; | ||
limit?: number; | ||
filters?: string | null; | ||
sort?: string; | ||
} | ||
|
||
export const useGetUsers = ({ page, limit, filters, sort }: IQueryParams) => { | ||
const queryString = [ | ||
page && `page=${page}`, | ||
limit && `limit=${limit}`, | ||
filters && `filters=${filters}`, | ||
sort && `sort=${sort}`, | ||
].join(''); | ||
|
||
return useQuery({ | ||
queryKey: ['useGetUsers', queryString], | ||
queryFn: async () => { | ||
const { data } = await API.get<IUserProtectedResponse>(`${API_USERS}?${queryString}`); | ||
return data; | ||
}, | ||
refetchOnMount: false, | ||
refetchOnWindowFocus: false, | ||
}); | ||
}; |
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
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
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
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
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 @@ | ||
export { SearchContext } from './search-context'; |
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,4 @@ | ||
import { createContext } from 'react'; | ||
import { SearchContextType } from '../types'; | ||
|
||
export const SearchContext = createContext<SearchContextType | null>(null); |
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,2 @@ | ||
export { useTrackFilterArr } from './useTrackFiltersArr'; | ||
export { useFilters } from './useFilters'; |
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,12 @@ | ||
import { useContext } from 'react'; | ||
import { SearchContext } from '../contexts'; | ||
|
||
export const useFilters = () => { | ||
const context = useContext(SearchContext); | ||
|
||
if (!context) { | ||
throw new Error(); | ||
} | ||
|
||
return context; | ||
}; |
46 changes: 46 additions & 0 deletions
46
client/src/shared/ui/search-bar/hooks/useTrackFiltersArr.ts
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,46 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import { Filter, IFilterParams } from '../types'; | ||
|
||
export const useTrackFilterArr = ( | ||
filterArr: Filter[], | ||
onChange: (filterValues: string | null) => void | ||
) => { | ||
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null); | ||
useEffect(() => { | ||
if (timerRef.current) { | ||
clearTimeout(timerRef.current); | ||
} | ||
|
||
timerRef.current = setTimeout(() => { | ||
const filterValues: IFilterParams = filterArr.reduce<{ | ||
[key: string]: string | string[] | [number, number]; | ||
}>((acc, curr) => { | ||
switch (curr.type) { | ||
case 'text': | ||
if (curr.filterValue.length) { | ||
acc[curr.value] = curr.filterValue; | ||
} | ||
|
||
return acc; | ||
|
||
case 'multiple': | ||
case 'checkbox': | ||
if (curr.filterValue.length) { | ||
acc[curr.value] = curr.filterValue.map<string>(item => item.value); | ||
} | ||
|
||
return acc; | ||
|
||
case 'range': | ||
if (curr.filterValue?.length) { | ||
acc[curr.value] = curr.filterValue; | ||
} | ||
|
||
return acc; | ||
} | ||
}, {}); | ||
|
||
onChange(Object.keys(filterValues).length ? JSON.stringify(filterValues) : null); | ||
}, 1300); | ||
}, [filterArr, onChange]); | ||
}; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...arch/ui/search-bar/search-bar.module.scss → ...ared/ui/search-bar/search-bar.module.scss
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
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
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,83 @@ | ||
'use client'; | ||
|
||
import { FC, useState } from 'react'; | ||
import styles from './search-bar.module.scss'; | ||
import { Filter } from './types'; | ||
import { FilterSelect } from './ui/filter-select'; | ||
import { SearchInput } from './ui/search-input'; | ||
import { TagList } from './ui/tag-list'; | ||
import { Flex } from '@/shared/ui'; | ||
import { useTrackFilterArr } from './hooks'; | ||
import { SearchContext } from './contexts'; | ||
import { ModalButton } from './ui/modal-button'; | ||
import { Modal } from './ui/modal'; | ||
|
||
/** | ||
* Search-bar Component | ||
* | ||
* Used to search by query parameters. | ||
* | ||
* Props: | ||
* | ||
* @prop {Filter[]} [initialFiltersState] - Initial state as an array with filters. | ||
* @prop {(filterValues: string | null) => void} [onChange] - A callback that takes a string of query parameters as an argument. Must be used for requests to the server. | ||
* | ||
* Usage: | ||
* | ||
* ```tsx | ||
* import { SearchBar } from '@/widgets/search'; | ||
* | ||
* <SearchBar initialFiltersState={[{ | ||
* type: 'text', | ||
* label: 'Name', | ||
* value: 'name', | ||
* placeholder: 'Search by name', | ||
* filterValue: '', | ||
* }]} | ||
* onChange={string => console.log(string)} | ||
* /> | ||
* ``` | ||
*/ | ||
|
||
interface SearchBarProps { | ||
initialFiltersState: Filter[]; | ||
onChange: (filterValues: string | null) => void; | ||
} | ||
|
||
export const SearchBar: FC<SearchBarProps> = ({ initialFiltersState, onChange }) => { | ||
const [filterArr, setFilterArr] = useState(initialFiltersState); | ||
const [filterIndex, setFilterIndex] = useState(0); | ||
const [isModalOpened, setIsModalOpened] = useState(false); | ||
useTrackFilterArr(filterArr, onChange); | ||
|
||
const onOpen = () => { | ||
setIsModalOpened(true); | ||
}; | ||
|
||
const onClose = () => { | ||
setIsModalOpened(false); | ||
}; | ||
|
||
return ( | ||
<SearchContext.Provider | ||
value={{ | ||
filterArr, | ||
setFilterArr, | ||
filterIndex, | ||
setFilterIndex, | ||
}} | ||
> | ||
<ModalButton onOpen={onOpen} onClose={onClose} /> | ||
|
||
<Flex direction='column' gap='24px' className={styles.searchbar}> | ||
<Flex className={styles.searchbar_content}> | ||
<FilterSelect /> | ||
<SearchInput /> | ||
</Flex> | ||
<TagList /> | ||
</Flex> | ||
|
||
<Modal isOpened={isModalOpened} onClose={onClose} /> | ||
</SearchContext.Provider> | ||
); | ||
}; |
File renamed without changes.
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
13 changes: 13 additions & 0 deletions
13
client/src/shared/ui/search-bar/ui/filter-menu/filter-menu.module.scss
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,13 @@ | ||
.searchinput_wrapper { | ||
width: 100%; | ||
min-height: 40px; | ||
border: 1px solid var(--green-normal-color); | ||
border-radius: 10px; | ||
overflow: hidden; | ||
} | ||
|
||
.menu_wrapper { | ||
height: 100%; | ||
margin-bottom: 10px; | ||
overflow: hidden; | ||
} |
19 changes: 19 additions & 0 deletions
19
client/src/shared/ui/search-bar/ui/filter-menu/filter-menu.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,19 @@ | ||
import { Flex } from '@/shared/ui'; | ||
import { SearchInput } from '../search-input'; | ||
import { TagList } from '../tag-list'; | ||
import styles from './filter-menu.module.scss'; | ||
import { useState } from 'react'; | ||
|
||
export const FilterMenu = () => { | ||
const [menuWrapper, setMenuWrapper] = useState<HTMLDivElement | null>(null); | ||
|
||
return ( | ||
<Flex direction='column' gap='16px' height='100%'> | ||
<Flex className={styles.searchinput_wrapper}> | ||
<SearchInput menuWrapper={menuWrapper} /> | ||
</Flex> | ||
<TagList isOnlyCurrentFilterTags /> | ||
<div className={styles.menu_wrapper} ref={setMenuWrapper}></div> | ||
</Flex> | ||
); | ||
}; |
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 @@ | ||
export { FilterMenu } from './filter-menu'; |
File renamed without changes.
Oops, something went wrong.