Commit bc0c8dc0 by Giang Tran

connect api

parent 236c9540
...@@ -16,78 +16,42 @@ import TextField from '../../components/Input/TextField'; ...@@ -16,78 +16,42 @@ import TextField from '../../components/Input/TextField';
import {getFontXD, HEIGHTXD, toPriceVnd, WIDTHXD} from '../../Config/Functions'; import {getFontXD, HEIGHTXD, toPriceVnd, WIDTHXD} from '../../Config/Functions';
import R from '../../assets/R'; import R from '../../assets/R';
import {showAlert, TYPE} from '../../components/DropdownAlert'; import {showAlert, TYPE} from '../../components/DropdownAlert';
import {getTransactionListByCategory} from '../../apis/Functions/Transaction'; import {getListExchangeRate} from '../../apis/Functions/Transaction';
import {showLoading, hideLoading} from '../../actions/loadingAction';
const DATA = [ import {connect} from 'react-redux';
{
id: 1,
name: 'Đậu tương',
value: 0.36744,
},
{
id: 2,
name: 'Khô đậu tương',
value: 1.1023,
},
{
id: 3,
name: 'Dầu đậu tương',
value: 22.0462,
},
{
id: 4,
name: 'Ngô',
value: 0.39368,
},
{
id: 5,
name: 'Lúa mỳ',
value: 0.36744,
},
{
id: 6,
name: 'Cà phê arabica',
value: 22.0462,
},
{
id: 7,
name: 'Cà phê Robusta',
value: 1,
},
{
id: 8,
name: 'Ca cao',
value: 1,
},
{
id: 9,
name: 'Bông',
value: 22.0462,
},
{
id: 10,
name: 'Đường',
value: 22.0462,
},
{
id: 11,
name: 'Cao su',
value: 9.4,
},
];
const ExchangeRate = (props) => { const ExchangeRate = (props) => {
const [product, setProduct] = useState(); const [product, setProduct] = useState();
const [priceExchange, setPriceExchange] = useState(); const [priceExchange, setPriceExchange] = useState();
const [usdTan, setUsdTan] = useState(); const [usdTan, setUsdTan] = useState();
const [dataProduct, setDataProduct] = useState([]);
useEffect(() => {
getProductData();
}, []);
const getProductData = async () => {
props.showLoading();
const res = await getListExchangeRate({
platform: Platform.OS,
page_size: 1000,
page_index: 1,
});
props.hideLoading();
if (res.status == 200 && res.data.code == 200) {
setDataProduct(res.data.data);
} else {
showAlert(TYPE.ERROR, I18n.t('Notification', I18n.t('Can_not_get_data')));
}
};
useEffect(() => { useEffect(() => {
caculator(); caculator();
}, [product, priceExchange]); }, [product, priceExchange]);
const caculator = () => { const caculator = () => {
if (product && priceExchange) { if (product && priceExchange) {
const total = priceExchange * product.value; const total = priceExchange * product.exchange_rate;
setUsdTan(total + ''); setUsdTan(total + '');
} else if (!priceExchange) setUsdTan(''); } else if (!priceExchange) setUsdTan('');
}; };
...@@ -99,7 +63,7 @@ const ExchangeRate = (props) => { ...@@ -99,7 +63,7 @@ const ExchangeRate = (props) => {
<AppText style={styles.txtTitle} i18nKey={'Product'} /> <AppText style={styles.txtTitle} i18nKey={'Product'} />
<PickerItem <PickerItem
width={width - 20} width={width - 20}
data={DATA} data={dataProduct}
onValueChange={(value, items) => { onValueChange={(value, items) => {
setProduct(items); setProduct(items);
}} }}
...@@ -194,4 +158,12 @@ const styles = StyleSheet.create({ ...@@ -194,4 +158,12 @@ const styles = StyleSheet.create({
marginTop: 10, marginTop: 10,
}, },
}); });
export default ExchangeRate;
const mapStateToProps = (state) => {
return {
user: state.userReducer,
};
};
export default connect(mapStateToProps, {showLoading, hideLoading})(
ExchangeRate,
);
...@@ -21,3 +21,8 @@ export const getProfitLost = async (body) => ...@@ -21,3 +21,8 @@ export const getProfitLost = async (body) =>
PostData(url.urlProfitLost, body) PostData(url.urlProfitLost, body)
.then((res) => res) .then((res) => res)
.catch((err) => err); .catch((err) => err);
export const getListExchangeRate = async (body) =>
GetData(url.urlGetListExchangeRate, body)
.then((res) => res)
.catch((err) => err);
...@@ -55,4 +55,6 @@ export default { ...@@ -55,4 +55,6 @@ export default {
urlSendRequest: root + 'api/v1/customers/send-request', urlSendRequest: root + 'api/v1/customers/send-request',
urlProfitLost: root + 'api/v1/customers/calculate-profit', urlProfitLost: root + 'api/v1/customers/calculate-profit',
urlGetListExchangeRate: root + 'api/v1/customers/get-list-exchange-rate',
}; };
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