1
1
import React , { useState } from 'react' ;
2
+ import { Link } from 'react-router-dom' ;
2
3
import axios from "axios" ;
3
- console . clear ( ) ;
4
+
4
5
export default function EditPage ( props ) {
5
- // const [post, setPost] = useState(null);
6
+ < div className = "row" >
7
+ < Link to = '/' className = 'text-black-50 p-2 col-md-5' > Go Back</ Link >
8
+ </ div >
9
+
10
+
6
11
const [ title , setTitle ] = useState ( props . data . title ) ;
7
12
const [ duration , setDuration ] = useState ( props . data . duration ) ;
8
13
const [ imagePath , setImagePath ] = useState ( props . data . imagePath ) ;
9
14
const [ online , setOnline ] = useState ( props . data . online ) ;
10
15
const [ description , setDescription ] = useState ( props . data . description ) ;
16
+
11
17
const [ start_date , setStart_date ] = useState ( props . data . dates . start_date ) ;
12
18
const [ end_date , setEnd_date ] = useState ( props . data . dates . end_date ) ;
13
19
const [ early_bird , setEarly_bird ] = useState ( props . data . price . early_bird ) ;
@@ -27,115 +33,130 @@ export default function EditPage(props) {
27
33
online,
28
34
description,
29
35
} ;
30
- console . log ( 'Link https://chain-legendary-strawflower.glitch.me/courses' + props . idNumber ) ;
31
- axios . put ( 'https://chain-legendary-strawflower.glitch.me/courses' + props . idNumber , data )
36
+
37
+ console . log ( 'Link https://chain-legendary-strawflower.glitch.me/courses/' + props . idNumber ) ;
38
+ axios . put ( 'https://chain-legendary-strawflower.glitch.me/courses/' + props . idNumber , data )
32
39
. then ( ( response ) => {
33
40
console . log ( "THE END" , response )
34
- }
41
+
42
+
43
+ }
35
44
)
36
45
. catch ( ( error ) => console . log ( error ) ) ;
46
+
37
47
props . close ( ) ;
38
48
props . fetchDetails ( ) ;
49
+
39
50
}
51
+
52
+
40
53
if ( ! props . open ) return null ;
41
54
return (
42
- // <div className="z-10 " aria-labelledby="modal-title" role="dialog" aria-modal="true">
43
- // <div className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"></div>
44
- < div className = "overflow-scroll" >
45
55
46
- < form onSubmit = { handleSubmit } className = "fixed top-5 left-5 right-10 bg-sky-100" >
47
- < button type = "button" className = "absolute top-0 right-0 h-16 w-16 box-border p-4 border-4 bg-gradient-to-r from-sky-400 to-red-500 hover:from-pink-500 hover:to-blue-500"
56
+ < div className = "z-10 " aria-labelledby = "modal-title" role = "dialog" aria-modal = "true" >
57
+ < div className = "fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" > </ div >
58
+
59
+ < div style = { { position : 'relative' , zIndex : '2' } } className = "" >
60
+
61
+ < form onSubmit = { handleSubmit } className = "fixed top-5 left-10 right-10 sm:max-xl:flex sm:max-xl:flex-wrap sm:max-xl:w-[90%] sm:max-xl:h-[90%] sm:max-xl:overflow-auto bg-sky-100" >
62
+ < button type = "button" className = "absolute top-0 right-0 box-border h-12 w-12 p-4 border-4 bg-gradient-to-r from-sky-400 to-red-500 hover:from-pink-500 hover:to-blue-500"
48
63
onClick = { ( ) => {
49
64
props . close ( ) ;
50
65
} }
51
66
>
52
67
X
53
68
</ button >
54
- < h1 className = "m-2 font-extrabold text-5xl mb-8 " > Edit Course</ h1 >
69
+ < h1 className = "m-2 font-extrabold text-5xl " > Edit Course</ h1 >
55
70
< div className = "flex flex-wrap -mx-2" >
56
71
< div className = "w-full md:w-1/2 px-2 mb-4 md:mb-0" >
57
72
< label
58
- className = "m-3 block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2 " htmlFor = "grid-first-name" >
73
+ className = "m-3 block uppercase tracking-wide text-gray-700 text-xs font-bold" htmlFor = "grid-first-name" >
59
74
Title
60
75
</ label >
61
76
< input required value = { title }
62
- className = "mx-4 appearance-none block w-[90%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white focus:border-gray-500 justify-center"
77
+ className = " mx-4 appearance-none block w-[90%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500 justify-center"
63
78
name = "title" type = "text"
64
79
onChange = {
65
80
( e ) => setTitle ( ( e . target . value ) )
66
81
} placeholder = "Lesson" > </ input >
67
82
</ div >
68
83
< div className = "w-full md:w-1/2 px-2" >
69
84
< label
70
- className = "m-3 block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2 " htmlFor = "grid-first-name" >
85
+ className = "m-3 block uppercase tracking-wide text-gray-700 text-xs font-bold" htmlFor = "grid-first-name" >
71
86
Duration
72
87
</ label >
73
88
< input required value = { duration }
74
- className = "mx-4 block w-[90%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
89
+ className = " mx-4 block w-[90%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
75
90
name = "duration" type = "text" onChange = { ( e ) => setDuration ( ( e . target . value ) ) } placeholder = "Duration" > </ input >
76
91
</ div >
77
92
</ div >
78
93
< label
79
- className = "m-3 block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2 " htmlFor = "grid-first-name" >
94
+ className = "m-3 block uppercase tracking-wide text-gray-700 text-xs font-bold " htmlFor = "grid-first-name" >
80
95
Image Path
81
96
</ label >
82
97
{ < input required value = { imagePath }
83
- className = "mx-4 w-[95%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
98
+ className = " mx-4 w-[95%] bg bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
84
99
name = "imagePath" type = "text" onChange = { ( e ) => setImagePath ( ( e . target . value ) ) } placeholder = "Image Path" > </ input > }
85
100
< label
86
- className = "m-3 uppercase tracking-wide text-gray-700 text-xs font-bold mb-2 " >
101
+ className = "m-3 uppercase tracking-wide text-gray-700 text-xs font-bold" >
87
102
online
88
103
</ label >
89
104
< input checked = { online } type = "checkbox" onChange = { ( e ) => setOnline ( ( e . target . checked ) ) } />
90
105
< label
91
- className = "m-3 block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2 " >
106
+ className = "m-3 block uppercase tracking-wide text-gray-700 text-xs font-bold " >
92
107
description
93
108
</ label >
94
109
< textarea required value = { description }
95
- className = "block mx-4 w-[95%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 mb-3 "
110
+ className = "block mx-4 w-[95%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 "
96
111
name = "description" type = "text" onChange = { ( e ) => setDescription ( ( e . target . value ) ) } >
97
112
</ textarea >
98
113
99
- < p className = "m-2 font-bold font-weight: 700" > Dates</ p >
114
+ < p className = " m-2 font-bold font-weight: 700" > Dates</ p >
100
115
< div className = "flex flex-wrap -mx-2" >
101
116
< div className = "w-full md:w-1/2 px-2 mb-4 md:mb-0" >
102
117
< label
103
118
className = "m-3 block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" >
104
119
Start Date
105
120
</ label >
106
121
< input required value = { start_date }
107
- className = "mx-4 w-[90%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
122
+ className = " mx-4 w-[90%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
108
123
name = "start_date" type = "date" onChange = { ( e ) => setStart_date ( ( e . target . value ) ) } > </ input >
109
124
</ div >
110
125
< div className = "w-full md:w-1/2 px-2 mb-4 md:mb-0" >
111
- < label className = "m-2 block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2 " >
126
+ < label className = "m-2 block uppercase tracking-wide text-gray-700 text-xs font-bold" >
112
127
End Date
113
128
</ label >
114
129
< input required value = { end_date } className = "mx-4 w-[90%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
115
130
name = "end_date" type = "date" onChange = { ( e ) => setEnd_date ( ( e . target . value ) ) } > </ input >
116
131
</ div >
117
132
</ div >
118
- < p className = "m-3 font-bold font-weight: 700" > Price </ p >
119
- < div className = "flex flex-wrap -mx-2" >
120
- < div className = "w-full md:w-1/2 px-2 mb-4 md:mb-0" >
133
+ < p className = "m-2 font-bold font-weight: 700" > Price </ p >
134
+
135
+ < div className = "flex flex-wrap -mx-2 " >
136
+ < div className = "w-full md:w-1/2 px-2 mb-4 md:mb-0" >
137
+
138
+
121
139
< label className = "m-3 block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2" >
122
140
Early Bird
123
141
</ label >
124
- < input required value = { early_bird } className = "mx-4 w-[90%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
142
+ < input required value = { early_bird } className = " mx-4 w-[90%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
125
143
name = "early_bird" type = "number" onChange = { ( e ) => setEarly_bird ( ( e . target . value ) ) } > </ input >
126
144
</ div >
127
- < div className = "w-full md:w-1/2 px-2 mb-4 md:mb-0" >
128
- < label className = "m-3 block uppercase tracking-wide text-gray-700 text-xs font-bold mb-2 " >
145
+ < div className = "w-full md:w-1/2 px-2 mb-4 md:mb-0" >
146
+ < label className = "m-2 block uppercase tracking-wide text-gray-700 text-xs font-bold" >
129
147
Normal Price
130
148
</ label >
131
149
< input required value = { normal } className = "mx-4 w-[90%] bg-gray-200 text-gray-700 border border-gray-200 rounded py-3 px-4 mb-3 leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
132
150
name = "normal" type = "number" onChange = { ( e ) => setNormal ( ( e . target . value ) ) } > </ input >
133
151
</ div >
152
+
134
153
</ div >
135
154
< button className = "m-2 float-right bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded text-right " type = 'submit' > Update Course </ button >
136
155
</ form >
156
+
157
+ </ div >
137
158
</ div >
138
- // </div>
159
+
139
160
) ;
140
161
141
162
}
0 commit comments