diff --git a/src/Screens/Tender/ProceedToBidDetail.tsx b/src/Screens/Tender/ProceedToBidDetail.tsx index 086ef56..f981123 100644 --- a/src/Screens/Tender/ProceedToBidDetail.tsx +++ b/src/Screens/Tender/ProceedToBidDetail.tsx @@ -107,27 +107,27 @@ const ProceedToBidDetail = () => { - {tenderData.tenderNumber} - ID: {tenderData.tenderId} + {tenderData?.tenderNumber} + ID: {tenderData?.tenderId} - + - {tenderData.biddingStatus ? "Active" : "Inactive"} + {tenderData?.biddingStatus ? "Active" : "Inactive"} - {tenderData.nameofWork} + {tenderData?.nameofWork} NIT No. - {tenderData.nitNo} + {tenderData?.nitNo} EMD Amount - ₹{tenderData.emdInFig} + ₹{tenderData?.emdInFig} @@ -136,19 +136,19 @@ const ProceedToBidDetail = () => { Envelope Submission Status - - - + + + {/* Envelope Logs */} - {tenderData.envelopeA_Logs && ( + {tenderData?.envelopeA_Logs && ( Submission Logs - - - + + + )} @@ -156,11 +156,11 @@ const ProceedToBidDetail = () => { Tender Details - - - - - + + + + + @@ -170,11 +170,11 @@ const ProceedToBidDetail = () => { Starts On: - {formatDate(tenderData.submittedStartDate)} + {formatDate(tenderData?.submittedStartDate)} Ends On: - {formatDate(tenderData.submittedEndDate)} + {formatDate(tenderData?.submittedEndDate)} @@ -183,12 +183,12 @@ const ProceedToBidDetail = () => { Available Features - - - - - - + + + + + + @@ -199,18 +199,18 @@ const ProceedToBidDetail = () => { All Envelopes Submitted: - {tenderData.envelopeASubmittStatus && tenderData.envelopeBSubmittStatus && tenderData.envelopeCSubmittStatus + {tenderData?.envelopeASubmittStatus && tenderData?.envelopeBSubmittStatus && tenderData?.envelopeCSubmittStatus ? "COMPLETED" : "PENDING"} Bidding Status: - {tenderData.biddingStatus ? "ACTIVE" : "CLOSED"} + { color: tenderData?.biddingStatus ? colors.success : colors.error }]}> + {tenderData?.biddingStatus ? "ACTIVE" : "CLOSED"} diff --git a/src/Screens/Tender/tenderBidding/TenderBidding.tsx b/src/Screens/Tender/tenderBidding/TenderBidding.tsx index d0f86aa..2ac6375 100644 --- a/src/Screens/Tender/tenderBidding/TenderBidding.tsx +++ b/src/Screens/Tender/tenderBidding/TenderBidding.tsx @@ -15,10 +15,11 @@ import MyInput from '../../../../src/Component/MyInput'; import { pick, types } from '@react-native-documents/picker'; import { InsideHeader } from '../../../Component/Index'; import colors from '../../../Constant/Color'; -import { SUBMIT_ENVELOPE_A, SUBMIT_ENVELOPE_B } from '../../../Services/BBPS/ApiUrls'; +import { SUBMIT_ENVELOPE_A, SUBMIT_ENVELOPE_B, SUBMIT_ENVELOPE_FILE_A, SUBMIT_ENVELOPE_FILE_B } from '../../../Services/BBPS/ApiUrls'; import axios from 'axios'; import { Fontisto } from '@react-native-vector-icons/fontisto'; -import { useSubmitEnvelopeA, useSubmitEnvelopeB } from '../../../Services/BBPS/Hooks'; +import { useSubmitEnvelopeA, useSubmitEnvelopeB, useUploadEnvelopeFile } from '../../../Services/BBPS/Hooks'; +import { apiCall } from '../../../Axios/Axios'; type EnvelopeType = 'A' | 'B' | 'C'; type EnvelopeFormState = { @@ -40,16 +41,14 @@ interface InfoRowProps { const TenderBidding = () => { const route = useRoute(); const navigation = useNavigation(); - const { mutate: submitEnvelopeA, isPending } = useSubmitEnvelopeA(() => { - navigation.goBack() - }) - const { mutate: submitEnvelopeB, isPending: isPendingB } = useSubmitEnvelopeB(() => { - navigation.goBack() - }) + const { mutate: submitEnvelopeA, isPending } = useSubmitEnvelopeA() + const { mutate: submitEnvelopeB, isPending: isPendingB } = useSubmitEnvelopeB() + const { mutate: uploadEnvelopeFile, isPending: uploadLoading } = + useUploadEnvelopeFile() const [bidData] = useState(route.params?.tenderData || null); - const tenderData: any= route.params?.bidData || null; - const [activeEnvelope, setActiveEnvelope] = useState('A'); + const tenderData: any = route.params?.bidData || null; + const [activeEnvelope, setActiveEnvelope] = useState('A'); const [isLoading, setIsLoading] = useState(false); const [envelopForm, setEnvelopForm] = useState({ A: {}, @@ -326,7 +325,7 @@ const TenderBidding = () => { }; const validateEnvelope = () => { - const list = bidData?.[`tenderEnvelope${activeEnvelope}List`] || []; + const list = tenderData?.[`tenderEnvelope${activeEnvelope}List`] || []; const formValues = envelopForm[activeEnvelope]; const missing = list.some((item: any) => { @@ -348,35 +347,59 @@ const TenderBidding = () => { return !missing; }; - const handleSubmitEnvelopeA = () => { + + const handleSubmitEnvelopeA = async () => { if (!validateEnvelope()) { - Alert.alert('Validation Error', 'Please fill all mandatory fields') - return + Alert.alert('Validation Error', 'Please fill all mandatory fields'); + return; } - const payload = buildEnvelopePayload() - console.log('Envelope A Payload:', payload) + const payload = buildEnvelopePayload(); + console.log('Envelope A Payload:', payload); + setLoading(true) + if (envelopForm?.[activeEnvelope]?.[3]) { + handleSubmitEnvelopeFile() + } + try { + + const res = await apiCall('post',SUBMIT_ENVELOPE_A, payload) + console.log("res A envelop : ", res) + ToastAndroid.show(res.message, ToastAndroid.SHORT) + + + navigation.goBack() + } catch (error) { + console.log("error A envelop submit : ", error) + } finally { + setLoading(false) + } + }; + + + const handleSubmitEnvelopeB = async () => { + if (!validateEnvelope()) { + Alert.alert('Validation Error', 'Please fill all mandatory fields'); + return; + } + setLoading(true) + const payload = buildEnvelopePayload(); + console.log('Envelope B Payload:', payload); + if (envelopForm?.[activeEnvelope]?.[3]) { handleSubmitEnvelopeFile() } + try { + const res = await apiCall('post', SUBMIT_ENVELOPE_B, payload) + console.log("res B envelop : ", res) - submitEnvelopeA(payload) - } - const handleSubmitEnvelopeB = () => { - if (!validateEnvelope()) { - Alert.alert('Validation Error', 'Please fill all mandatory fields') - return + ToastAndroid.show(res.message, ToastAndroid.SHORT) + navigation.goBack() + } catch (error) { + console.log("error B envelop submit : ", error) + } finally { + setLoading(false) } - - const payload = buildEnvelopePayload() - console.log('Envelope A Payload:', payload) - - if (envelopForm?.[activeEnvelope]?.[3]) { - handleSubmitEnvelopeFile() - } - - submitEnvelopeB(payload) } const handleSubmitEnvelopeFile = async () => { @@ -396,8 +419,7 @@ const TenderBidding = () => { console.log("reuestDto for fil doc : ", formData) - // return - const res = await axios.post(activeEnvelope === 'B' ? SUBMIT_ENVELOPE_B : SUBMIT_ENVELOPE_A, payload) + const res = await apiCall('post', activeEnvelope === 'B' ? SUBMIT_ENVELOPE_FILE_B : SUBMIT_ENVELOPE_FILE_A, payload) console.log(`res file ${activeEnvelope} Payload:`, res) ToastAndroid.show(res.message, ToastAndroid.SHORT) // navigation.goBack() @@ -408,18 +430,8 @@ const TenderBidding = () => { } } - if (isLoading) { - return ( - <> - - Loading... - - - ); - } - // console.log("route for date : ", bidData) - // console.log("bid envelop : ", tenderData) + return ( @@ -492,6 +504,7 @@ const TenderBidding = () => { )} + {hasEnvelopes() ? ( { getNextPageParam: (lastPage, allPages) => { console.log('last page : ', lastPage) console.log("all page : ", allPages) - const {totalCount } = lastPage; + const { totalCount } = lastPage; const totalPages = Math.ceil(totalCount / 10); const nextPage = allPages.length; @@ -122,29 +122,17 @@ export const useProceedToBid = (tenderId?: string) => { }; -export const useSubmitEnvelopeA = (onSuccessCallback?: () => void) => { - return useMutation({ +export const useSubmitEnvelopeA = () => + useMutation({ mutationFn: submitEnvelopeA, - onSuccess: (data) => { - ToastAndroid.show(data?.message || 'Submitted successfully', ToastAndroid.SHORT) - onSuccessCallback?.() - }, - onError: (error: any) => { - console.log('Envelope A submit error:', error) - ToastAndroid.show('Something went wrong', ToastAndroid.SHORT) - }, }) -} -export const useSubmitEnvelopeB = (onSuccessCallback?: () => void) => { - return useMutation({ + +export const useSubmitEnvelopeB = () => + useMutation({ mutationFn: submitEnvelopeB, - onSuccess: (data) => { - ToastAndroid.show(data?.message || 'Submitted successfully', ToastAndroid.SHORT) - onSuccessCallback?.() - }, - onError: (error: any) => { - console.log('Envelope A submit error:', error) - ToastAndroid.show('Something went wrong', ToastAndroid.SHORT) - }, }) -} \ No newline at end of file + +export const useUploadEnvelopeFile = () => + useMutation({ + mutationFn: uploadEnvelopeFile, + }) diff --git a/src/Services/BBPS/apis.ts b/src/Services/BBPS/apis.ts index cf22cde..c8ee2fb 100644 --- a/src/Services/BBPS/apis.ts +++ b/src/Services/BBPS/apis.ts @@ -3,7 +3,15 @@ import { DASHBOARD_COUNT, GET_MY_AUCTION, GET_MY_TENDER, GET_TENDER_DETAILS, LIV import { apiCall } from "../../Axios/Axios"; // User - +export type UploadArgs = { + activeEnvelope: 'A' | 'B' + file: { + uri: string + name: string + type: string + } + payload: any +} export const userLogin = async (payload: { emailAdd: string, password: string }): Promise => { try { // const response = await axios.post(LOG_IN_URL, { ...payload, divice: "mobileApp" }); @@ -85,14 +93,42 @@ export const proceedToBid = async (tenderId: string): Promise => { } export const submitEnvelopeA = async (payload: any) => { + console.log('SUBMIT ENVELOPE A API CALLED', payload) const { data } = await apiCall('post', SUBMIT_ENVELOPE_A, payload) + console.log("data : ", data) return data } export const submitEnvelopeB = async (payload: any) => { + console.log('SUBMIT ENVELOPE B API CALLED', payload) const { data } = await apiCall('post', SUBMIT_ENVELOPE_B, payload) + console.log("data : ", data) return data } -export const submitEnvelopeFileB = async (payload: any) => { - const { data } = await apiCall('post', SUBMIT_ENVELOPE_FILE_B, payload) + + +export const uploadEnvelopeFile = async ({ + activeEnvelope, + file, + payload, +}: UploadArgs) => { + const formData = new FormData() + + formData.append('files', { + uri: file.uri, + name: file.name, + type: file.type, + } as any) + + formData.append('requestDto', JSON.stringify(payload)) + + const url = + activeEnvelope === 'B' ? SUBMIT_ENVELOPE_FILE_B : SUBMIT_ENVELOPE_FILE_A + + const data = await apiCall('post', url, formData, { + headers: { + 'Content-Type': 'multipart/form-data', + }, + }) + return data } \ No newline at end of file