1- import React , { useEffect , useState } from 'react'
1+ import React , { useEffect , useState } from 'react'
22import './fees.css'
33import Modal from 'react-modal'
44import MyCalendar from '../reusables/Calendar'
55import MyLoader from '../reusables/MyLoader'
66
77const customStyles = {
8- content : {
9- top : '50%' ,
10- left : '50%' ,
11- right : 'auto' ,
12- bottom : 'auto' ,
13- marginRight : '-50%' ,
14- transform : 'translate(-50%, -50%)'
8+ content : {
9+ top : '50%' ,
10+ left : '50%' ,
11+ right : 'auto' ,
12+ bottom : 'auto' ,
13+ marginRight : '-50%' ,
14+ transform : 'translate(-50%, -50%)'
1515 }
1616} ;
1717
@@ -22,49 +22,49 @@ const Fee = (props) => {
2222 const [ date , setDate ] = useState ( new Date ( ) )
2323 const [ amount , setAmount ] = useState ( Number )
2424 const [ dateModalOpen , setDateModalOpen ] = useState ( false )
25-
26- useEffect ( ( ) => getStudents ( ) , [ ] )
2725
28- const getStudents = ( ) => {
26+ useEffect ( ( ) => getStudents ( ) , [ ] )
27+
28+ const getStudents = ( ) => {
2929 setLoading ( true )
30- fetch ( '/api/students' , {
30+ fetch ( '/api/students' , {
3131 method : 'GET' ,
3232 mode : 'cors' ,
3333 headers : {
3434 'Content-Type' : 'application/json'
3535 }
3636 } )
37- . then ( res => {
38- if ( res . status !== 200 && res . status !== 201 ) {
39- if ( res . status === 401 ) {
40- setLoading ( false )
41- props . history . push ( '/login' )
42- }
43- if ( res . status === 404 ) {
37+ . then ( res => {
38+ if ( res . status !== 200 && res . status !== 201 ) {
39+ if ( res . status === 401 ) {
40+ setLoading ( false )
41+ props . history . push ( '/login' )
42+ }
43+ if ( res . status === 404 ) {
44+ setLoading ( false )
45+ return < h4 > Not Found !!</ h4 >
46+ }
4447 setLoading ( false )
45- return < h4 > Not Found !! </ h4 >
48+ throw new Error ( res . status )
4649 }
50+ return res . json ( )
51+ } )
52+ . then ( resdata => {
4753 setLoading ( false )
48- throw new Error ( res . status )
49- }
50- return res . json ( )
51- } )
52- . then ( resdata => {
53- setLoading ( false )
54- setStudents ( resdata )
55- } )
56- . catch ( err => {
57- console . log ( err )
58- setLoading ( false )
59- } )
54+ setStudents ( resdata )
55+ } )
56+ . catch ( err => {
57+ console . log ( err )
58+ setLoading ( false )
59+ } )
6060 }
6161
6262 const selectStudent = ( obj , e ) => {
6363 e . preventDefault ( ) ;
6464 setSelectedStudent ( obj )
6565 }
6666
67- const isEmpty = ( obj ) => {
67+ const isEmpty = ( obj ) => {
6868 for ( var key in obj ) {
6969 if ( hasOwnProperty . call ( obj , key ) ) return false
7070 }
@@ -90,107 +90,107 @@ const Fee = (props) => {
9090 "date" : date ,
9191 "amount" : amount
9292 }
93- fetch ( '/api/fee/installment/' + selectedStudent . _id , {
94- method : 'PUT' ,
93+ fetch ( '/api/fee/installment/' + selectedStudent . _id , {
94+ method : 'PUT' ,
9595 mode : 'cors' ,
9696 headers : {
9797 'content-type' : 'application/json'
9898 } ,
9999 body : JSON . stringify ( body )
100100 } )
101- . then ( res => {
102- if ( res . status !== 200 && res . status !== 201 ) {
103- if ( res . status === 401 ) {
101+ . then ( res => {
102+ if ( res . status !== 200 && res . status !== 201 ) {
103+ if ( res . status === 401 ) {
104+ setLoading ( false )
105+ props . history . push ( '/login' )
106+ }
107+ if ( res . status === 404 ) {
108+ setLoading ( false )
109+ return < h4 > Not Found !!</ h4 >
110+ }
104111 setLoading ( false )
105- props . history . push ( '/login' )
106- }
107- if ( res . status === 404 ) {
108- setLoading ( false )
109- return < h4 > Not Found !!</ h4 >
112+ throw new Error ( res . status )
110113 }
114+ return res . json ( ) ;
115+ } )
116+ . then ( data => {
111117 setLoading ( false )
112- throw new Error ( res . status )
113- }
114- return res . json ( ) ;
115- } )
116- . then ( data => {
117- setLoading ( false )
118- getStudents ( )
119- setSelectedStudent ( data )
120- } )
121- . catch ( err => {
122- console . log ( err )
123- setLoading ( false )
124- } )
118+ getStudents ( )
119+ setSelectedStudent ( data )
120+ } )
121+ . catch ( err => {
122+ console . log ( err )
123+ setLoading ( false )
124+ } )
125125 }
126-
127- const remainingFees = ( ) => {
128- const { total, installments} = selectedStudent . fees ;
126+
127+ const remainingFees = ( ) => {
128+ const { total, installments } = selectedStudent . fees ;
129129 let temp = total ;
130130 installments . map ( inst => ( temp = temp - inst . amount ) )
131131 return < h6 > { temp } </ h6 >
132132 }
133-
134- const { fees} = selectedStudent ;
133+
134+ const { fees } = selectedStudent ;
135135
136136 return ( loading ) ?
137- < MyLoader loading = { loading } /> :
137+ < MyLoader loading = { loading } /> :
138138 < div className = "container" >
139139 < h1 className = 'main-heading' > Fees</ h1 >
140140 < div className = "row" >
141141 < div className = "col-md-4" >
142142 < table className = "table table-dark" >
143- < thead onClick = { e => setSelectedStudent ( { } ) } >
143+ < thead onClick = { e => setSelectedStudent ( { } ) } >
144144 < tr >
145145 < th scope = 'col' > #</ th >
146146 < th scope = 'col' > Student</ th >
147147 </ tr >
148148 </ thead >
149149 < tbody >
150- {
151- students . sort ( ( a , b ) => { return a . standard - b . standard } ) . map ( ( stud , i ) => (
152- < tr key = { i } onClick = { e => selectStudent ( stud , e ) } >
153- < th scope = 'row' > { i } </ th >
154- < td > { stud . firstName } { stud . lastName } </ td >
155- </ tr >
156- ) )
157- }
150+ {
151+ students . sort ( ( a , b ) => { return a . standard - b . standard } ) . map ( ( stud , i ) => (
152+ < tr key = { i } onClick = { e => selectStudent ( stud , e ) } >
153+ < th scope = 'row' > { i } </ th >
154+ < td > { stud . firstName } { stud . lastName } </ td >
155+ </ tr >
156+ ) )
157+ }
158158 </ tbody >
159159 </ table >
160160 </ div >
161161 { ! isEmpty ( selectedStudent ) && < div className = "col bg-dark text-white pt-3 fees" >
162162 < div className = "col-md total" >
163163 < h5 > Total Fees</ h5 >
164- < hr className = 'border' />
164+ < hr className = 'border' />
165165 { ! isEmpty ( selectedStudent ) && < h6 > { fees . total } </ h6 > }
166166 </ div >
167167 < div className = "col rem" >
168168 < h5 > Remaining Fees</ h5 >
169- < hr className = 'border' />
169+ < hr className = 'border' />
170170 { ! isEmpty ( selectedStudent ) && < span > { remainingFees ( ) } </ span > }
171171 </ div >
172172 </ div > }
173173 < div className = "h-100 border" > </ div >
174174 { ! isEmpty ( selectedStudent ) && < div className = "col-md bg-dark text-white pt-3 fees" >
175175 < div className = "col paid" >
176176 < h5 > Installments Paid</ h5 >
177- < hr className = 'border' />
177+ < hr className = 'border' />
178178 { ! isEmpty ( selectedStudent ) && < h6 > { fees . installments
179- . map ( ( inst , i ) => < div key = { i } > { inst . amount } </ div > ) } </ h6 > }
179+ . map ( ( inst , i ) => < div key = { i } > { inst . amount } </ div > ) } </ h6 > }
180180 </ div >
181181
182182 < div className = "col new" >
183183 < h5 > Add Installment</ h5 >
184- < hr className = 'border' />
184+ < hr className = 'border' />
185185 < form onSubmit = { handleSubmit } >
186186 < div className = "form-group" >
187187 < label htmlFor = "installment" > Amount</ label >
188- < input type = "tel" onChange = { e => setAmount ( e . target . value ) } className = 'form-control form-control-sm' name = "installment" required />
188+ < input type = "tel" onChange = { e => setAmount ( e . target . value ) } className = 'form-control form-control-sm' name = "installment" required />
189189 < label htmlFor = "date" > Date</ label >
190190 < i className = "far fa-calendar-alt btn-lg" id = "date" onClick = { openModal } > </ i >
191191 < p > Selected Date:- { date . toLocaleString ( 'en-IN' ) . split ( ',' ) [ 0 ] } </ p >
192192 </ div >
193- < input type = "submit" className = 'btn btn-sm btn-light mt-3' value = "Add Installment" />
193+ < input type = "submit" className = 'btn btn-sm btn-light mt-3' value = "Add Installment" />
194194 </ form >
195195 </ div >
196196 </ div > }
0 commit comments