yosadade

MainApp.js

Jul 19th, 2020
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. import React, {useEffect, useState} from 'react';
  2. import {StyleSheet, View, ScrollView} from 'react-native';
  3. import {colors, getData} from '../../utils';
  4. import {
  5. List,
  6. Gap,
  7. HomeProfile,
  8. Loan,
  9. Header,
  10. StatusBar,
  11. } from '../../components';
  12. import Axios from 'axios';
  13. import {useSelector} from 'react-redux';
  14. import {Fire} from '../../config';
  15. import {showMessage} from 'react-native-flash-message';
  16.  
  17. const Dashboard = ({route, navigation}) => {
  18. const [dataLogin, setDataLogin] = useState({});
  19. const [dataHutang, setDataHutang] = useState({});
  20. const [dataCicilan, setDataCicilan] = useState([]);
  21.  
  22. const [profile, setProfile] = useState({
  23. displayName: '',
  24. email: '',
  25. });
  26.  
  27. useEffect(() => {
  28. getDataLogin();
  29. getDataHutang();
  30. getDataCicilan();
  31. getData('user').then(res => {
  32. setProfile(res);
  33. });
  34. }, []);
  35.  
  36. const getDataLogin = async () => {
  37. try {
  38. let formData = new FormData();
  39. formData.append('user', 'ngadimin');
  40. formData.append('pass', 'h4oejsgmQ#6ChYBtDb');
  41.  
  42. const httpReq = await Axios({
  43. headers: {
  44. Authorization:
  45. 'Basic dXNtYW5ydWJpYW50b3JvcW9kcnFvZHJiZWV3b293YToyNjM3NmVkeXV3OWUwcmkzNDl1ZA==',
  46. },
  47. method: 'post',
  48. url: 'http://api.tanpariba.co.id:8000/v4.0/account/login',
  49. data: formData,
  50. });
  51.  
  52. if (httpReq.data.data) {
  53. // console.log(httpReq.data.data);
  54. const data = httpReq.data.data;
  55. setDataLogin(data);
  56. console.log('setDataLogin:', data);
  57. // jalankan fungsi sukses login
  58. } else {
  59. console.log(httpReq.data);
  60. // jalankan fungsi error login
  61. }
  62. } catch (error) {
  63. // jalankan fungsi cath error
  64. console.log(error);
  65. }
  66. };
  67.  
  68. const getDataHutang = async () => {
  69. try {
  70. let formData = new FormData();
  71. formData.append('session', '470237778affea2393d37825de144ecb');
  72.  
  73. const httpReq = await Axios({
  74. headers: {
  75. Authorization:
  76. 'Basic dXNtYW5ydWJpYW50b3JvcW9kcnFvZHJiZWV3b293YToyNjM3NmVkeXV3OWUwcmkzNDl1ZA==',
  77. },
  78. method: 'post',
  79. url: 'http://api.tanpariba.co.id:8000/v4.0/page_mobile/dashboard',
  80. data: formData,
  81. });
  82.  
  83. if (httpReq.data.data_hutang) {
  84. console.log(httpReq.data.data_hutang);
  85. const data = httpReq.data.data_hutang;
  86. setDataHutang(data);
  87. // jalankan fungsi sukses login
  88. } else {
  89. console.log(httpReq);
  90. // jalankan fungsi error login
  91. }
  92. } catch (error) {
  93. // jalankan fungsi cath error
  94. console.log(error);
  95. }
  96. };
  97.  
  98. const getDataCicilan = async () => {
  99. try {
  100. let formData = new FormData();
  101. formData.append('session', '470237778affea2393d37825de144ecb');
  102.  
  103. const httpReq = await Axios({
  104. headers: {
  105. Authorization:
  106. 'Basic dXNtYW5ydWJpYW50b3JvcW9kcnFvZHJiZWV3b293YToyNjM3NmVkeXV3OWUwcmkzNDl1ZA==',
  107. },
  108. method: 'post',
  109. url: 'http://api.tanpariba.co.id:8000/v4.0/page_mobile/dashboard',
  110. data: formData,
  111. });
  112.  
  113. if (httpReq.data.data_cicilan) {
  114. // console.log(httpReq.data.data_cicilan);
  115. const data = httpReq.data.data_cicilan;
  116. const filterData = data.filter(el => el !== null);
  117. setDataCicilan(filterData);
  118. // jalankan fungsi sukses login
  119. } else {
  120. console.log(httpReq);
  121. // jalankan fungsi error login
  122. }
  123. } catch (error) {
  124. // jalankan fungsi cath error
  125. console.log(error);
  126. }
  127. };
  128.  
  129. const stateGlobal = useSelector(state => state);
  130.  
  131. const signOut = () => {
  132. Fire.auth()
  133. .signOut()
  134. .then(() => {
  135. console.log('success sign out');
  136. navigation.replace('GetStarted');
  137. })
  138. .catch(err => {
  139. showMessage({
  140. message: err.message,
  141. type: 'default',
  142. backgroundColor: colors.background.tertiary,
  143. color: colors.text.secondary,
  144. });
  145. });
  146. };
  147.  
  148. const {displayName, email} = route.params;
  149. console.log('displayName', displayName);
  150. return (
  151. <View style={styles.page}>
  152. <StatusBar type="secondary" background={colors.background.secondary} />
  153. <Header type="headerIconOnly" onPressRight={signOut} />
  154. {/* <HomeProfile name={dataLogin.display_name} email={dataLogin.user_email} /> */}
  155. <HomeProfile name="Admin" email="admintanpariba@gmail.com" />
  156. <Loan sisaHutang="7 gr" jatuhTempo="31-12-2020" />
  157. <View style={styles.listLoan}>
  158. <ScrollView showsVerticalScrollIndicator={false}>
  159. <Gap height={10} />
  160. {/* <List
  161. type="diagram"
  162. sudah_bayar={dataHutang.sudah_bayar}
  163. total_hutang={dataHutang.total_hutang}
  164. persen_bayar={dataHutang.persen_bayar}
  165. /> */}
  166. <List
  167. type="diagram"
  168. sudah_bayar="3 gr"
  169. total_hutang="10 gr"
  170. persen_bayar="30%"
  171. />
  172. {stateGlobal.cicilans.map((item, index) => {
  173. return (
  174. <List
  175. key={index}
  176. cicilan={item.ke}
  177. bayar={item.jml}
  178. waktu={item.tgl_nyicil}
  179. sisa={item.sisa_hutang}
  180. sudah_bayar={item.sudah_bayar}
  181. />
  182. );
  183. })}
  184. </ScrollView>
  185. </View>
  186. </View>
  187. );
  188. };
  189.  
  190. export default Dashboard;
  191.  
  192. const styles = StyleSheet.create({
  193. page: {
  194. flex: 1,
  195. backgroundColor: colors.background.primary,
  196. },
  197. listLoan: {
  198. flex: 1,
  199. borderTopLeftRadius: 30,
  200. borderTopRightRadius: 30,
  201. marginTop: -25,
  202. paddingVertical: 14,
  203. backgroundColor: colors.background.primary,
  204. alignItems: 'center',
  205. },
  206. });
Add Comment
Please, Sign In to add comment