-
Notifications
You must be signed in to change notification settings - Fork 7
/
editCView.js
162 lines (142 loc) · 4.43 KB
/
editCView.js
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Component name: editCView
// This component will display the complaint details and edit access to Faculty
import React from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Button,
Text,
StatusBar,
} from 'react-native';
import axios from 'axios'
import RadioForm, { RadioButton, RadioButtonInput, RadioButtonLabel } from 'react-native-simple-radio-button';
var radio_props = [
{ label: 'submitted', value: 0 },
{ label: 'Processing', value: 1 },
{ label: 'closed', value: 2 }
];
// submitted, processing, closed
class editCView extends React.Component {
// This constructor function initialises the state's application status
constructor() {
super()
state = {
value: null
}
}
// This function will give the initial application status to the state
setStatus = () => {
this.setState(
{ value: this.props.navigation.getParam('status', 'status') }
)
}
// This function will change the application status as provided by the faculty
changeStatus = () => {
console.log('changestatus', this.state.value)
const idx = this.props.navigation.getParam('id', 'id')
let label = 'submitted'
if (this.state.value == 1) {
label = 'processing'
} else if (this.state.value == 2) {
label = 'closed'
}
const patchData = {
'status': label
}
const headers = {
'Authorization': 'Bearer ' + this.props.navigation.getParam('token', 'token')
}
axios({
method: 'PATCH',
url: 'https://201751025.pythonanywhere.com/complaint/update/' + idx,
headers: headers,
data: patchData
}).then((response) => {
console.log('resp', response.data)
}).catch((error) => {
console.log(error)
});
this.props.navigation.navigate('Complaint')
}
// This function will call the application status once the component mounts
componentDidMount() {
this.setStatus()
}
render() {
const role = this.props.navigation.getParam('role', 'role')
const status = this.props.navigation.getParam('status', 'status')
const token = this.props.navigation.getParam('token', 'token')
let val = 0;
if (status == 'processing') val = 1
if (status == 'closed') val = 2
return (
<View style={styles.container}>
<Text style={styles.title}>{this.props.navigation.getParam('title', 'title')}</Text>
<Text style={styles.description}>{this.props.navigation.getParam('content', 'content')}</Text>
<Text style={styles.statusDescription}>Status:</Text>
{/* Radio form will be displayed only when user is a faculty */}
{role == "faculty" &&
<View style={styles.status}>
<RadioForm
radio_props={radio_props}
initial={val}
onPress={(value) => { this.setState({ value: value }) }}
/>
<Button title='Update Status' onPress={this.changeStatus}> </Button>
</View>
}
{/* Application status will be visible to the students */}
{
role != "faculty" &&
<Text style={styles.status}>{status}</Text>
}
</View>
);
}
};
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 5,
},
button: {
width: 200,
height: 70,
backgroundColor: 'blue',
marginTop: 150,
marginLeft: 100,
},
radio: {
// marginLeft: 'auto',
// marginRight: 'auto',
paddingLeft: 30,
marginTop: 20,
},
title: {
marginTop: 5,
color: '#1976d2',
fontSize: 40,
paddingLeft: 30,
textAlign: 'center'
},
description: {
fontSize: 20,
paddingLeft: 30,
marginTop: 20,
marginBottom: 40
},
statusDescription: {
paddingLeft: 30,
fontSize: 20,
marginTop: 50,
fontWeight: 'bold',
},
status: {
// textAlign: 'center',
fontSize: 20,
paddingLeft: 30,
}
});
export default (editCView);