mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 20:01:59 +00:00
Format code style
This commit is contained in:
@@ -18,18 +18,22 @@ const useRooms = () => {
|
||||
|
||||
const sortByValue = searchParams.get('sortBy') || 'id';
|
||||
const orderByValue = searchParams.get('orderBy') || 'asc';
|
||||
const roomSearch = searchParams.get('search') || '';
|
||||
const page = searchParams.get('page')
|
||||
? Number(searchParams.get('page'))
|
||||
: 1;
|
||||
const searchValue = searchParams.get('search') || '';
|
||||
const page = searchParams.get('page') ? Number(searchParams.get('page')) : 1;
|
||||
|
||||
const {
|
||||
isLoading,
|
||||
data: { data: rooms, count } = {},
|
||||
error,
|
||||
} = useQuery({
|
||||
queryKey: ['rooms', sortByValue, orderByValue, roomSearch, page],
|
||||
queryFn: () => getAllRooms(sortByValue, orderByValue, roomSearch, page),
|
||||
queryKey: ['rooms', sortByValue, orderByValue, searchValue, page],
|
||||
queryFn: () =>
|
||||
getAllRooms({
|
||||
sortBy: sortByValue,
|
||||
orderBy: orderByValue,
|
||||
roomName: searchValue,
|
||||
page,
|
||||
}),
|
||||
});
|
||||
|
||||
if (error) {
|
||||
@@ -43,9 +47,14 @@ const useRooms = () => {
|
||||
const nextPage = page + 1;
|
||||
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: ['rooms', sortByValue, orderByValue, roomSearch, nextPage],
|
||||
queryKey: ['rooms', sortByValue, orderByValue, searchValue, nextPage],
|
||||
queryFn: () =>
|
||||
getAllRooms(sortByValue, orderByValue, roomSearch, nextPage),
|
||||
getAllRooms({
|
||||
sortBy: sortByValue,
|
||||
orderBy: orderByValue,
|
||||
roomName: searchValue,
|
||||
page: nextPage,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -53,9 +62,14 @@ const useRooms = () => {
|
||||
const previousPage = page - 1;
|
||||
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: ['rooms', sortByValue, orderByValue, roomSearch, previousPage],
|
||||
queryKey: ['rooms', sortByValue, orderByValue, searchValue, previousPage],
|
||||
queryFn: () =>
|
||||
getAllRooms(sortByValue, orderByValue, roomSearch, previousPage),
|
||||
getAllRooms({
|
||||
sortBy: sortByValue,
|
||||
orderBy: orderByValue,
|
||||
roomName: searchValue,
|
||||
page: previousPage,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,18 +17,22 @@ const useUsers = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const sortByValue = searchParams.get('sortBy') || 'id';
|
||||
const orderByValue = searchParams.get('orderBy') || 'asc';
|
||||
const phoneSearch = searchParams.get('search') || '';
|
||||
const page = searchParams.get('page')
|
||||
? Number(searchParams.get('page'))
|
||||
: 1;
|
||||
const searchValue = searchParams.get('search') || '';
|
||||
const page = searchParams.get('page') ? Number(searchParams.get('page')) : 1;
|
||||
|
||||
const {
|
||||
isLoading,
|
||||
data: { data: users, count } = {},
|
||||
error,
|
||||
} = useQuery({
|
||||
queryKey: ['users', sortByValue, orderByValue, phoneSearch, page],
|
||||
queryFn: () => getAllUsers(sortByValue, orderByValue, phoneSearch, page),
|
||||
queryKey: ['users', sortByValue, orderByValue, searchValue, page],
|
||||
queryFn: () =>
|
||||
getAllUsers({
|
||||
sortBy: sortByValue,
|
||||
orderBy: orderByValue,
|
||||
phoneSearch: searchValue,
|
||||
page,
|
||||
}),
|
||||
});
|
||||
|
||||
if (error) {
|
||||
@@ -42,9 +46,14 @@ const useUsers = () => {
|
||||
const nextPage = page + 1;
|
||||
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: ['users', sortByValue, orderByValue, phoneSearch, nextPage],
|
||||
queryKey: ['users', sortByValue, orderByValue, searchValue, nextPage],
|
||||
queryFn: () =>
|
||||
getAllUsers(sortByValue, orderByValue, phoneSearch, nextPage),
|
||||
getAllUsers({
|
||||
sortBy: sortByValue,
|
||||
orderBy: orderByValue,
|
||||
phoneSearch: searchValue,
|
||||
page: nextPage,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -52,9 +61,14 @@ const useUsers = () => {
|
||||
const previousPage = page - 1;
|
||||
|
||||
queryClient.prefetchQuery({
|
||||
queryKey: ['users', sortByValue, orderByValue, phoneSearch, previousPage],
|
||||
queryKey: ['users', sortByValue, orderByValue, searchValue, previousPage],
|
||||
queryFn: () =>
|
||||
getAllUsers(sortByValue, orderByValue, phoneSearch, previousPage),
|
||||
getAllUsers({
|
||||
sortBy: sortByValue,
|
||||
orderBy: orderByValue,
|
||||
phoneSearch: searchValue,
|
||||
page: previousPage,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -14,16 +14,23 @@ const ERROR_UPDATE_ROOM = "Can't update room!";
|
||||
const ERROR_CREATE_ROOM = "Can't create room!";
|
||||
const ERROR_DELETE_ROOM = "Can't delete room!";
|
||||
|
||||
interface IGetAllRooms {
|
||||
sortBy: string;
|
||||
orderBy: string;
|
||||
roomName: string;
|
||||
page: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all rooms from database
|
||||
* @returns Return all rooms in database
|
||||
*/
|
||||
const getAllRooms = async (
|
||||
sortBy: string,
|
||||
orderBy: string,
|
||||
roomName: string,
|
||||
page: number
|
||||
): Promise<{ data: IRoom[]; count: number | null }> => {
|
||||
const getAllRooms = async ({
|
||||
sortBy,
|
||||
orderBy,
|
||||
roomName,
|
||||
page,
|
||||
}: IGetAllRooms): Promise<{ data: IRoom[]; count: number | null }> => {
|
||||
const from = (page - 1) * DEFAULT_PAGE_SIZE;
|
||||
const to = from + DEFAULT_PAGE_SIZE - 1;
|
||||
|
||||
|
||||
@@ -52,6 +52,13 @@ const updateUser = async (user: IUser): Promise<IUser> => {
|
||||
return data;
|
||||
};
|
||||
|
||||
interface IGetAllUsers {
|
||||
sortBy: string;
|
||||
orderBy: string;
|
||||
phoneSearch: string;
|
||||
page: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return data of users from database
|
||||
* @param sortBy Sort by column
|
||||
@@ -59,12 +66,12 @@ const updateUser = async (user: IUser): Promise<IUser> => {
|
||||
* @param phoneSearch The phone need to be search
|
||||
* @returns The data of users from database
|
||||
*/
|
||||
const getAllUsers = async (
|
||||
sortBy: string,
|
||||
orderBy: string,
|
||||
phoneSearch: string,
|
||||
page: number
|
||||
): Promise<{ data: IUser[]; count: number | null }> => {
|
||||
const getAllUsers = async ({
|
||||
sortBy,
|
||||
orderBy,
|
||||
phoneSearch,
|
||||
page,
|
||||
}: IGetAllUsers): Promise<{ data: IUser[]; count: number | null }> => {
|
||||
const from = (page - 1) * DEFAULT_PAGE_SIZE;
|
||||
const to = from + DEFAULT_PAGE_SIZE - 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user