-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
160 lines (153 loc) · 4.24 KB
/
app.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
import React from 'react';
import HeaderSection from './layouts/component/header';
import Home from './layouts/body/tabs/Home';
import Event from './layouts/body/tabs/Event';
import User from './layouts/body/tabs/admin/User';
import Profile from './layouts/body/tabs/Profile';
import Activities from './layouts/body/tabs/Activities';
import Booking from './layouts/body/tabs/Booking';
import Services from './layouts/body/tabs/Services';
import { Button, Tab } from 'semantic-ui-react';
import Pouchdb from 'pouchdb-browser';
var userdb = Pouchdb('user');
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
role: '',
fullname: 'Guest User',
profilePic: '',
userId: '',
username: '',
password: '',
firstname: '',
lastname: '',
email: '',
studentId: '',
contact: '',
password: '',
course: '',
study_level: '',
gender: '',
createdAt: '',
updatedAt: ''
};
}
componentWillMount() {
this.fetchfromlocal();
}
fetchfromlocal() {
userdb
.get('user')
.then((doc) => {
this.setState({
role: doc.ROLE,
fullname: (doc.FIRST_NAME + ' ' + doc.LAST_NAME).toString(),
profilePic: doc.IMAGE_URL,
userId: doc.USER_ID,
username: doc.USERNAME,
password: doc.PASSWORD,
firstname: doc.FIRST_NAME,
lastname: doc.LAST_NAME,
email: doc.EMAIL,
studentId: doc.STUDENT_ID,
contact: doc.CONTACT,
password: doc.PASSWORD,
course: doc.COURSE,
study_level: doc.STUDY_LEVEL,
gender: doc.GENDER,
createdAt: doc.CREATED_AT,
updatedAt: doc.UPDATED_AT
});
})
.catch((err) => {
if (err.name === 'not_found') {
console.log(err);
this.setState({
role: 'Guest',
fullname: 'Guest User',
profilePic:
'http://greenwings.co/wp-content/uploads/2018/09/blank-head-profile-pic-for-a-man.jpg'
});
} else {
console.log(err);
}
});
}
render() {
const adminPanes = [
{
menuItem: 'Home',
render: () => <Home role={this.state.role} />
},
{ menuItem: 'Event', render: () => <Event role={this.state.role} /> },
{ menuItem: 'All Bookings', render: () => <Booking role={this.state.role} /> },
{ menuItem: 'Activities', render: () => <Activities role={this.state.role} /> },
{ menuItem: 'Services', render: () => <Services role={this.state.role} /> },
{ menuItem: 'User', render: () => <User role={this.state.role} /> }
];
const user = [
{
menuItem: 'Home',
render: () => <Home role={this.state.role} />
},
{ menuItem: 'Event', render: () => <Event role={this.state.role} userId={this.state.userId} /> },
{ menuItem: 'My Bookings', render: () => <Booking role={this.state.role} userId={this.state.userId} /> },
{ menuItem: 'Activities', render: () => <Activities role={this.state.role} /> },
{ menuItem: 'Services', render: () => <Services role={this.state.role} /> },
{
menuItem: 'Profile',
render: () => (
<Profile
userID={this.state.userId}
firstName={this.state.firstname}
lastName={this.state.lastname}
userName={this.state.username}
password={this.state.password}
email={this.state.email}
profilePic={this.state.profilePic}
createdAt={this.state.createdAt}
updatedAt={this.state.updatedAt}
studentId={this.state.studentId}
role={this.state.role}
study_level={this.state.study_level}
course={this.state.course}
contact={this.state.contact}
gender={this.state.gender}
/>
)
}
];
const guest = [
{
menuItem: 'Home',
render: () => <Home role={this.state.role} />
},
{ menuItem: 'Event', render: () => <Event role={this.state.role} /> },
{ menuItem: 'Activities', render: () => <Activities role={this.state.role} /> },
{ menuItem: 'Services', render: () => <Services role={this.state.role} /> }
];
return (
<div>
<HeaderSection
fullname={this.state.fullname}
profilePic={this.state.profilePic}
role={this.state.role}
/>
<Tab
panes={
this.state.role == 'Guest' ? (
guest
) : this.state.role == 'Admin' ? (
adminPanes
) : this.state.role == 'Student' ? (
user
) : (
guest
)
}
/>
</div>
);
}
}