Fix bug and optimized code

This commit is contained in:
2023-10-30 20:50:32 +07:00
parent 23a79657b9
commit c775d6e581
3 changed files with 8 additions and 5 deletions
+3 -1
View File
@@ -1,3 +1,5 @@
const TIME_OUT_SEC = 1;
const DEFAULT_SORT_BY = 'id';
const DEFAULT_ORDER_BY = 'asc';
export { TIME_OUT_SEC };
export { TIME_OUT_SEC, DEFAULT_SORT_BY, DEFAULT_ORDER_BY };
+2 -2
View File
@@ -57,8 +57,8 @@ const getValueUser = (user: TUser | null = null, prop: string): string => {
const searchQuery = (phone: string, sort: string, order: string) => {
const phoneParams = phone ? 'phone_like=' + phone : '';
const sortParams = sort ? '_sort=' + sort : '_sort=id';
const orderParams = order ? '_order=' + order : '_order=asc';
const sortParams = sort ? '_sort=' + sort : '';
const orderParams = order ? '_order=' + order : '';
const finalParam = [phoneParams, sortParams, orderParams];
let query = '';
let isFirstParam = true;
+3 -2
View File
@@ -28,6 +28,7 @@ import Search from '../../components/Search';
import SortBy from '../../components/SortBy';
import OrderBy from '../../components/OrderBy';
import { useSearchParams } from 'react-router-dom';
import { DEFAULT_ORDER_BY, DEFAULT_SORT_BY } from '../../constants/config';
interface IUserRow {
user: TUser;
@@ -113,10 +114,10 @@ const UserTable = ({
const [users, setUsers] = useState<TUser[]>([]);
const sortByValue = searchParams.get('sortBy')
? searchParams.get('sortBy')!
: '';
: DEFAULT_SORT_BY;
const orderByValue = searchParams.get('orderBy')
? searchParams.get('orderBy')!
: '';
: DEFAULT_ORDER_BY;
const { data, isPending, errorMsg } = useFetch(
'users',