before merge
This commit is contained in:
@@ -0,0 +1,278 @@
|
||||
import {
|
||||
KeyboardAvoidingView,
|
||||
SafeAreaView,
|
||||
ScrollView,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
Platform,
|
||||
} from 'react-native';
|
||||
import React, { use, useState } from 'react';
|
||||
import { useNavigation, useRoute, NavigationProp, RouteProp } from '@react-navigation/native';
|
||||
import colors from '../../Constant/Color';
|
||||
import PrimaryButton from '../../Component/PrimaryButton/PrimaryButton';
|
||||
import MyInput from '../../Component/MyInput';
|
||||
import { showToast } from '../../Constant/ShowDailog';
|
||||
import { PARTNER_API_ENDPOINT } from '../../Services/BBPS/ApiUrls';
|
||||
import { usePartnerShipSubmit } from '../../Services/BBPS/Hooks';
|
||||
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
||||
import { Navigation } from 'lucide-react-native';
|
||||
import { NavigationString } from '../../Constant/AllImports';
|
||||
|
||||
|
||||
type Partner = {
|
||||
partnerName: string;
|
||||
percentage: string;
|
||||
partnerPan: string;
|
||||
aadharNumber: string;
|
||||
mobileNumber: string;
|
||||
};
|
||||
type Navigation = {
|
||||
replace: (route: string) => void;
|
||||
};
|
||||
type PartnershipParams = {
|
||||
otherId: string | number
|
||||
};
|
||||
const Partnership = () => {
|
||||
const route = useRoute<RouteProp<{ params: PartnershipParams }, 'params'>>();
|
||||
|
||||
const navigation = useNavigation() as Navigation;
|
||||
const [partners, setPartners] = useState<Partner[]>([
|
||||
{
|
||||
partnerName: '',
|
||||
percentage: '',
|
||||
partnerPan: '',
|
||||
aadharNumber: '',
|
||||
mobileNumber: '',
|
||||
},
|
||||
]);
|
||||
|
||||
const [focusedField, setFocusedField] = useState<string>('');
|
||||
const [loading, setLoading] = useState(false)
|
||||
const { mutateAsync:partnerShipSubmit } = usePartnerShipSubmit();
|
||||
const insets = useSafeAreaInsets();
|
||||
const handleChange = (index: number, name: keyof Partner, value: string) => {
|
||||
const updated = [...partners];
|
||||
updated[index][name] = value;
|
||||
setPartners(updated);
|
||||
};
|
||||
|
||||
const handleAddMore = () => {
|
||||
setPartners(prev => [
|
||||
...prev,
|
||||
{
|
||||
partnerName: '',
|
||||
percentage: '',
|
||||
partnerPan: '',
|
||||
aadharNumber: '',
|
||||
mobileNumber: '',
|
||||
},
|
||||
]);
|
||||
};
|
||||
|
||||
const handleRemove = (index: number) => {
|
||||
const updated = [...partners];
|
||||
updated.splice(index, 1);
|
||||
setPartners(
|
||||
updated.length > 0
|
||||
? updated
|
||||
: [
|
||||
{
|
||||
partnerName: '',
|
||||
percentage: '',
|
||||
partnerPan: '',
|
||||
aadharNumber: '',
|
||||
mobileNumber: '',
|
||||
},
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
// Convert percentage strings to numbers and validate
|
||||
const payload = partners.map((p, i) => {
|
||||
const percentage = Number(p.percentage);
|
||||
|
||||
if (isNaN(percentage) || percentage < 0 || percentage > 100) {
|
||||
throw new Error(`Invalid percentage value for partner ${p.partnerName}`);
|
||||
}
|
||||
|
||||
return {
|
||||
contOtherId: route?.params?.otherId,
|
||||
ptnrAadharNo: p.aadharNumber,
|
||||
ptnrMobNo: p.mobileNumber,
|
||||
ptnrName: p.partnerName,
|
||||
ptnrPop: percentage, // Ensure this is a number
|
||||
ptnrPANNo: p.partnerPan,
|
||||
ptnrNo: i,
|
||||
};
|
||||
});
|
||||
|
||||
// Validate total percentage equals 100%
|
||||
const totalPercentage = payload.reduce((sum, p) => sum + p.ptnrPop, 0);
|
||||
if (totalPercentage !== 100) {
|
||||
showToast(`Total percentage must equal 100% (currently ${totalPercentage}%)`);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Partner ship payload:", payload);
|
||||
const response = await partnerShipSubmit(payload);
|
||||
|
||||
console.log("first ====== ", response)
|
||||
if (response?.statusCode === 200) {
|
||||
console.log('✅ Partners submitted successfully:', response);
|
||||
showToast(response.message || 'Submitted successfully!');
|
||||
navigation.replace(NavigationString.Home);
|
||||
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('❌ Submission failed:', error.message);
|
||||
showToast(error.message || 'Submission failed. Please check partner details.');
|
||||
}finally{
|
||||
setLoading(false)
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={{ flex: 1 }}>
|
||||
<Text style={[styles.heading, { paddingTop: insets.top }]}>Partnership Details</Text>
|
||||
<SafeAreaView style={{ flex: 1 }}>
|
||||
<KeyboardAvoidingView
|
||||
style={{ flex: 1 }}
|
||||
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
||||
keyboardVerticalOffset={40}
|
||||
>
|
||||
<ScrollView contentContainerStyle={styles.scrollContainer} keyboardShouldPersistTaps="handled">
|
||||
{partners.map((partner, index) => (
|
||||
<View style={{ marginBottom: 20 }} key={index}>
|
||||
<Text style={styles.partnerTitle}>Partner {index + 1}</Text>
|
||||
|
||||
<MyInput
|
||||
icon="user"
|
||||
placeholder="Name of Partner *"
|
||||
value={partner.partnerName}
|
||||
onChangeText={text => handleChange(index, 'partnerName', text)}
|
||||
onFocus={() => setFocusedField(`partnerName-${index}`)}
|
||||
onBlur={() => setFocusedField('')}
|
||||
focused={focusedField === `partnerName-${index}`}
|
||||
/>
|
||||
|
||||
<MyInput
|
||||
icon="percent"
|
||||
placeholder="Partnership Percentage *"
|
||||
value={partner.percentage}
|
||||
onChangeText={text => handleChange(index, 'percentage', text)}
|
||||
onFocus={() => setFocusedField(`percentage-${index}`)}
|
||||
onBlur={() => setFocusedField('')}
|
||||
focused={focusedField === `percentage-${index}`}
|
||||
keyboardType="numeric"
|
||||
maxlength={3}
|
||||
/>
|
||||
|
||||
<MyInput
|
||||
icon="id-card"
|
||||
placeholder="PAN of Partner *"
|
||||
value={partner.partnerPan}
|
||||
onChangeText={text => handleChange(index, 'partnerPan', text)}
|
||||
onFocus={() => setFocusedField(`partnerPan-${index}`)}
|
||||
onBlur={() => setFocusedField('')}
|
||||
focused={focusedField === `partnerPan-${index}`}
|
||||
autoCapitalize="characters"
|
||||
maxlength={10}
|
||||
|
||||
/>
|
||||
|
||||
<MyInput
|
||||
icon="credit-card"
|
||||
placeholder="Aadhar Number *"
|
||||
value={partner.aadharNumber}
|
||||
onChangeText={text => handleChange(index, 'aadharNumber', text)}
|
||||
onFocus={() => setFocusedField(`aadharNumber-${index}`)}
|
||||
onBlur={() => setFocusedField('')}
|
||||
focused={focusedField === `aadharNumber-${index}`}
|
||||
keyboardType="numeric"
|
||||
maxlength={12}
|
||||
/>
|
||||
|
||||
<MyInput
|
||||
icon="phone"
|
||||
placeholder="Mobile Number *"
|
||||
value={partner.mobileNumber}
|
||||
onChangeText={text => handleChange(index, 'mobileNumber', text)}
|
||||
onFocus={() => setFocusedField(`mobileNumber-${index}`)}
|
||||
onBlur={() => setFocusedField('')}
|
||||
focused={focusedField === `mobileNumber-${index}`}
|
||||
keyboardType="phone-pad"
|
||||
maxlength={10}
|
||||
/>
|
||||
|
||||
{partners.length > 1 && (
|
||||
<TouchableOpacity style={styles.deleteButton} onPress={() => handleRemove(index)}>
|
||||
<Text style={styles.deleteText}>Delete Partner</Text>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
</View>
|
||||
))}
|
||||
|
||||
<TouchableOpacity style={styles.addButton} onPress={handleAddMore}>
|
||||
<Text style={styles.addText}>+ Add Partner</Text>
|
||||
</TouchableOpacity>
|
||||
</ScrollView>
|
||||
</KeyboardAvoidingView>
|
||||
</SafeAreaView>
|
||||
|
||||
<PrimaryButton title={loading ? "Loading..." : "Submit" }onPress={handleSubmit} />
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default Partnership;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
heading: {
|
||||
fontSize: 18,
|
||||
fontWeight: 'bold',
|
||||
marginBottom: 10,
|
||||
marginTop: 10,
|
||||
textAlign: 'center',
|
||||
|
||||
},
|
||||
partnerTitle: {
|
||||
fontWeight: '600',
|
||||
fontSize: 16,
|
||||
marginBottom: 10,
|
||||
},
|
||||
scrollContainer: {
|
||||
// backgroundColor: color.background,
|
||||
flexGrow: 1,
|
||||
},
|
||||
addButton: {
|
||||
backgroundColor: colors.primary,
|
||||
padding: 10,
|
||||
marginTop: 10,
|
||||
borderRadius: 10,
|
||||
alignItems: 'center',
|
||||
width: 140,
|
||||
alignSelf: 'flex-end',
|
||||
},
|
||||
addText: {
|
||||
color: 'white',
|
||||
fontWeight: '600',
|
||||
},
|
||||
deleteButton: {
|
||||
backgroundColor: '#FF5C5C',
|
||||
padding: 10,
|
||||
marginTop: 10,
|
||||
borderRadius: 10,
|
||||
alignItems: 'center',
|
||||
width: 140,
|
||||
alignSelf: 'flex-end',
|
||||
},
|
||||
deleteText: {
|
||||
color: 'white',
|
||||
fontWeight: '600',
|
||||
},
|
||||
});
|
||||
@@ -327,6 +327,7 @@ useEffect(() => {
|
||||
orgPAN: formData.orgPanNumber,
|
||||
comAadharNo: formData.aadhaarNumber,
|
||||
gistnNo: formData.gstnNo,
|
||||
stateName: MasterData?.data?.states?.find((state:any)=>state.stateId==formData.state)?.stateName || '',
|
||||
};
|
||||
console.log('Form Data for registration',formData);
|
||||
|
||||
|
||||
@@ -62,14 +62,14 @@ const Splash: React.FC = () => {
|
||||
|
||||
const routeByOrgType = (params: { otherId: any; orgType: any }) => {
|
||||
const orgType = String(params.orgType);
|
||||
|
||||
console.log("hitting here ")
|
||||
if (orgType === '4' || orgType === '5' || orgType === '6') {
|
||||
navigation.replace('StageThree', params);
|
||||
return;
|
||||
}
|
||||
|
||||
if (orgType === '7') {
|
||||
navigation.replace('PartnerShip', params);
|
||||
navigation.replace(NavigationString.Partnership, params);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ const Splash: React.FC = () => {
|
||||
const handleGetData = async () => {
|
||||
try {
|
||||
const res = await registrationStateMutate();
|
||||
console.log('Registration status response:', res?.statusCode);
|
||||
console.log('Registration status response:', res);
|
||||
|
||||
if (res?.statusCode === 404 || res?.statusCode === 401) {
|
||||
navigation.replace('Registration');
|
||||
|
||||
@@ -7,6 +7,7 @@ import StartReverseBidding from "./Bidding/StartReverseBidding";
|
||||
import Home from "./Home/Home";
|
||||
import Login from "./Login/Login";
|
||||
import Onboarding from "./Onboarding/Onboarding";
|
||||
import Partnership from "./Ragistration/PartnerShip";
|
||||
import Registration from "./Ragistration/Ragistration";
|
||||
import Signup from "./SignUp/SignUp";
|
||||
import Splash from "./Splash/Splash";
|
||||
@@ -34,7 +35,8 @@ const Screens = {
|
||||
ProceedToBidDetail,
|
||||
StartReverseBidding,
|
||||
Signup,
|
||||
Registration
|
||||
Registration,
|
||||
Partnership
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user