360 lines
9.6 KiB
TypeScript
360 lines
9.6 KiB
TypeScript
import { useInfiniteQuery, useMutation, useQuery } from '@tanstack/react-query';
|
|
import { contractorStageThreeSubmit, contractorStageTwoSubmit, fetchAuctionItem, fetchCityDropdown, fetchDashboard, fetchEmdCheck, fetchLiveAuction, fetchLiveTender, fetchMasterData, fetchPurchaseAuction, fetchPurchaseAuctionList, fetchPurchaseTender, fetchTenderById, getAuction, getDesignation, getRagistrationState, offlineAuctionPurchase, offlineTenderPurchase, partnerShipSubmit, proceedToBid, registerContractor, sendAadhaarOtp, submitEnvelopeA, submitEnvelopeB, uploadEnvelopeFile, userAuctionLogin, userLogin, verifyAadhaarOtp, verifyGstNumber, verifyPanHandler, viewAuctionDocumentDownload, viewAuctionDocuments, viewAuctionItemDocuments, fetchPurchaseAuctionPage, tenderDetails, fetchLiveTenderById, fetchContractorProfile, updateUserProfile, eSetuAdharVarification, fetchTenderBidDetailById } from './apis';
|
|
|
|
// User
|
|
|
|
export const useLogin = () => {
|
|
return useMutation({
|
|
mutationFn: (payload: { emailAdd: string, password: string }) => userLogin(payload),
|
|
});
|
|
};
|
|
export const useAuctionLogin = () => {
|
|
return useMutation({
|
|
mutationFn: (payload: { emailAdd: string, password: string }) => userAuctionLogin(payload),
|
|
});
|
|
};
|
|
|
|
// Dashboard
|
|
export const useDashboard = () => {
|
|
return useQuery({
|
|
queryKey: ['fetchDashboard'],
|
|
queryFn: () => fetchDashboard()
|
|
});
|
|
};
|
|
|
|
// Auction & Tender
|
|
|
|
export const useFetchPurchaseTender = () => {
|
|
return useInfiniteQuery({
|
|
queryKey: ['fetchPurchaseTender'],
|
|
queryFn: ({ pageParam = 0 }) =>
|
|
fetchPurchaseTender({
|
|
page: pageParam,
|
|
size: 10,
|
|
}),
|
|
initialPageParam: 0,
|
|
getNextPageParam: (lastPage, allPages) => {
|
|
const { totalCount } = lastPage;
|
|
|
|
const totalPages = Math.ceil(totalCount / 10);
|
|
const nextPage = allPages.length;
|
|
return nextPage < totalPages ? nextPage : undefined;
|
|
},
|
|
|
|
select: (data) => ({
|
|
...data,
|
|
result: data.pages.flatMap(
|
|
(page: any) => page?.data ?? []
|
|
),
|
|
}),
|
|
});
|
|
};
|
|
|
|
|
|
|
|
export const useFetchLiveTender = () => {
|
|
|
|
return useInfiniteQuery({
|
|
queryKey: ['fetchLiveTender'],
|
|
queryFn: ({ pageParam = 0 }) => fetchLiveTender({
|
|
page: pageParam,
|
|
size: 10
|
|
}),
|
|
initialPageParam: 0,
|
|
getNextPageParam: (lastPage, allPages) => {
|
|
const { totalCount } = lastPage;
|
|
console.log("last page : ", lastPage)
|
|
console.log("all pages : ", allPages)
|
|
const totalPages = Math.ceil(totalCount / 10);
|
|
const nextPage = allPages.length;
|
|
return nextPage < totalPages ? nextPage : undefined;
|
|
},
|
|
|
|
select: (data) => ({
|
|
...data,
|
|
result: data.pages.flatMap(
|
|
(page: any) => page?.data ?? []
|
|
),
|
|
}),
|
|
})
|
|
};
|
|
export const useContractorProfile = () => {
|
|
return useQuery({
|
|
queryKey: ['Profile',],
|
|
queryFn: () => fetchContractorProfile()
|
|
});
|
|
};
|
|
|
|
|
|
export const useFetchPurchaseAuction = () => {
|
|
return useQuery({
|
|
queryKey: ['fetchPurchaseAuction',],
|
|
queryFn: () => fetchPurchaseAuction()
|
|
});
|
|
};
|
|
|
|
export const useFetchLiveAuctionPage = (payload: any) => {
|
|
return useInfiniteQuery<any>({
|
|
queryKey: ['fetchPurchaseAuctionPage', payload],
|
|
queryFn: ({ pageParam = 0 }) =>
|
|
fetchPurchaseAuctionPage({
|
|
page: pageParam,
|
|
size: 10,
|
|
...payload
|
|
}),
|
|
initialPageParam: 0,
|
|
|
|
getNextPageParam: (lastPage, allPages) => {
|
|
const { size, totalCount } = lastPage;
|
|
const totalPages = Math.ceil(totalCount / size);
|
|
const nextPage = allPages.length;
|
|
return nextPage < totalPages ? nextPage : undefined;
|
|
},
|
|
|
|
select: (data) => {
|
|
const mergedResults = data.pages.flatMap(
|
|
(page: any) => page?.data ?? []
|
|
);
|
|
|
|
return {
|
|
...data,
|
|
result: mergedResults,
|
|
};
|
|
},
|
|
});
|
|
};
|
|
|
|
export const useFetchLiveAuction = () => {
|
|
return useInfiniteQuery<any>({
|
|
queryKey: ['fetchLiveAuction'],
|
|
queryFn: ({ pageParam = 0 }) =>
|
|
fetchLiveAuction({
|
|
page: pageParam,
|
|
size: 10,
|
|
}),
|
|
initialPageParam: 0,
|
|
|
|
getNextPageParam: (lastPage, allPages) => {
|
|
const { size, totalCount } = lastPage;
|
|
const totalPages = Math.ceil(totalCount / size);
|
|
const nextPage = allPages.length;
|
|
return nextPage < totalPages ? nextPage : undefined;
|
|
},
|
|
|
|
select: (data) => {
|
|
const mergedResults = data.pages.flatMap(
|
|
(page: any) => page?.data ?? []
|
|
);
|
|
|
|
return {
|
|
...data,
|
|
result: mergedResults,
|
|
};
|
|
},
|
|
});
|
|
};
|
|
|
|
|
|
// Auction Purchase offline
|
|
|
|
export const useOfflineAuctionPurchase = () => {
|
|
return useMutation({
|
|
mutationFn: (payload: any) => offlineAuctionPurchase(payload),
|
|
});
|
|
};
|
|
export const useOfflineTenderPurchase = () => {
|
|
return useMutation({
|
|
mutationFn: (payload: any) => offlineTenderPurchase(payload),
|
|
});
|
|
};
|
|
|
|
export const useFetchTenderById = (tenderId: string) => {
|
|
return useQuery({
|
|
queryKey: ['fetchTenderById', tenderId],
|
|
queryFn: () => fetchTenderById(tenderId),
|
|
enabled: !!tenderId, // prevents running with undefined id
|
|
});
|
|
}
|
|
export const useFetchTenderBidDetailById = (tenderId: string) => {
|
|
return useQuery({
|
|
queryKey: ['fetchTenderBidDetailById', tenderId],
|
|
queryFn: () => fetchTenderBidDetailById(tenderId),
|
|
});
|
|
}
|
|
export const useProceedToBid = (tenderId?: string) => {
|
|
return useQuery({
|
|
queryKey: ['proceedToBid', tenderId],
|
|
queryFn: () => proceedToBid(tenderId as string),
|
|
|
|
});
|
|
};
|
|
|
|
export const useAuctionItem = () => {
|
|
return useMutation({
|
|
mutationFn: (payload: any) => fetchAuctionItem(payload),
|
|
});
|
|
};
|
|
|
|
|
|
// EMD
|
|
export const useEmdCheck = () => {
|
|
return useMutation({
|
|
mutationFn: (payload: any) => fetchEmdCheck(payload),
|
|
});
|
|
};
|
|
|
|
export const useGetDesignation = () => {
|
|
return useQuery({
|
|
queryKey: ['Designation'],
|
|
queryFn: () => getDesignation()
|
|
|
|
});
|
|
}
|
|
|
|
export const useRegisterContractor = () => {
|
|
return useMutation({
|
|
mutationFn: (payload: any) => registerContractor(payload),
|
|
});
|
|
};
|
|
|
|
export const useRagistrationState = () => {
|
|
return useMutation({
|
|
mutationFn: () => getRagistrationState(),
|
|
});
|
|
};
|
|
|
|
export const useUpdateUserProfile = () => {
|
|
return useMutation({
|
|
mutationFn: (payload:any) => updateUserProfile(payload),
|
|
});
|
|
};
|
|
|
|
|
|
export const usefetchMasterData = () => {
|
|
return useQuery({
|
|
queryKey: ['MasterData'],
|
|
queryFn: () => fetchMasterData()
|
|
|
|
});
|
|
}
|
|
|
|
export const useCityDropdown = () => {
|
|
return useMutation({
|
|
mutationFn: (stateId: number) => fetchCityDropdown(stateId),
|
|
});
|
|
};
|
|
|
|
export const useVerifyPan = () =>
|
|
useMutation({
|
|
mutationFn: verifyPanHandler,
|
|
});
|
|
|
|
|
|
export const useSendAadhaarOtp = () =>
|
|
useMutation({
|
|
mutationFn: sendAadhaarOtp,
|
|
});
|
|
|
|
export const useVerifyAadhaarOtp = () =>
|
|
useMutation({
|
|
mutationFn: verifyAadhaarOtp,
|
|
});
|
|
|
|
export const useVerifyGstNumber = () =>
|
|
useMutation({
|
|
mutationFn: verifyGstNumber,
|
|
});
|
|
|
|
|
|
export const useContractorStageTwoSubmit = () =>
|
|
useMutation({
|
|
mutationFn: contractorStageTwoSubmit,
|
|
});
|
|
|
|
export const useContractorStageThreeSubmit = () =>
|
|
useMutation({
|
|
mutationFn: contractorStageThreeSubmit,
|
|
});
|
|
|
|
export const usePartnerShipSubmit = () =>
|
|
useMutation({
|
|
mutationFn: partnerShipSubmit,
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
export const useSubmitEnvelopeA = () =>
|
|
useMutation({
|
|
mutationFn: submitEnvelopeA,
|
|
})
|
|
|
|
export const useSubmitEnvelopeB = () =>
|
|
useMutation({
|
|
mutationFn: submitEnvelopeB,
|
|
})
|
|
|
|
export const useUploadEnvelopeFile = () =>
|
|
useMutation({
|
|
mutationFn: uploadEnvelopeFile,
|
|
})
|
|
|
|
|
|
|
|
// Purchase Auction List
|
|
export const usePurchaseAuctionList = () => {
|
|
return useMutation({
|
|
mutationFn: (payload: any) => fetchPurchaseAuctionList(payload),
|
|
});
|
|
};
|
|
|
|
export const useGetAuciton = (payload: { auctionId: string }) => {
|
|
return useQuery({
|
|
queryKey: ['getAuction'],
|
|
queryFn: () => getAuction(payload)
|
|
});
|
|
};
|
|
|
|
export const useGetAucitonDocument = (payload: { auctionId: number }) => {
|
|
return useQuery({
|
|
queryKey: ['viewAuctionDocuments'],
|
|
queryFn: () => viewAuctionDocuments(payload)
|
|
});
|
|
};
|
|
|
|
export const useAucitonItemDetail = (payload: { auctionItemId: number }) => {
|
|
return useQuery({
|
|
queryKey: [],
|
|
queryFn: () => viewAuctionItemDocuments(payload)
|
|
});
|
|
};
|
|
|
|
export const useAucitonDocDownload = () => {
|
|
return useMutation({
|
|
mutationFn: (payload: { documentId: number, isAmendment: boolean }) => viewAuctionDocumentDownload(payload),
|
|
});
|
|
};
|
|
|
|
|
|
|
|
|
|
export const useTenderDetails = () => {
|
|
return useMutation({
|
|
mutationFn: (tenderId) => tenderDetails(tenderId),
|
|
});
|
|
};
|
|
|
|
export const useFetchLiveTenderById = (tenderId: number) => {
|
|
return useQuery({
|
|
queryKey: ['fetchLiveTenderById', tenderId],
|
|
queryFn: () => fetchLiveTenderById(tenderId)
|
|
});
|
|
};
|
|
|
|
export const useESetuAdharVarification = () => {
|
|
return useMutation({
|
|
mutationFn: (payload: any) => eSetuAdharVarification(payload),
|
|
});
|
|
};
|