MethodPay.js 1.19 KB
Newer Older
Giang Tran committed
1
import React, {useState, useEffect} from 'react';
Giang Tran committed
2 3

import MethodPayView from './MethodPayView';
Giang Tran committed
4 5
import {getListWidthDraw} from '../../apis/Functions/Widthdraw';
import {useNavigation} from '@react-navigation/native';
Giang Tran committed
6
import I18n from '../../helper/i18/i18n';
Giang Tran committed
7
import {showAlert, TYPE} from '../../components/DropdownAlert';
Giang Tran committed
8 9

const MethodPay = (props) => {
Giang Tran committed
10
  const [data, setData] = useState([]);
Giang Tran committed
11
  const [isRefresh, setRefresh] = useState(false);
Giang Tran committed
12
  const navigation = useNavigation();
Giang Tran committed
13 14

  useEffect(() => {
Giang Tran committed
15 16 17 18 19 20
    const unsubscribe = navigation.addListener('focus', () => {
      getData();
    });

    return unsubscribe;
  }, [navigation]);
Giang Tran committed
21

Giang Tran committed
22 23 24
  const onRefresh = () => {
    getData();
  };
Giang Tran committed
25 26

  const getData = async () => {
Giang Tran committed
27
    setRefresh(true);
Giang Tran committed
28 29 30
    const res = await getListWidthDraw({
      platform: Platform.OS,
    });
Giang Tran committed
31
    setRefresh(false);
Giang Tran committed
32 33
    if (res.data.code == 200 && res.data.data) {
      setData(res.data.data);
Giang Tran committed
34
      console.log(res.data.data);
Giang Tran committed
35
    } else {
Giang Tran committed
36
      showAlert(TYPE.ERROR, I18n.t('Notification'), I18n.t('Can_not_get_data'));
Giang Tran committed
37 38 39
    }
  };

Giang Tran committed
40 41 42 43 44 45 46
  return (
    <MethodPayView
      onRefresh={onRefresh}
      listMethod={data}
      isRefresh={isRefresh}
    />
  );
Giang Tran committed
47 48 49
};

export default MethodPay;