Skip to content

Commit 12a4b08

Browse files
committed
dates in add and edit
1 parent b356f34 commit 12a4b08

File tree

13 files changed

+277
-188
lines changed

13 files changed

+277
-188
lines changed

app/config/keys.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const dbURI = 'mongodb://localhost:27017/nitmoi';
1+
const dbURI = 'mongodb://archisbhoir:Archi%40123321@ds351807.mlab.com:51807/nitmoi'
22
const SECRET = 'fdshgchsbfojsd153456ds4fndsjbvjkdsda4sfdfgf564sd56v4f';
33
module.exports = {dbURI, SECRET}
44

app/models/student.model.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const StudentSchema = new mongoose.Schema({
1212
type: String,
1313
require: [true, 'name required mann!!']
1414
},
15+
dateOfBirth: Date,
1516
Address: {
1617
type: String,
1718
require: [true, 'name required mann!!']

client/src/components/add-student/AddStudent.js

Lines changed: 88 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import React, { Component } from 'react'
22
import Modal from 'react-modal';
33
import MyCalendar from '../reusables/Calendar'
44
import { AuthContext } from '../../context'
5-
import MyLoader from '../reusables/MyLoader';
6-
5+
import MyLoader from '../reusables/MyLoader'
76

87
const customStyles = {
98
content: {
@@ -25,16 +24,15 @@ export default class AddStudent extends Component {
2524
this.englishEl = React.createRef(); this.mathsEl = React.createRef();
2625
this.sexEl = React.createRef(); this.feesEl = React.createRef();
2726
this.state = {
28-
modalIsOpen: false,
27+
modalJoinIsOpen: false, modalDOBIsOpen: false,
2928
date: new Date(),
30-
addedStudent: {},
31-
loading: false,
32-
loggedIn: false
29+
loading: false,loggedIn: false,
30+
dateOfJoining: 'pick a date',dateOfBirth: new Date()
3331
}
3432
}
3533

36-
componentDidMount=()=>{
37-
this.setState({loading: true})
34+
componentDidMount = () => {
35+
this.setState({ loading: true })
3836
fetch('/auth', {
3937
method: 'GET',
4038
mode: 'cors',
@@ -43,27 +41,36 @@ export default class AddStudent extends Component {
4341
}
4442
}).then(res => {
4543
if (res.status === 200) {
46-
this.setState({loggedIn: true, loading:false})
44+
this.setState({ loggedIn: true, loading: false })
4745
} else {
48-
this.setState({ loggedIn: false, loading:false})
46+
this.setState({ loggedIn: false, loading: false })
4947
}
5048
}).catch(err => {
51-
this.setState({loggedIn: false,loading:false})
49+
this.setState({ loggedIn: false, loading: false })
5250
throw new Error(err)
5351
})
5452
}
5553

5654
onChange = date => {
57-
this.setState({ date })
55+
this.setState({ dateOfJoining: date })
56+
this.closeModal()
57+
}
58+
59+
onDOBChange = date => {
60+
this.setState({ dateOfBirth: date })
5861
this.closeModal()
5962
}
6063

61-
openModal = () => {
62-
this.setState({ modalIsOpen: true });
64+
openJoiningModal = () => {
65+
this.setState({ modalJoinIsOpen: true });
66+
}
67+
68+
openDOBModal = () => {
69+
this.setState({ modalDOBIsOpen: true });
6370
}
6471

6572
closeModal = () => {
66-
this.setState({ modalIsOpen: false });
73+
this.setState({ modalJoinIsOpen: false, modalDOBIsOpen: false });
6774
}
6875

6976
redirectHome = (e) => {
@@ -78,52 +85,41 @@ export default class AddStudent extends Component {
7885
handleAddForm = (e) => {
7986
e.preventDefault();
8087
this.setState({ loading: true })
81-
const fName = this.firstNameEl.current.value;
82-
const mName = this.firstNameEl.current.value;
83-
const lName = this.lastNameEl.current.value;
84-
const std = this.standardEl.current.value;
85-
const addr = this.addressEl.current.value;
86-
const brd = this.boardEl.current.value;
87-
const phy = this.physicsEl.current.value;
88-
const eng = this.englishEl.current.value;
89-
const maths = this.mathsEl.current.value;
90-
const sex = this.sexEl.current.value;
91-
const fees = this.feesEl.current.value;
88+
const fName = this.firstNameEl.current.value; const mName = this.firstNameEl.current.value;
89+
const lName = this.lastNameEl.current.value; const std = this.standardEl.current.value;
90+
const addr = this.addressEl.current.value; const brd = this.boardEl.current.value;
91+
const phy = this.physicsEl.current.value; const eng = this.englishEl.current.value;
92+
const maths = this.mathsEl.current.value; const sex = this.sexEl.current.value; const fees = this.feesEl.current.value;
9293

9394
const addStudentRequest = {
9495
"firstName": fName, "middleName": mName, "lastName": lName,
95-
"Address": addr, "standard": std,
96-
"Board": brd,
97-
"lastYearmarks": {
98-
"physics": phy,
99-
"english": eng,
100-
"maths": maths
101-
}, "sex": sex,
102-
"fees": {
103-
"total": fees
104-
}
96+
"dateOfBirth": this.state.dateOfBirth,
97+
"joinedOn": this.state.dateOfJoining,
98+
"Address": addr, "standard": std, "Board": brd,
99+
"lastYearmarks": { "physics": phy, "english": eng, "maths": maths },
100+
"sex": sex, "fees": { "total": fees }
105101
}
106102
fetch('/api/student', {
107103
method: 'POST', mode: 'cors',
108104
headers: {
109105
'Content-Type': 'application/json',
110106
'Accept': 'application/json'
111-
},
112-
body: JSON.stringify(addStudentRequest)
113-
}).then(res => {
114-
if (res.status !== 200 && res.status !== 201) {
115-
if (res.status === 401) {
116-
this.setState({ loading: false })
117-
this.props.history.push('/login')
118-
} else {
119-
this.setState({ loading: false })
120-
}
121-
}
122-
this.setState({ loading: false })
123-
return res.json();
107+
}, body: JSON.stringify(addStudentRequest)
124108
})
109+
.then(res => {
110+
if (res.status !== 200 && res.status !== 201) {
111+
if (res.status === 401) {
112+
this.setState({ loading: false })
113+
this.props.history.push('/login')
114+
} else {
115+
this.setState({ loading: false })
116+
}
117+
}
118+
this.setState({ loading: false })
119+
return res.json();
120+
})
125121
.then(resData => {
126-
this.setState({ addedStudent: resData, loading: false })
122+
this.setState({ loading: false })
127123
this.props.history.push('/list')
128124
})
129125
.catch(err => {
@@ -132,13 +128,14 @@ export default class AddStudent extends Component {
132128
}
133129

134130
render() {
135-
return (this.state.loading) ? <MyLoader loading={this.state.loading} /> :
131+
return (this.state.loading) ? <MyLoader loading={this.state.loading} /> :
136132
this.state.loggedIn ? <AuthContext.Consumer>
137-
{context => (
133+
{context => (
138134
<div className="container text-align-center p-3">
139135
<div className="container w-75 text-align-center">
140-
<div className="container" style={{textAlign:'center',fontSize:'25px'}}>Add New Student</div>
136+
<div className="container" style={{ textAlign: 'center', fontSize: '25px' }}>Add New Student</div>
141137
<form className="py-3" onSubmit={this.handleAddForm}>
138+
<hr />
142139
<div className="row py-3">
143140
<div className="col">
144141
<input type="text" ref={this.firstNameEl} className="form-control form-control-sm" placeholder="First name" required />
@@ -152,6 +149,16 @@ export default class AddStudent extends Component {
152149
</div>
153150
<div className="form-group">
154151
<input type="text" ref={this.addressEl} className="form-control form-control-sm" id="InputAddress" placeholder="Address" required />
152+
<div className="input-group w-25">
153+
<label htmlFor="dateOfBirth">Date Of Birth </label>
154+
<div className="w-100"></div>
155+
<input type="text" className='form-control form-control-sm' value={this.state.dateOfBirth.toLocaleString('en-IN').split(',')[0]} name="dateOfBirth" readOnly />
156+
<div className="input-group-append">
157+
<span className="input-group-text" title='Date Of Joining' id="basic-addon1" onClick={this.openDOBModal}>
158+
<i className="far fa-calendar-alt" id="date" />
159+
</span>
160+
</div>
161+
</div>
155162
</div>
156163
<hr />
157164
<div className="row">
@@ -176,10 +183,15 @@ export default class AddStudent extends Component {
176183
</select>
177184
</div>
178185
</div>
179-
<div className="form-group">
180-
<label htmlFor="InputDate">Date Of Joining </label>
181-
<i className="far fa-calendar-alt ml-2 mr-4 mb-2 btn-lg" id="InputDate" onClick={this.openModal} />
182-
<span>Selected Date:- {this.state.date.toLocaleString('en-IN').split(',')[0]}</span>
186+
<div className="input-group w-25">
187+
<label htmlFor="dateOfJoining">Date Of Joining </label>
188+
<div className="w-100"></div>
189+
<input type="text" className='form-control form-control-sm' value={this.state.dateOfJoining.toLocaleString('en-IN').split(',')[0]} name="dateOfJoining" readOnly />
190+
<div className="input-group-append">
191+
<span className="input-group-text" title='Date Of Joining' id="basic-addon1" onClick={this.openJoiningModal}>
192+
<i className="far fa-calendar-alt" id="date" />
193+
</span>
194+
</div>
183195
</div>
184196
<hr />
185197
<div>
@@ -196,7 +208,7 @@ export default class AddStudent extends Component {
196208
<input type="text" className="form-control form-control-sm" ref={this.mathsEl} id="InputMaths" placeholder="Maths" required />
197209
</div>
198210
</div>
199-
<hr/>
211+
<hr />
200212
<div className="row">
201213
<div className="form-group col">
202214
<label htmlFor="InputSex">Gender</label>
@@ -210,14 +222,14 @@ export default class AddStudent extends Component {
210222
<input type="number" className="form-control form-control-sm" ref={this.feesEl} id="InputFees" placeholder="Total Fees" />
211223
</div>
212224
</div>
213-
<hr/>
225+
<hr />
214226
<button type="button" onClick={this.redirectHome} className="btn btn-light float-right ml-3">Cancel</button>
215227
<button type="submit" className="btn btn-primary float-right">Submit</button>
216228
</form>
217229
</div>
218230

219231
<Modal
220-
isOpen={this.state.modalIsOpen}
232+
isOpen={this.state.modalJoinIsOpen}
221233
onRequestClose={this.closeModal}
222234
style={customStyles}
223235
contentLabel="Date Picker Modal"
@@ -228,11 +240,23 @@ export default class AddStudent extends Component {
228240
value={this.state.date}
229241
/>
230242
</Modal>
243+
<Modal
244+
isOpen={this.state.modalDOBIsOpen}
245+
onRequestClose={this.closeModal}
246+
style={customStyles}
247+
contentLabel="Date Picker Modal"
248+
ariaHideApp={false}
249+
>
250+
<MyCalendar
251+
onChange={this.onDOBChange}
252+
value={this.state.date}
253+
/>
254+
</Modal>
231255
</div>
232256
)}
233-
</AuthContext.Consumer>: <div className='container p-5'>
234-
<h3>OOPS !! <br/> Not Logged In</h3>
235-
<a href="/login" onClick={this.redirectLogin}>Login</a>
257+
</AuthContext.Consumer> : <div className='container p-5'>
258+
<h3>OOPS !! <br /> Not Logged In</h3>
259+
<a href="/login" onClick={this.redirectLogin}>Login</a>
236260
</div>
237-
}
261+
}
238262
}

client/src/components/attendance/Attendance.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import MyLoader from '../reusables/MyLoader';
55
import './attendance.css'
66
import Checkbox from './Checkbox'
77

8-
const customStylesContainer = {
9-
'fontSize': '18px',
10-
'border': '1px solid black',
11-
'textAlign': 'left',
12-
'height': 'auto',
13-
'width': '50%',
14-
'minWidth': '350px',
15-
'top': '50%',
16-
'margin': '100px auto 0 auto',
17-
'padding': '20px',
18-
'backgroundColor': 'white'
19-
}
8+
// const customStylesContainer = {
9+
// 'fontSize': '18px',
10+
// 'border': '1px solid black',
11+
// 'textAlign': 'left',
12+
// 'height': 'auto',
13+
// 'width': '50%',
14+
// 'minWidth': '350px',
15+
// 'top': '50%',
16+
// 'margin': '100px auto 0 auto',
17+
// 'padding': '20px',
18+
// 'backgroundColor': 'white'
19+
// }
2020

2121
const customStyles = {
2222
content: {
@@ -67,7 +67,7 @@ export default class AddAttendance extends Component {
6767
}
6868
}
6969

70-
componentWillMount = () => {
70+
componentDidMount = () => {
7171
this.setState({ loading: true })
7272
fetch('/api/students', {
7373
method: 'GET',
@@ -99,7 +99,9 @@ export default class AddAttendance extends Component {
9999

100100
handleCheckboxChange = (student) => {
101101
if (this.state.present.indexOf(student) === -1) {
102-
this.setState({ present: [...this.state.present, student] })
102+
this.setState({ present: [...this.state.present, student] },()=>{
103+
console.log(this.state.present)
104+
})
103105
}
104106
}
105107

@@ -248,7 +250,7 @@ export default class AddAttendance extends Component {
248250
<br />
249251
<h4 className='selected-date'>Selected Date {this.state.viewDate.toDateString()}</h4>
250252
<button type="submit" className="btn btn-primary" onClick={this.getAttendanceByDate}>Find Attendance</button>
251-
{this.state.errors.length === 0 && this.state.presentStuds.map((stud, i) => <div className='border' style={{ margin: '20px auto' }}>
253+
{this.state.errors.length === 0 && this.state.presentStuds.map((stud, i) => <div key={i} className='border' style={{ margin: '20px auto' }}>
252254
{/* <Student key={i}
253255
fName={stud.firstName}
254256
lName={stud.lastName}

client/src/components/attendance/Checkbox.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ export default class Checkbox extends Component {
99
}
1010

1111
handleClick = (e) => {
12+
console.log(this.props)
1213
const { handleChange, stud, clearList } = this.props;
1314
this.setState({ checked: !this.state.checked },()=>{
14-
console.log(this.state.checked)
15+
if (this.state.checked) {
16+
handleChange(stud)
17+
} else {
18+
clearList(stud)
19+
}
1520
});
16-
if (this.state.checked) {
17-
handleChange(stud)
18-
} else {
19-
clearList(stud)
20-
}
21+
2122
}
2223

2324
render() {

client/src/components/fees/Fee.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ const Fee = (props) => {
238238
<div class="input-group mb-3 w-75">
239239
<input type="tel" onChange={installmentInputHandler} className='form-control form-control-sm' name="installment" required />
240240
<div class="input-group-append">
241-
<span class="input-group-text" id="basic-addon1">
241+
<span class="input-group-text" title='Date Of Installment' id="basic-addon1">
242242
<i className="far fa-calendar-alt" id="date" onClick={openModal}></i>
243243
</span>
244244
</div>

client/src/components/login/Login.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ html,body{
66
height: 100%;
77
font-family: 'Numans', sans-serif, Courier, "Courier New", "Palatino Linotype","Franklin Gothic Medium";
88
background-color: rgb(202, 215, 255);
9+
font-size: 14px !important;
910
}
1011

1112
.login-container{

client/src/components/login/Login.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class AppLogin extends Component {
9696
type="email"
9797
className="form-control"
9898
placeholder="email"
99+
autoComplete='email'
99100
ref={this.emailEl}
100101
/>
101102
</div>

0 commit comments

Comments
 (0)