index.js
3.42 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import 'moment/locale/es'
import React, { Component } from 'react'
import {
View,
Text,
SectionList
} from 'react-native'
import { connect } from 'react-redux'
import { StackActions } from 'react-navigation'
import { ListItem, Button } from 'react-native-elements'
import {
verDetalleSolicitud,
cambiarPaginaSolicitud,
cambiarBusquedaSolicitud
} from '../../redux/actions/solicitudes'
import DefaultIndicator from '../../components/DefaultIndicator'
import Pagination from '../../components/Pagination'
import css from './style'
// AIP Movil
const navegarSolicitud = (self, solicitud) => {
self.props.verDetalleSolicitud(solicitud)
const pushAction = StackActions.push({
routeName: 'DetalleSolicitud',
params: solicitud
})
self.props.navigation.dispatch(pushAction)
}
const renderSectionHeader = ({ section }) =>
(<Text style={css.sectionHeader}>
{section.title}
</Text>)
const renderItem = function (self) {
return ({ item }) => (
<ListItem
key={item.id}
title={item.titulo}
subtitle={`# ${item.id}`}
badge={item.formato ? { value: item.formato.nombre } : null}
titleStyle={{ fontWeight: 'bold' }}
subtitleStyle={{ fontWeight: 'normal' }}
onPress={() => navegarSolicitud(self, item)}
/>
)
}
class MisSolicitudes extends Component {
static navigationOptions = ({ navigation }) => ({
title: 'Mis solicitudes',
headerStyle: css.headerStyle,
headerTitleStyle: css.headerTitleStyle,
headerLeft:
<Button
icon={{ name: 'menu', size: 27, color: 'white' }}
buttonStyle={{ backgroundColor: 'transparent' }}
onPress={() => navigation.toggleDrawer()}
/>
});
componentWillMount() {
this.props.cambiarPaginaSolicitud({
by_usuario: this.props.usuario.datos.mail,
page: 1,
by_titulo: null
})
}
render() {
const busqueda = this.props.busqueda
const self = this
const pagination = (show) => {
if (show) {
return (
<Pagination
next={() => self.props.cambiarPaginaSolicitud({ page: busqueda.page + 1 })}
previous={() => self.props.cambiarPaginaSolicitud({ page: busqueda.page - 1 })}
page={busqueda.page}
totalPages={this.props.pages.totalPages}
totalCount={this.props.pages.totalCount}
/>)
}
}
const spinner = <DefaultIndicator />
const section = (
<SectionList
sections={this.props.tabla}
renderItem={renderItem(this)}
renderSectionHeader={renderSectionHeader}
keyExtractor={(item, index) => index}
ListFooterComponent={() => pagination(!self.props.loading)}
/>)
return (
<View style={[css.pane, css.container]}>
{this.props.loading ? spinner : section}
</View>
)
}
}
const mapStateToProps = (state) => ({
token: state.autenticacion.token,
loading: state.solicitudes.loading,
tabla: [state.solicitudes.pendientes, state.solicitudes.finalizadas],
usuario: state.usuario,
busqueda: state.solicitudes.busqueda,
pages: state.solicitudes.pages,
})
const mapDispatchToProps = dispatch => ({
cambiarBusquedaSolicitud: (params) => dispatch(cambiarBusquedaSolicitud(params)),
verDetalleSolicitud: (solicitud) => dispatch(verDetalleSolicitud(solicitud)),
cambiarPaginaSolicitud: (busqueda) => dispatch(cambiarPaginaSolicitud(busqueda))
})
export default connect(mapStateToProps, mapDispatchToProps)(MisSolicitudes)