use-post-get-users-from-country.tsx 811 B

1234567891011121314151617181920212223242526
  1. import { countriesQueryKeys } from '../countries-query-keys';
  2. import { countriesApi, type PostGetUsersFromCountryDataReturn } from '../countries-api';
  3. import type { BaseAxiosError } from '../../../../types';
  4. import { useMutation } from '@tanstack/react-query';
  5. export const useGetUsersFromCountryMutation = () => {
  6. return useMutation<
  7. PostGetUsersFromCountryDataReturn,
  8. BaseAxiosError,
  9. { id: number; page: number; sort?: string; age?: number },
  10. PostGetUsersFromCountryDataReturn
  11. >({
  12. mutationKey: countriesQueryKeys.getUsersFromCountry(),
  13. mutationFn: async (variables) => {
  14. const response = await countriesApi.getUsersFromCountry(
  15. variables.id,
  16. variables.page,
  17. variables.sort,
  18. variables.age
  19. );
  20. return response.data;
  21. }
  22. });
  23. };