import React from 'react'; import {Alert, Platform} from 'react-native'; import Assets from '../../../components/assets.manager.js'; import Theme from '../../../components/theme.style.js'; const formData = (data) => { let formData = new FormData() formData.append('firstname', data.userProfile.firstname) formData.append('middlename', data.userProfile.middlename) formData.append('lastname', data.userProfile.lastname) formData.append('birthdate', Theme.formatter.DTUI(data.userProfile.birthdate)) formData.append('mobile', data.newmobile && data.newmobile != "+" + data.userProfile.mobile ? Theme.formatter.PMBL(data.newmobile.replace("+", "")) : Theme.formatter.PMBL(data.userProfile.mobile)) formData.append('email', data.newemail ? data.newemail : data.userProfile.email) formData.append('address', data.newaddress ? data.newaddress : data.userProfile.address) // formData.append('city', data.newcity ? data.newcity : data.userProfile.city_name) formData.append('vo_code', data.vehicleType ? data.vehicleType.value : data.userProfile.vo_code) formData.append('fueltype_code', data.fuelType ? data.fuelType.value : data.userProfile.fueltype_code) formData.append('civilstatus_code', data.maritalStatus ? data.maritalStatus.value : data.userProfile.civilstatus_code) formData.append('gender_code', data.gender ? data.gender.value : data.userProfile.gender_code) formData.append('is_deleted', data.is_deleted) return formData } const responseHandler = (res, callback, onError, props) => { if(res.status == 1){ if(Platform.OS == 'ios'){ setTimeout(() => { Alert.alert("Success", '\n' + "Your profile is successfully updated", [{text: "OK", onPress: () => callback()}]); }, 700) }else{ setTimeout(() => { Alert.alert("Success", '\n' + "Your profile is successfully updated", [{text: "OK", onPress: () => { navigation.route.params.onGoBack(); navigation.navigation.goBack(); }}]); }, 700) } }else{ onError(res.data) if(Platform.OS == 'ios'){ let message = res?.data.email[0] != undefined ? res?.data.email : res.message; Alert.alert("Information", '\n' + message); } } } const blobBody = (data) => { const body = { image: { name: data.newphoto.fileName, type: data.newphoto.type, uri: Platform.OS === 'android' ? data.newphoto.uri : data.newphoto.uri.replace('file://', ''), }, firstname: data.userProfile.firstname, middlename: data.userProfile.middlename, lastname: data.userProfile.lastname, birthdate: Theme.formatter.DTUI(data.userProfile.birthdate), mobile: data.newmobile && data.newmobile != "+" + data.userProfile.mobile ? Theme.formatter.PMBL(data.newmobile.replace("+", "")) : Theme.formatter.PMBL(data.userProfile.mobile), email: data.newemail ? data.newemail : data.userProfile.email, address: data.newaddress ? data.newaddress : data.userProfile.address, vo_code: data.vehicleType ? data.vehicleType.value : data.userProfile.vo_code, fueltype_code: data.fuelType ? data.fuelType.value : data.userProfile.fueltype_code, civilstatus_code: data.maritalStatus ? data.maritalStatus.value : data.userProfile.civilstatus_code, gender_code: data.gender ? data.gender.value : data.userProfile.gender_code, is_deleted: data.is_deleted } return body } export default { blobBody, formData, responseHandler }