Guest User

Untitled

a guest
Nov 24th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.53 KB | None | 0 0
  1. import React from 'react';
  2. import {
  3. StyleSheet,
  4. Text,
  5. View,
  6. TouchableOpacity,
  7. ScrollView,
  8. ActivityIndicator,
  9. } from 'react-native';
  10. import { Actions } from 'react-native-router-flux';
  11. import PropTypes from 'prop-types';
  12. import PopupDialog, {
  13. DialogTitle,
  14. DialogButton,
  15. } from 'react-native-popup-dialog';
  16.  
  17. const styles = StyleSheet.create({
  18. principal: {
  19. flex: 1,
  20. },
  21.  
  22. content: {
  23. flex: 1,
  24. paddingTop: 6,
  25. backgroundColor: 'white',
  26. },
  27.  
  28. listSchedule: {
  29. flex: 1,
  30. marginHorizontal: 15,
  31. marginVertical: 10,
  32. borderColor: 'black',
  33. borderWidth: 1,
  34. borderRadius: 3,
  35. backgroundColor: '#FAFAFA',
  36. justifyContent: 'space-between',
  37. flexDirection: 'row',
  38. alignItems: 'center',
  39. },
  40.  
  41. textBox: {
  42. paddingLeft: 4,
  43. justifyContent: 'flex-start',
  44. },
  45.  
  46. text: {
  47. fontSize: 15,
  48. paddingVertical: 2,
  49. },
  50.  
  51. buttonBox: {
  52. borderColor: 'black',
  53. borderWidth: 0.8,
  54. borderRadius: 7,
  55. backgroundColor: '#4cd964',
  56. padding: 7,
  57. marginBottom: 20,
  58. justifyContent: 'center',
  59. marginRight: 20,
  60. },
  61.  
  62. buttonInvitees: {
  63. borderColor: 'black',
  64. borderWidth: 0.8,
  65. borderRadius: 7,
  66. backgroundColor: 'white',
  67. padding: 8,
  68. justifyContent: 'center',
  69. marginRight: 20,
  70. },
  71.  
  72. buttonText: {
  73. fontSize: 12,
  74. textAlign: 'center',
  75. },
  76.  
  77. footerPopUp: {
  78. backgroundColor: '#F9F9FB',
  79. borderColor: '#DAD9DC',
  80. borderTopWidth: 0.5,
  81. borderBottomLeftRadius: 8,
  82. borderBottomRightRadius: 8,
  83. flexDirection: 'row',
  84. alignItems: 'center',
  85. justifyContent: 'center',
  86. },
  87. });
  88.  
  89. class StartPendingInspection extends React.Component {
  90. constructor(props) {
  91. super(props);
  92.  
  93. this.state = {
  94. invitees: [],
  95. };
  96. }
  97.  
  98. componentWillMount() {
  99. this.props.asyncGetSchedule(this.props.counselor);
  100. this.props.asyncGetCounselorFromGroup(this.props.counselor.profile.CAE,
  101. this.props.counselor.profile.cpf);
  102. }
  103.  
  104. mountListOfInvitees(listOfInvitees) {
  105. this.setState({ invitees: [] });
  106.  
  107. this.props.listOfCounselorsInAGroup.map(counselor => (
  108. listOfInvitees[counselor.nuvemCode] !== undefined ?
  109. this.setState({ invitees: [...this.state.invitees, counselor] })
  110. : null
  111. ));
  112. this.popupDialog.show();
  113. }
  114.  
  115. verification(listOfInvitees) {
  116. if (listOfInvitees[this.props.counselor.nuvemCode] === undefined) {
  117. return (
  118. <View style={[styles.buttonBox, { backgroundColor: '#ff3b30' }]}>
  119. <TouchableOpacity
  120. disabled
  121. >
  122. <Text style={styles.buttonText}>NÃO CONVIDADO</Text>
  123. </TouchableOpacity>
  124. </View>
  125. );
  126. } else if (!listOfInvitees[this.props.counselor.nuvemCode].confirmed) {
  127. return (
  128. <View style={[styles.buttonBox, { backgroundColor: '#ffcc00' }]}>
  129. <TouchableOpacity
  130. disabled
  131. >
  132. <Text style={styles.buttonText}>NÃO CONFIRMOU</Text>
  133. </TouchableOpacity>
  134. </View>
  135. );
  136. }
  137. return (
  138. <View style={styles.buttonBox}>
  139. <TouchableOpacity
  140. onPress={() => Actions.mainReportsScreen()}
  141. >
  142. <Text style={styles.buttonText}>FISCALIZAR</Text>
  143. </TouchableOpacity>
  144. </View>
  145. );
  146. }
  147.  
  148. arrayScheduleList() {
  149. if (this.props.listOfPendingScheduleInAGroup.length === 0) {
  150. return (
  151. <ActivityIndicator style={{ marginTop: 50 }} size="large" color="#FF9500" />
  152. );
  153. }
  154. return (
  155. this.props.listOfPendingScheduleInAGroup.map(schedule => (
  156. <View style={styles.listSchedule}>
  157. <View style={styles.textBox}>
  158. <Text style={styles.text}>
  159. <Text style={{ fontWeight: 'bold' }}>Escola: </Text>
  160. {schedule.schoolName}
  161. </Text>
  162. <Text style={styles.text}>
  163. <Text style={{ fontWeight: 'bold' }}>Data: </Text>
  164. {schedule.date}
  165. </Text>
  166. <Text style={styles.text}>
  167. <Text style={{ fontWeight: 'bold' }}>Horário: </Text>
  168. {schedule.time}
  169. </Text>
  170. {
  171. schedule.invitedAgent ? (
  172. <Text style={styles.text}>
  173. <Text style={{ fontWeight: 'bold' }}>Um agente foi convidado</Text>
  174. </Text>
  175. ) :
  176. <Text style={styles.text}>
  177. <Text style={{ fontWeight: 'bold' }}>Agente não convidado</Text>
  178. </Text>
  179. }
  180. <Text style={styles.text}>
  181. <Text style={{ fontWeight: 'bold' }}>Número de convidados: </Text>
  182. {Object.keys(schedule.listOfInvitees).length}
  183. </Text>
  184. </View>
  185. <View>
  186. {this.verification(schedule.listOfInvitees)}
  187. <View style={styles.buttonInvitees}>
  188. <TouchableOpacity
  189. onPress={() => this.mountListOfInvitees(schedule.listOfInvitees)}
  190. >
  191. <Text style={styles.buttonText}>CONVIDADOS</Text>
  192. </TouchableOpacity>
  193. </View>
  194. </View>
  195. </View>
  196. ))
  197. );
  198. }
  199. render() {
  200. console.log(this.state.invitees);
  201. return (
  202. <View style={styles.principal}>
  203. <PopupDialog
  204. ref={(popupDialog) => {
  205. this.popupDialog = popupDialog;
  206. }}
  207. dialogTitle={<DialogTitle title="Escolha quem deseja convidar" />}
  208. overlayPointerEvents="none"
  209. height="80%"
  210. width="85%"
  211. actions={[
  212. <View style={styles.footerPopUp}>
  213. <DialogButton
  214. buttonStyle={styles.dialogButtonStyle}
  215. text="OK"
  216. onPress={() => this.popupDialog.dismiss()}
  217. key="dialogButton1"
  218. />
  219. </View>,
  220. ]}
  221. >
  222. <ScrollView key="showInviteCounselorList">
  223. <Text>DASDA</Text>
  224. </ScrollView>
  225. </PopupDialog>
  226.  
  227. <ScrollView style={styles.content}>
  228. {this.arrayScheduleList()}
  229. </ScrollView>
  230. </View>
  231. );
  232. }
  233. }
  234.  
  235. const { shape, func } = PropTypes;
  236.  
  237. StartPendingInspection.propTypes = {
  238. asyncGetCounselorFromGroup: func.isRequired,
  239. asyncGetSchedule: func.isRequired,
  240. listOfPendingScheduleInAGroup: PropTypes.arrayOf(PropTypes.shape({
  241. codSchool: PropTypes.number,
  242. date: PropTypes.string,
  243. time: PropTypes.string,
  244. })).isRequired,
  245. counselor: shape({
  246. }).isRequired,
  247. listOfCounselorsInAGroup: PropTypes.arrayOf(PropTypes.shape({
  248. name: PropTypes.string,
  249. cpf: PropTypes.string,
  250. phone: PropTypes.string,
  251. })).isRequired,
  252. };
  253.  
  254. export default StartPendingInspection;
Add Comment
Please, Sign In to add comment