diff --git a/src/components/country/CountrySettings.jsx b/src/components/country/CountrySettings.jsx index f9d6532..c397480 100644 --- a/src/components/country/CountrySettings.jsx +++ b/src/components/country/CountrySettings.jsx @@ -1,13 +1,17 @@ -import { useState } from "react"; -import { useQuery } from '@tanstack/react-query' +import { useEffect, useState } from "react"; +import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query' import queryKeys from '../../services/queryKeys' import BreadcrumbCom from "../breadcrumb/BreadcrumbCom"; -import { getCountry } from "../../services/siteServices"; +import { getCountry, setCountry } from "../../services/siteServices"; import TableWrapper from "../tableWrapper/TableWrapper"; export default function CountrySettings(){ - const {data, isFetching, isError, error} = useQuery({ + const [selected, setSelected] = useState('') + + const queryClient = useQueryClient() + + const {data, isFetching, status, isError, error} = useQuery({ queryKey: queryKeys.country_list, queryFn: () => { const reqData = { @@ -16,19 +20,52 @@ export default function CountrySettings(){ } return getCountry(reqData) }, - staleTime: 0 //0 mins + // placeholderData: (previousData, previousQuery) => previousData, + staleTime: 0 // 0 mins }) const countryData = data?.data?.country_data // COUNTRY LIST + const statusChange = useMutation({ + mutationFn: (fields) => { + return setCountry(fields) + }, + onError: (error) => { + }, + onSuccess: (res) => { + queryClient.refetchQueries({ + queryKey: [...queryKeys.country_list], + // type: 'active', + // exact: true, + }) + }, + onSettled: () => { + setSelected('') + } + }) + + //FUNCTION TO CHANGE STATUS OR SIGNUP + const handleStatusChange = (event, details) => { + setSelected(event.target.id) + const name = event.target.name + const val = name.toLowerCase() == 'STATUS' ? details.status : details.signup + const reqData = { + 'val_type': name.toUpperCase(), + 'country_uid': details?.country_uid, + 'code': details?.code, + 'val': val == 0 ? 1 : 0 + } + statusChange.mutate(reqData) + }; + return (
Loading...
: isError ?{error.message}
@@ -67,25 +104,52 @@ export default function CountrySettings(){Loading...
+