index.js
3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import React, { Component } from 'react'
import {
ScrollView,
View,
Text
} from 'react-native'
import { StackActions } from 'react-navigation'
import { SearchBar, ListItem, Button } from 'react-native-elements'
import { connect } from 'react-redux'
import { map, merge } from 'ramda'
import css from './style'
import DefaultIndicator from '../../components/DefaultIndicator'
import Pagination from '../../components/Pagination'
import { buscarInstituciones, fetchInstituciones } from '../../redux/actions/instituciones'
import { seleccionarInstitucion } from '../../redux/actions/nuevaSolicitud'
const navegarSolicitud = (self, institucion) => {
self.props.seleccionar(institucion)
const pushAction = StackActions.push({
routeName: 'NuevaSolicitud'
})
self.props.navigation.dispatch(pushAction)
}
class SeleccionarInstitucion extends Component {
static navigationOptions = ({ navigation }) => ({
title: 'Nueva Solicitud',
headerStyle: css.headerStyle,
headerTitleStyle: css.headerTitleStyle,
headerLeft:
<Button
icon={{ name: 'menu', size: 27, color: 'white' }}
buttonStyle={{ backgroundColor: 'transparent' }}
onPress={() => navigation.toggleDrawer()}
/>
})
componentDidMount() {
this.props.cargar(this.props.token)
}
render() {
const { token, buscar, busqueda } = this.props
const self = this
const items = map((institucion) => (
<ListItem
key={institucion.id}
title={institucion.nombre}
onPress={() => navegarSolicitud(self, institucion)}
/>
))
const pagination = (show) => {
if (show) {
return (
<Pagination
next={() => buscar(token, merge(busqueda, { page: busqueda.page + 1 }))}
previous={() => buscar(token, merge(busqueda, { page: busqueda.page - 1 }))}
page={busqueda.page}
totalPages={this.props.pages.totalPages}
totalCount={this.props.pages.totalCount}
/>)
}
}
const spinner = (<DefaultIndicator />)
return (
<ScrollView style={css.pane} contentContainerStyle={css.contentContainer} >
<Text style={css.label}>A qué institución le solicitará información?</Text>
<SearchBar
lightTheme
onChangeText={(text) => buscar(token, { page: 1, text })}
icon={{ type: 'font-awesome', name: 'search' }}
placeholder='Buscar Institucion'
/>
<View>
{this.props.loading ? spinner : items(this.props.instituciones)}
{pagination(!this.props.loading)}
</View>
</ScrollView>)
}
}
const mapStateToProps = (state) => ({
token: state.autenticacion.token,
loading: state.instituciones.loading,
instituciones: state.instituciones.data,
pages: state.instituciones.pages,
busqueda: state.instituciones.busqueda
})
const mapDispatchToProps = (dispatch) => ({
buscar: (token, parametros) => dispatch(buscarInstituciones(token, parametros)),
cargar: (token) => dispatch(fetchInstituciones(token, { page: 1 })),
seleccionar: (token) => dispatch(seleccionarInstitucion(token, { page: 1 })),
})
export default connect(mapStateToProps, mapDispatchToProps)(SeleccionarInstitucion)