Commit bc0c8dc0 by Giang Tran

connect api

parent 236c9540
......@@ -16,78 +16,42 @@ import TextField from '../../components/Input/TextField';
import {getFontXD, HEIGHTXD, toPriceVnd, WIDTHXD} from '../../Config/Functions';
import R from '../../assets/R';
import {showAlert, TYPE} from '../../components/DropdownAlert';
import {getTransactionListByCategory} from '../../apis/Functions/Transaction';
const DATA = [
{
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,
},
];
import {getListExchangeRate} from '../../apis/Functions/Transaction';
import {showLoading, hideLoading} from '../../actions/loadingAction';
import {connect} from 'react-redux';
const ExchangeRate = (props) => {
const [product, setProduct] = useState();
const [priceExchange, setPriceExchange] = 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(() => {
caculator();
}, [product, priceExchange]);
const caculator = () => {
if (product && priceExchange) {
const total = priceExchange * product.value;
const total = priceExchange * product.exchange_rate;
setUsdTan(total + '');
} else if (!priceExchange) setUsdTan('');
};
......@@ -99,7 +63,7 @@ const ExchangeRate = (props) => {
<AppText style={styles.txtTitle} i18nKey={'Product'} />
<PickerItem
width={width - 20}
data={DATA}
data={dataProduct}
onValueChange={(value, items) => {
setProduct(items);
}}
......@@ -194,4 +158,12 @@ const styles = StyleSheet.create({
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) =>
PostData(url.urlProfitLost, body)
.then((res) => res)
.catch((err) => err);
export const getListExchangeRate = async (body) =>
GetData(url.urlGetListExchangeRate, body)
.then((res) => res)
.catch((err) => err);
......@@ -55,4 +55,6 @@ export default {
urlSendRequest: root + 'api/v1/customers/send-request',
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