@@ -6,26 +6,8 @@ import LoadingAnimation from "../../LoadingAnimation/LoadingAnimation";
6
6
import ShopItem from "../ShopItem/ShopItem" ;
7
7
import ShowModal from "../../ShowModal/ShowModal" ;
8
8
import { handleAddInvention } from "../../Api_/ShopApi" ;
9
-
10
- const newInvention = {
11
- name : "" ,
12
- description : "" ,
13
- uses : "" ,
14
- creator : "" ,
15
- image : "" ,
16
- date_of_invention : "" ,
17
- patent_number : "" ,
18
- price : "" ,
19
- weight : "" ,
20
- dimensions : "" ,
21
- power_source : "" ,
22
- operating_time : "" ,
23
- material : "" ,
24
- status : 0 ,
25
- reviews : [ ] ,
26
- category : "" ,
27
- target_audience : "" ,
28
- } ;
9
+ import ShopAddInvention from "../ShopAddInvention/ShopAddInvention" ;
10
+ import { newInvention } from "../../../content" ;
29
11
30
12
export default function ShopContainer ( ) {
31
13
const [ data , setData ] = useState ( [ ] ) ;
@@ -36,6 +18,7 @@ export default function ShopContainer() {
36
18
const [ selectedSectionId , setSelectedSectionId ] = useState ( null ) ;
37
19
const [ addItem , setAddItem ] = useState ( false ) ;
38
20
const [ newItems , setNewItems ] = useState ( newInvention ) ;
21
+ const [ errorMessage , setErrorMessage ] = useState ( "" ) ;
39
22
40
23
function handleChangeInvention ( event ) {
41
24
setNewItems ( ( prev ) => {
@@ -45,8 +28,14 @@ export default function ShopContainer() {
45
28
46
29
function addNewInvention ( event ) {
47
30
event . preventDefault ( ) ;
48
- handleAddInvention ( newItems , setData ) ;
49
- setNewItems ( newInvention ) ;
31
+ handleAddInvention ( newItems , setData , setErrorMessage ) ;
32
+
33
+ setTimeout ( ( ) => setErrorMessage ( "" ) , 5000 ) ;
34
+
35
+ if ( ! Object . values ( newItems ) . includes ( "" ) && errorMessage === "" ) {
36
+ setAddItem ( false ) ;
37
+ setNewItems ( newInvention ) ;
38
+ }
50
39
}
51
40
useEffect ( ( ) => {
52
41
fetchShopData ( ( newData ) => {
@@ -101,106 +90,15 @@ export default function ShopContainer() {
101
90
< Navbar title = { [ "Getting started" , "Shop" ] } >
102
91
< ShowModal
103
92
modalStatus = { addItem }
104
- title = " Add a new invention"
93
+ title = { errorMessage !== "" ? errorMessage : ` Add a new Invention` }
105
94
modalDisable = { setAddItem }
106
95
>
107
- < form className = "shop-invention-add-form" >
108
- < div >
109
- < label > Your name:</ label >
110
- < input
111
- name = "creator"
112
- onChange = { handleChangeInvention }
113
- type = "text"
114
- />
115
- < label > Invention name:</ label >
116
- < input
117
- name = "name"
118
- value = { newItems . name }
119
- onChange = { handleChangeInvention }
120
- type = "text"
121
- />
122
- < label > Uses form:</ label >
123
- < input
124
- name = "uses"
125
- value = { newItems . uses }
126
- onChange = { handleChangeInvention }
127
- type = "text"
128
- />
129
- < label > Price:</ label >
130
- < input
131
- name = "price"
132
- value = { newItems . price }
133
- onChange = { handleChangeInvention }
134
- type = "text"
135
- />
136
- < label > Weight:</ label >
137
- < input
138
- name = "weight"
139
- value = { newItems . weight }
140
- onChange = { handleChangeInvention }
141
- type = "text"
142
- />
143
- < label > Description:</ label >
144
- < textarea
145
- name = "description"
146
- value = { newItems . description }
147
- onChange = { handleChangeInvention }
148
- > </ textarea >
149
- </ div >
150
- < hr />
151
- < div >
152
- < label > Dimensions:</ label >
153
- < input
154
- value = { newItems . dimensions }
155
- name = "dimensions"
156
- onChange = { handleChangeInvention }
157
- type = "text"
158
- />
159
- < label > Power source:</ label >
160
- < input
161
- value = { newItems . power_source }
162
- name = "power_source"
163
- onChange = { handleChangeInvention }
164
- type = "text"
165
- />
166
- < label > Material:</ label >
167
- < input
168
- value = { newItems . material }
169
- name = "material"
170
- onChange = { handleChangeInvention }
171
- type = "text"
172
- />
173
- < label > Avaiable:</ label >
174
- < input
175
- value = { newItems . status }
176
- name = "status"
177
- onChange = { handleChangeInvention }
178
- type = "number"
179
- />
180
- < label > Category:</ label >
181
- < input
182
- value = { newItems . category }
183
- name = "category"
184
- onChange = { handleChangeInvention }
185
- type = "text"
186
- />
187
- < label > Target Audience:</ label >
188
- < input
189
- value = { newItems . target_audience }
190
- name = "target_audience"
191
- onChange = { handleChangeInvention }
192
- type = "text"
193
- />
194
-
195
- < span >
196
- < button onClick = { addNewInvention } > Add invention</ button >
197
- </ span >
198
- < p className = "shop-invention-text" >
199
- < a > *</ a > If you add your invention, it will appear at the bottom of
200
- page!
201
- </ p >
202
- </ div >
203
- </ form >
96
+ < ShopAddInvention
97
+ newItems = { newItems }
98
+ errorMessage = { errorMessage }
99
+ addNewInvention = { addNewInvention }
100
+ handleChangeInvention = { handleChangeInvention }
101
+ />
204
102
</ ShowModal >
205
103
< section className = "shop-searchbox" >
206
104
< input
0 commit comments