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 sortByValue = searchParams.get('sortBy') || 'id';
|
||||||
const orderByValue = searchParams.get('orderBy') || 'asc';
|
const orderByValue = searchParams.get('orderBy') || 'asc';
|
||||||
const roomSearch = searchParams.get('search') || '';
|
const searchValue = searchParams.get('search') || '';
|
||||||
const page = searchParams.get('page')
|
const page = searchParams.get('page') ? Number(searchParams.get('page')) : 1;
|
||||||
? Number(searchParams.get('page'))
|
|
||||||
: 1;
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isLoading,
|
isLoading,
|
||||||
data: { data: rooms, count } = {},
|
data: { data: rooms, count } = {},
|
||||||
error,
|
error,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ['rooms', sortByValue, orderByValue, roomSearch, page],
|
queryKey: ['rooms', sortByValue, orderByValue, searchValue, page],
|
||||||
queryFn: () => getAllRooms(sortByValue, orderByValue, roomSearch, page),
|
queryFn: () =>
|
||||||
|
getAllRooms({
|
||||||
|
sortBy: sortByValue,
|
||||||
|
orderBy: orderByValue,
|
||||||
|
roomName: searchValue,
|
||||||
|
page,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -43,9 +47,14 @@ const useRooms = () => {
|
|||||||
const nextPage = page + 1;
|
const nextPage = page + 1;
|
||||||
|
|
||||||
queryClient.prefetchQuery({
|
queryClient.prefetchQuery({
|
||||||
queryKey: ['rooms', sortByValue, orderByValue, roomSearch, nextPage],
|
queryKey: ['rooms', sortByValue, orderByValue, searchValue, nextPage],
|
||||||
queryFn: () =>
|
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;
|
const previousPage = page - 1;
|
||||||
|
|
||||||
queryClient.prefetchQuery({
|
queryClient.prefetchQuery({
|
||||||
queryKey: ['rooms', sortByValue, orderByValue, roomSearch, previousPage],
|
queryKey: ['rooms', sortByValue, orderByValue, searchValue, previousPage],
|
||||||
queryFn: () =>
|
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 queryClient = useQueryClient();
|
||||||
const sortByValue = searchParams.get('sortBy') || 'id';
|
const sortByValue = searchParams.get('sortBy') || 'id';
|
||||||
const orderByValue = searchParams.get('orderBy') || 'asc';
|
const orderByValue = searchParams.get('orderBy') || 'asc';
|
||||||
const phoneSearch = searchParams.get('search') || '';
|
const searchValue = searchParams.get('search') || '';
|
||||||
const page = searchParams.get('page')
|
const page = searchParams.get('page') ? Number(searchParams.get('page')) : 1;
|
||||||
? Number(searchParams.get('page'))
|
|
||||||
: 1;
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isLoading,
|
isLoading,
|
||||||
data: { data: users, count } = {},
|
data: { data: users, count } = {},
|
||||||
error,
|
error,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: ['users', sortByValue, orderByValue, phoneSearch, page],
|
queryKey: ['users', sortByValue, orderByValue, searchValue, page],
|
||||||
queryFn: () => getAllUsers(sortByValue, orderByValue, phoneSearch, page),
|
queryFn: () =>
|
||||||
|
getAllUsers({
|
||||||
|
sortBy: sortByValue,
|
||||||
|
orderBy: orderByValue,
|
||||||
|
phoneSearch: searchValue,
|
||||||
|
page,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -42,9 +46,14 @@ const useUsers = () => {
|
|||||||
const nextPage = page + 1;
|
const nextPage = page + 1;
|
||||||
|
|
||||||
queryClient.prefetchQuery({
|
queryClient.prefetchQuery({
|
||||||
queryKey: ['users', sortByValue, orderByValue, phoneSearch, nextPage],
|
queryKey: ['users', sortByValue, orderByValue, searchValue, nextPage],
|
||||||
queryFn: () =>
|
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;
|
const previousPage = page - 1;
|
||||||
|
|
||||||
queryClient.prefetchQuery({
|
queryClient.prefetchQuery({
|
||||||
queryKey: ['users', sortByValue, orderByValue, phoneSearch, previousPage],
|
queryKey: ['users', sortByValue, orderByValue, searchValue, previousPage],
|
||||||
queryFn: () =>
|
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_CREATE_ROOM = "Can't create room!";
|
||||||
const ERROR_DELETE_ROOM = "Can't delete room!";
|
const ERROR_DELETE_ROOM = "Can't delete room!";
|
||||||
|
|
||||||
|
interface IGetAllRooms {
|
||||||
|
sortBy: string;
|
||||||
|
orderBy: string;
|
||||||
|
roomName: string;
|
||||||
|
page: number;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all rooms from database
|
* Get all rooms from database
|
||||||
* @returns Return all rooms in database
|
* @returns Return all rooms in database
|
||||||
*/
|
*/
|
||||||
const getAllRooms = async (
|
const getAllRooms = async ({
|
||||||
sortBy: string,
|
sortBy,
|
||||||
orderBy: string,
|
orderBy,
|
||||||
roomName: string,
|
roomName,
|
||||||
page: number
|
page,
|
||||||
): Promise<{ data: IRoom[]; count: number | null }> => {
|
}: IGetAllRooms): Promise<{ data: IRoom[]; count: number | null }> => {
|
||||||
const from = (page - 1) * DEFAULT_PAGE_SIZE;
|
const from = (page - 1) * DEFAULT_PAGE_SIZE;
|
||||||
const to = from + DEFAULT_PAGE_SIZE - 1;
|
const to = from + DEFAULT_PAGE_SIZE - 1;
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,13 @@ const updateUser = async (user: IUser): Promise<IUser> => {
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface IGetAllUsers {
|
||||||
|
sortBy: string;
|
||||||
|
orderBy: string;
|
||||||
|
phoneSearch: string;
|
||||||
|
page: number;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return data of users from database
|
* Return data of users from database
|
||||||
* @param sortBy Sort by column
|
* @param sortBy Sort by column
|
||||||
@@ -59,12 +66,12 @@ const updateUser = async (user: IUser): Promise<IUser> => {
|
|||||||
* @param phoneSearch The phone need to be search
|
* @param phoneSearch The phone need to be search
|
||||||
* @returns The data of users from database
|
* @returns The data of users from database
|
||||||
*/
|
*/
|
||||||
const getAllUsers = async (
|
const getAllUsers = async ({
|
||||||
sortBy: string,
|
sortBy,
|
||||||
orderBy: string,
|
orderBy,
|
||||||
phoneSearch: string,
|
phoneSearch,
|
||||||
page: number
|
page,
|
||||||
): Promise<{ data: IUser[]; count: number | null }> => {
|
}: IGetAllUsers): Promise<{ data: IUser[]; count: number | null }> => {
|
||||||
const from = (page - 1) * DEFAULT_PAGE_SIZE;
|
const from = (page - 1) * DEFAULT_PAGE_SIZE;
|
||||||
const to = from + DEFAULT_PAGE_SIZE - 1;
|
const to = from + DEFAULT_PAGE_SIZE - 1;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user