Advertisement
Eulis

sendorder

Apr 17th, 2020
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. import React, { useState, useCallback, useEffect } from 'react';
  2. import { ScrollView, Text, Alert } from 'react-native';
  3. import PropTypes from 'prop-types';
  4. import HTML from 'react-native-render-html';
  5. import api from '~/services/api';
  6.  
  7. import CheckBox from './CheckBox';
  8. import Header from '~/components/Header';
  9. import {
  10. Container,
  11. PaymentStatus,
  12. Title,
  13. StyledButton,
  14. SubmitButton,
  15. PaymentText,
  16. Library,
  17. Option,
  18. OptionTitle,
  19. LibraryTitle,
  20. Document,
  21. CloseButton,
  22. ButtonText,
  23. } from './styles';
  24. import DocLibrary from '~/components/DocLibrary';
  25.  
  26. export default function SendOrder({ navigation }) {
  27. const [agreeTerms, setAgreeTerms] = useState(false);
  28. const [recomendationData, setRecomendationData] = useState([]);
  29. const [userInvestmentThesis, setUserInvestmentThesis] = useState('');
  30. const [fileToken, setFileToken] = useState('');
  31. const [showModal, setShowModal] = useState(false);
  32. const [showDoc, setShowDoc] = useState(false);
  33. const [document, setDocument] = useState([]);
  34. const [requestDone, setRequestDone] = useState(0);
  35. const [loading, setLoading] = useState(false);
  36.  
  37. const htmlContent = document;
  38.  
  39. const getRecomendationRequest = useCallback(async () => {
  40. const {
  41. data: { data },
  42. } = await api.get('robotadvisory/recomendation/get', {});
  43. setRecomendationData(data);
  44. setUserInvestmentThesis(data.file_token);
  45. }, []);
  46.  
  47. const setRecomendantionRequest = useCallback(async () => {
  48. // navigation.navigate('LaunchpadConfig');
  49. // await api.post('robotadvisory/informedconsent', {
  50. // recomendation_token: recomendationData.token,
  51. // });
  52. // console.log('tk', recomendationData.token);
  53. navigation.navigate('LaunchpadConfig');
  54. }, [navigation, recomendationData]);
  55.  
  56. const getDocument = useCallback(async () => {
  57. try {
  58. setLoading(true);
  59. const { data } = await api.post('accounts/files/documents', {
  60. token: fileToken,
  61. });
  62. setDocument(data);
  63. setLoading(false);
  64. } catch (error) {
  65. setLoading(false);
  66. if (error != null && error.response != null) {
  67. Alert.alert('Token expirado', 'É necessário fazer login novamente');
  68. setShowDoc(false);
  69. // navigation.navigate('Login');
  70. } else {
  71. Alert.alert('Ocorreu um erro, por favor tente novamente mais tarde!');
  72. }
  73. }
  74. }, [fileToken]);
  75.  
  76. useEffect(() => {
  77. if (requestDone < 1) {
  78. getRecomendationRequest();
  79. setRequestDone(requestDone + 1);
  80. }
  81. }, [getRecomendationRequest, recomendationData, requestDone]);
  82.  
  83. return (
  84. <>
  85. <Header navigation={navigation} />
  86. <PaymentStatus>
  87. <PaymentText>PAGAMENTO EFETUADO COM SUCESSO</PaymentText>
  88. </PaymentStatus>
  89. <Container>
  90. <Title>Tese de Investimento</Title>
  91. <StyledButton
  92. doc
  93. onPress={() => {
  94. setFileToken(userInvestmentThesis);
  95. setShowModal(true);
  96. }}
  97. >
  98. Abrir Documentos
  99. </StyledButton>
  100. <DocLibrary />
  101. {/* <Library isVisible={showModal} animationOutTiming={400}>
  102. <CloseButton lib onPress={() => setShowModal(false)}>
  103. <ButtonText lib>X</ButtonText>
  104. </CloseButton>
  105. <LibraryTitle>Biblioteca de Documentos</LibraryTitle>
  106. <Option
  107. onPress={() => {
  108. setShowDoc(true);
  109. setShowModal(false);
  110. getDocument();
  111. }}
  112. >
  113. <OptionTitle
  114. onPress={() => {
  115. setShowDoc(true);
  116. setShowModal(false);
  117. getDocument();
  118. }}
  119. >
  120. Teses de investimento
  121. </OptionTitle>
  122. </Option>
  123. </Library>
  124. <Document
  125. isVisible={showDoc}
  126. backdropTransitionInTiming={500}
  127. animationInTiming={200}
  128. >
  129. <CloseButton onPress={() => setShowDoc(false)}>
  130. <ButtonText>X</ButtonText>
  131. </CloseButton>
  132. <ScrollView>
  133. <HTML html={htmlContent} />
  134. </ScrollView>
  135. </Document> */}
  136. <CheckBox
  137. checked={agreeTerms}
  138. onPress={() => setAgreeTerms(!agreeTerms)}
  139. text="Concordo com a Tese de Investimento proposta"
  140. />
  141. <SubmitButton
  142. disable={!agreeTerms}
  143. onPress={() => setRecomendantionRequest()}
  144. >
  145. Submeter
  146. </SubmitButton>
  147. </Container>
  148. </>
  149. );
  150. }
  151.  
  152. SendOrder.propTypes = {
  153. navigation: PropTypes.oneOfType([PropTypes.object]).isRequired,
  154. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement