Created
June 9, 2024 13:33
-
-
Save Jalson1982/c797411a675019ae62b7d2b76edc8216 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useCallback} from 'react'; | |
import {Alert} from 'react-native'; | |
import {GUIDES} from '@features/guide/const'; | |
import {useTranslations} from '@hooks'; | |
import {RootStackScreenProps, RouteNames} from '@navigation'; | |
import { | |
setShouldRefresh, | |
useAppDispatch, | |
useAwardConsultantMutation, | |
useAwardedVendorsQuery, | |
} from '@store'; | |
import {SelectedBidder} from '../../components/templates'; | |
export const SelectConsultant = ({ | |
navigation, | |
route, | |
}: RootStackScreenProps<typeof RouteNames.SelectConsultant>) => { | |
const params = route.params; | |
const {translate} = useTranslations(); | |
const dispatch = useAppDispatch(); | |
const [awardConsultant, {isLoading}] = useAwardConsultantMutation(); | |
const {refetch} = useAwardedVendorsQuery(); | |
const onSubmit = useCallback( | |
async (vendorId: string) => { | |
try { | |
await awardConsultant({ | |
vendorId, | |
serviceRequestId: params.serviceRequestId, | |
}); | |
dispatch(setShouldRefresh({key: 'home', value: true})); | |
refetch(); | |
navigation.navigate(RouteNames.ServicePopUp, { | |
title: translate('portal_select_consultant_success_popup_title'), | |
subtitle: `${translate('portal_info_modal_sr_number')} #${ | |
params.caseNumber | |
}`, | |
description: translate( | |
'portal_select_consultant_success_popup_description', | |
), | |
action: () => navigation.navigate(RouteNames.Home), | |
}); | |
} catch (error) { | |
Alert.alert('Error', error?.toString()); | |
} | |
}, | |
[ | |
awardConsultant, | |
params.serviceRequestId, | |
params.caseNumber, | |
dispatch, | |
refetch, | |
navigation, | |
translate, | |
], | |
); | |
return ( | |
<SelectedBidder | |
type="consultants" | |
isLoading={isLoading} | |
onSubmit={onSubmit} | |
serviceRequestId={params.serviceRequestId} | |
slug={GUIDES.FIND_CONSULTANT_SERVICE} | |
/> | |
); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useCallback} from 'react'; | |
import {Alert} from 'react-native'; | |
import {useTranslations} from '@hooks'; | |
import {RootStackScreenProps, RouteNames} from '@navigation'; | |
import { | |
setShouldRefresh, | |
useAppDispatch, | |
useAwardContractorMutation, | |
useAwardedVendorsQuery, | |
} from '@store'; | |
import {SelectedBidder} from '../../components/templates'; | |
export const SelectContractor = ({ | |
navigation, | |
route, | |
}: RootStackScreenProps<typeof RouteNames.SelectContractor>) => { | |
const params = route.params; | |
const {translate} = useTranslations(); | |
const dispatch = useAppDispatch(); | |
const [awardConstractor, {isLoading}] = useAwardContractorMutation(); | |
const {refetch} = useAwardedVendorsQuery(); | |
const onSubmit = useCallback( | |
async (vendorId: string) => { | |
try { | |
await awardConstractor({ | |
vendorId, | |
serviceRequestId: params.serviceRequestId, | |
}); | |
dispatch(setShouldRefresh({key: 'home', value: true})); | |
refetch(); | |
navigation.navigate(RouteNames.ServicePopUp, { | |
title: translate('portal_select_contractor_success_popup_title'), | |
subtitle: `${translate('portal_info_modal_sr_number')} #${ | |
params.caseNumber | |
}`, | |
description: translate( | |
'portal_select_contractor_success_popup_description', | |
), | |
action: () => navigation.navigate(RouteNames.Home), | |
}); | |
} catch (error) { | |
Alert.alert('Error', error?.toString()); | |
} | |
}, | |
[ | |
awardConstractor, | |
params.serviceRequestId, | |
params.caseNumber, | |
dispatch, | |
refetch, | |
navigation, | |
translate, | |
], | |
); | |
return ( | |
<SelectedBidder | |
type="contractors" | |
isLoading={isLoading} | |
onSubmit={onSubmit} | |
serviceRequestId={params.serviceRequestId} | |
/> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment