Commit ff6fbf64 by Nguyễn Thị Thúy

integrate convert unit api

parent ff0a6cfa
...@@ -14,6 +14,11 @@ import DeviceInfo from 'react-native-device-info'; ...@@ -14,6 +14,11 @@ import DeviceInfo from 'react-native-device-info';
import R from './assets/R'; import R from './assets/R';
import {WIDTHXD, HEIGHTXD} from './Config/Functions'; import {WIDTHXD, HEIGHTXD} from './Config/Functions';
import DropdownManager from './components/DropdownAlert/DropdownManager'; import DropdownManager from './components/DropdownAlert/DropdownManager';
import AsyncStorage from '@react-native-community/async-storage';
import KEY from './assets/AsynStorage';
import I18n, {setLocation} from './helper/i18/i18n';
import {changeLanguage} from './actions/language';
enableScreens(); enableScreens();
...@@ -23,11 +28,16 @@ const RootView = (props) => { ...@@ -23,11 +28,16 @@ const RootView = (props) => {
dropDownAlertRef.current, dropDownAlertRef.current,
dropDownAlertLongTimeRef.current, dropDownAlertLongTimeRef.current,
); );
setInitLanguage()
}, []); }, []);
const dropDownAlertRef = useRef(null); const dropDownAlertRef = useRef(null);
const dropDownAlertLongTimeRef = useRef(null); const dropDownAlertLongTimeRef = useRef(null);
const setInitLanguage = async () => {
const laguage = await AsyncStorage.getItem(KEY.LANGUAGE);
if (laguage) props.changeLanguage(laguage);
setLocation(I18n, laguage);
};
return ( return (
<> <>
<View style={{flex: 1}}> <View style={{flex: 1}}>
...@@ -85,4 +95,4 @@ const mapStateToProps = (state) => { ...@@ -85,4 +95,4 @@ const mapStateToProps = (state) => {
}; };
}; };
export default connect(mapStateToProps, {})(RootView); export default connect(mapStateToProps, {changeLanguage})(RootView);
...@@ -79,7 +79,7 @@ const CaculatedStopLoss = (props) => { ...@@ -79,7 +79,7 @@ const CaculatedStopLoss = (props) => {
if (res.status == 200 && res.data.code == 200) { if (res.status == 200 && res.data.code == 200) {
setDataProduct(res.data.data); setDataProduct(res.data.data);
} else { } else {
showAlert(TYPE.ERROR, I18n.t('Notification', I18n.t('Can_not_get_data'))); showAlert(TYPE.ERROR, I18n.t('Notification'), I18n.t('Can_not_get_data'));
} }
}; };
......
...@@ -67,7 +67,7 @@ const CalculatorProfitLoss = (props) => { ...@@ -67,7 +67,7 @@ const CalculatorProfitLoss = (props) => {
}); });
props.hideLoading(); props.hideLoading();
if (res.status == 200 && res.data.code == 200) { if (res.status == 200 && res.data.code == 200) {
const newList = [res.data.data].concat(dataCalculator); const newList = [res.data.data].concat([...dataCalculator]);
setDataCalculator(newList); setDataCalculator(newList);
setLotTransactionNumber(null); setLotTransactionNumber(null);
setOpenPrice(null); setOpenPrice(null);
......
...@@ -112,7 +112,7 @@ const CalculatorProfitLossView = (props) => { ...@@ -112,7 +112,7 @@ const CalculatorProfitLossView = (props) => {
</View> </View>
<FlatList <FlatList
style={{paddingBottom: HEIGHTXD(15), backgroundColor: R.colors.white}} style={{paddingBottom: HEIGHTXD(15), backgroundColor: R.colors.white}}
keyExtractor={(item) => item.id} keyExtractor={(item) => item}
data={props.dataCalculator} data={props.dataCalculator}
renderItem={({item, index}) => ( renderItem={({item, index}) => (
<ItemCalculator <ItemCalculator
......
import React, {Component, useState} from 'react'; import React, {useEffect, useState} from 'react';
import { import {Platform, StyleSheet, Text, TextInput, View} from 'react-native';
View,
Text,
StyleSheet,
TextInput,
TouchableOpacity,
} from 'react-native';
import HeaderBack from '../../components/Header/HeaderBack'; import HeaderBack from '../../components/Header/HeaderBack';
import PickerItem from '../../components/Picker/PickerItem'; import PickerItem from '../../components/Picker/PickerItem';
import I18n from '../../helper/i18/i18n'; import I18n from '../../helper/i18/i18n';
import AppText from '../../components/AppText'; import AppText from '../../components/AppText';
import TextField from '../../components/Input/TextField'; import {getFontXD, HEIGHTXD, toPriceVnd, WIDTHXD} from '../../Config/Functions';
import {getFontXD, HEIGHTXD, WIDTHXD} from '../../Config/Functions';
import R from '../../assets/R'; import R from '../../assets/R';
import Icon from 'react-native-vector-icons/FontAwesome'; import {getUnitList} from '../../apis/Functions/Transaction';
import {showAlert, TYPE} from '../../components/DropdownAlert';
const dataType = [ import {hideLoading, showLoading} from '../../actions/loadingAction';
{ import {connect} from 'react-redux';
value: '0',
name: 'KG',
},
{
value: '1',
name: 'Pound',
},
];
const ConvertUnit = (props) => { const ConvertUnit = (props) => {
const [typeOne, setTypeOne] = useState(); const [fromUnitList, setFromUnitList] = useState([]);
const [typeTwo, setTypeTwo] = useState(); const [toUnitList, setToUnitList] = useState([]);
const [valueOne, setValueOne] = useState(); const [toUnit, setToUnit] = useState();
const [valueTwo, setValueTwo] = useState(); const [fromUnit, setFromUnit] = useState();
const [result, setResult] = useState(); const [number, setNumber] = useState(null);
const [rateItem, setRateItem] = useState({
const onClick = () => { value_one: 0.025000000373,
console.log('Heloo', typeOne, typeTwo, valueOne, valueTwo); value_two: 0,
}; name: 'Kg,',
});
return ( const [result, setResult] = useState();
<View style={{flex: 1}}> useEffect(() => {
<HeaderBack title={'ConvertUnit'} /> getDataUnit();
<View style={{flex: 1, paddingTop: 20, paddingHorizontal: 20}}> }, []);
<AppText style={styles.txtTitle} i18nKey={'Count'} />
<View style={styles.Item}>
<View style={styles.wrap}>
<TextInput
onChangeText={(val) => setValueOne(val)}
keyboardType={'number-pad'}
style={styles.wrapInput}
maxLength={12}
/>
</View>
</View>
<View style={styles.Item}> useEffect(() => {
<View style={styles.wrap}> calcultorResult();
<PickerItem }, [number, fromUnit, toUnit]);
width={WIDTHXD(400)}
data={dataType} const getDataUnit = async () => {
onValueChange={(value, items) => { props.showLoading();
setTypeTwo(items); const res = await getUnitList({
}} platform: Platform.OS,
/> });
<TouchableOpacity> if (res.status == 200 && res.data.code == 200) {
<Icon name={'exchange'} size={30} color={R.colors.black} /> setFromUnitList(res.data.data);
</TouchableOpacity> setFromUnit(res.data.data[0]);
onChangeFromUnit('', res.data.data[0])
<PickerItem } else {
width={WIDTHXD(400)} showAlert(TYPE.ERROR, I18n.t('Notification'), I18n.t('Can_not_get_data'));
data={dataType} }
onValueChange={(value, items) => { props.hideLoading();
setTypeOne(items); };
}}
/> const onChangeNumber = (string) => {
</View> let number = string.toString().split(',').join('');
</View> setNumber(number);
};
<Text style={styles.txtResult}>Kết qu: {result}</Text> const onChangeFromUnit = (value, item) => {
setFromUnit(item);
let toUnit = [];
item.rates.map((rateItem) => {
toUnit.push({
id: rateItem.to_unit_id,
value: rateItem.to_unit.name,
name: rateItem.to_unit.name,
rate: rateItem.value_one > 0 ? rateItem.value_one : rateItem.value_two,
});
});
setToUnitList(toUnit);
setToUnit(toUnit[0]);
};
<View style={styles.footer}> const onChangeToUnit = (value, item) => {
<TouchableOpacity onPress={onClick} style={styles.btnContainer}> setToUnit(item);
<AppText style={styles.txtBtn} i18nKey={'Caculate'} /> if (number && number != '' && parseFloat(number) > 0) {
</TouchableOpacity> let result = parseFloat(number) * item.rate;
setResult(`${parseFloat(number)} ${fromUnit.name} = ${result} ${item.name}`);
}
};
const calcultorResult = () => {
if (number && number != '' && parseFloat(number) > 0) {
let result = parseFloat(number) * toUnit.rate;
setResult(`${parseFloat(number)} ${fromUnit.name} = ${result} ${toUnit.name}`);
} else {
setResult('')
}
};
return (
<View style={{flex: 1}}>
<HeaderBack title={'ConvertUnit'}/>
<View style={{flex: 1, paddingTop: 20, paddingHorizontal: 20}}>
<AppText style={styles.txtTitle} i18nKey={'Count'}/>
<View style={styles.Item}>
<View style={styles.wrap}>
<TextInput
onChangeText={(val) => onChangeNumber(val)}
keyboardType={'number-pad'}
style={styles.wrapInput}
maxLength={12}
value={toPriceVnd(number)}
/>
</View>
</View>
<View style={styles.Item}>
<View style={styles.wrap}>
<PickerItem
width={WIDTHXD(480)}
data={fromUnitList}
defaultValue={fromUnit?.name}
value={fromUnit?.name}
onValueChange={(value, item) => {
onChangeFromUnit(value, item);
}}
/>
{/*<TouchableOpacity>*/}
{/* <Icon name={'exchange'} size={30} color={R.colors.black} />*/}
{/*</TouchableOpacity>*/}
<PickerItem
width={WIDTHXD(480)}
data={toUnitList}
defaultValue={toUnit?.name}
value={toUnit?.name}
onValueChange={(value, item) => {
onChangeToUnit(value, item);
}}
/>
</View>
</View>
<Text style={styles.txtResult}>{result}</Text>
</View>
</View> </View>
</View> );
</View>
);
}; };
const styles = StyleSheet.create({ const styles = StyleSheet.create({
txtTitle: { txtTitle: {
fontSize: getFontXD(42), fontSize: getFontXD(42),
color: R.colors.color777, color: R.colors.color777,
marginBottom: 5, marginBottom: 5,
}, },
note: { note: {
fontSize: getFontXD(36), fontSize: getFontXD(36),
fontStyle: 'italic', fontStyle: 'italic',
marginTop: 10, marginTop: 10,
}, },
row: { row: {
height: HEIGHTXD(109), height: HEIGHTXD(109),
width: '80%', width: '80%',
justifyContent: 'space-between', justifyContent: 'space-between',
marginVertical: 5, marginVertical: 5,
paddingHorizontal: 10, paddingHorizontal: 10,
}, },
footer: { footer: {
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
marginTop: 40, marginTop: 40,
}, },
btnContainer: { btnContainer: {
width: WIDTHXD(428), width: WIDTHXD(428),
height: HEIGHTXD(120), height: HEIGHTXD(120),
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
backgroundColor: R.colors.main, backgroundColor: R.colors.main,
borderRadius: 10, borderRadius: 10,
}, },
txtBtn: { txtBtn: {
fontSize: getFontXD(48), fontSize: getFontXD(48),
color: R.colors.white, color: R.colors.white,
fontWeight: '600', fontWeight: '600',
}, },
wrapInput: { wrapInput: {
width: '100%', width: '100%',
backgroundColor: R.colors.white, backgroundColor: R.colors.white,
height: HEIGHTXD(109), height: HEIGHTXD(109),
fontSize: getFontXD(42), fontSize: getFontXD(42),
borderRadius: 5, borderRadius: 5,
paddingHorizontal: 10, paddingHorizontal: 10,
shadowColor: '#000', shadowColor: '#000',
shadowOffset: { shadowOffset: {
width: 0, width: 0,
height: 1, height: 1,
},
shadowOpacity: 0.2,
shadowRadius: 1.41,
elevation: 2,
},
wrap: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
},
Item: {
marginBottom: 20,
},
txtNote: {
fontSize: getFontXD(36),
textAlign: 'right',
marginTop: 10,
},
txtResult: {
fontSize: getFontXD(52),
color: R.colors.black,
fontWeight: '600',
textAlign: 'center',
marginTop: 20,
}, },
shadowOpacity: 0.2,
shadowRadius: 1.41,
elevation: 2,
},
wrap: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
},
Item: {
marginBottom: 20,
},
txtNote: {
fontSize: getFontXD(36),
textAlign: 'right',
marginTop: 10,
},
txtResult: {
fontSize: getFontXD(52),
color: R.colors.black,
fontWeight: '600',
textAlign: 'center',
marginTop: 20,
},
}); });
export default ConvertUnit; const mapStateToProps = (state) => {
return {};
};
export default connect(mapStateToProps, {
showLoading,
hideLoading,
})(ConvertUnit);
...@@ -41,7 +41,7 @@ const ExchangeRate = (props) => { ...@@ -41,7 +41,7 @@ const ExchangeRate = (props) => {
if (res.status == 200 && res.data.code == 200) { if (res.status == 200 && res.data.code == 200) {
setDataProduct(res.data.data); setDataProduct(res.data.data);
} else { } else {
showAlert(TYPE.ERROR, I18n.t('Notification', I18n.t('Can_not_get_data'))); showAlert(TYPE.ERROR, I18n.t('Notification'), I18n.t('Can_not_get_data'));
} }
}; };
......
...@@ -26,3 +26,8 @@ export const getListExchangeRate = async (body) => ...@@ -26,3 +26,8 @@ export const getListExchangeRate = async (body) =>
GetData(url.urlGetListExchangeRate, body) GetData(url.urlGetListExchangeRate, body)
.then((res) => res) .then((res) => res)
.catch((err) => err); .catch((err) => err);
export const getUnitList = async (body) =>
GetData(url.urlGetUnitList, body)
.then((res) => res)
.catch((err) => err);
...@@ -57,4 +57,6 @@ export default { ...@@ -57,4 +57,6 @@ export default {
urlProfitLost: root + 'api/v1/customers/calculate-profit', urlProfitLost: root + 'api/v1/customers/calculate-profit',
urlGetListExchangeRate: root + 'api/v1/customers/get-list-exchange-rate', urlGetListExchangeRate: root + 'api/v1/customers/get-list-exchange-rate',
urlGetUnitList: `${root}api/v1/customers/get-list-unit`,
}; };
...@@ -18,7 +18,7 @@ import Test from '../Screens/NewFeed/Test'; ...@@ -18,7 +18,7 @@ import Test from '../Screens/NewFeed/Test';
import {useNavigation} from '@react-navigation/native'; import {useNavigation} from '@react-navigation/native';
import Transaction from '../Screens/Transaction/Transaction'; import Transaction from '../Screens/Transaction/Transaction';
import {AccountVerification, PACKETCQG} from '../routers/ScreenNames'; import {AccountVerification, PACKETCQG} from '../routers/ScreenNames';
import I18n from '../helper/i18/i18n'; import I18n, {setLocation} from '../helper/i18/i18n';
import {changeLanguage} from '../actions/language'; import {changeLanguage} from '../actions/language';
import KEY from '../assets/AsynStorage'; import KEY from '../assets/AsynStorage';
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
...@@ -77,6 +77,7 @@ const TabNavigator = (props) => { ...@@ -77,6 +77,7 @@ const TabNavigator = (props) => {
const setInitLanguage = async () => { const setInitLanguage = async () => {
const laguage = await AsyncStorage.getItem(KEY.LANGUAGE); const laguage = await AsyncStorage.getItem(KEY.LANGUAGE);
if (laguage) props.changeLanguage(laguage); if (laguage) props.changeLanguage(laguage);
setLocation(I18n, laguage);
}; };
const showPopUp = () => { const showPopUp = () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment