@@ -9,6 +9,8 @@ import { useHistory } from 'react-router-dom';
9
9
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
10
10
import { faBookmark } from '@fortawesome/free-solid-svg-icons' ;
11
11
import Switch from 'react-switch' ;
12
+ import { useMutation } from '@apollo/client' ;
13
+ import CREATE_JOURNAL from '../../graphql/mutation/createJournal' ;
12
14
import {
13
15
Container ,
14
16
Head ,
@@ -30,130 +32,113 @@ import { useGlobalContext } from '../../context/DataContext';
30
32
import { SectionLayout , PolicyContainer } from '../marginals' ;
31
33
32
34
const AddJournal = ( ) => {
33
- const {
34
- title,
35
- authors,
36
- journaltype,
37
- topic,
38
- issn,
39
- link,
40
- policy,
41
- dataavail,
42
- handleChangeData,
43
- datashared,
44
- handleChangeData2,
45
- peerreview,
46
- handleChangePeer,
47
- enforced,
48
- evidence,
49
- isPending,
50
- handleSubmit,
51
- dispatch,
52
- } = useGlobalContext ( ) ;
35
+ const [ title , setTitile ] = useState ( '' ) ;
36
+ const [ topic , setTopic ] = useState ( '' ) ;
37
+ const [ issn , setIssn ] = useState ( '' ) ;
38
+ const [ link , setLink ] = useState ( '' ) ;
39
+ const [ policy , setPolicy ] = useState ( '' ) ;
40
+ const [ dataavail , setDataavail ] = useState ( false ) ;
41
+ const [ datashared , setDatashared ] = useState ( false ) ;
42
+ const [ peerreview , setPeerreview ] = useState ( false ) ;
43
+ const [ enforced , setEnforced ] = useState ( '' ) ;
44
+ const [ evidence , setEvidence ] = useState ( '' ) ;
45
+ const [ policyTitle , setPolicyTitle ] = useState ( '' ) ;
46
+ // const [firstYear] = useState(2000);
47
+
48
+ const [ createJournal , { data, error } ] = useMutation ( CREATE_JOURNAL ) ;
49
+
50
+ console . log ( { data } ) ;
51
+ // console.log(createJournal);
52
+
53
+ const addJournal = async ( event ) => {
54
+ event . preventDefault ( ) ;
55
+ const response = await createJournal ( {
56
+ variables : {
57
+ journalToCreate : {
58
+ title,
59
+ url : link ,
60
+ issn,
61
+ domainName : topic ,
62
+ policies : {
63
+ title : policyTitle ,
64
+ policyType : policy ,
65
+ enforced,
66
+ enforcedEvidence : evidence ,
67
+ isDataAvailabilityStatementPublished : dataavail ,
68
+ isDataShared : datashared ,
69
+ isDataPeerReviewed : peerreview ,
70
+ firstYear : 2000 ,
71
+ } ,
72
+ } ,
73
+ } ,
74
+ } ) ;
75
+ } ;
76
+
77
+ const handleChangeData = ( nextChecked ) => {
78
+ setDataavail ( nextChecked ) ;
79
+ } ;
80
+ const handleChangeData2 = ( nextChecked ) => {
81
+ setDatashared ( nextChecked ) ;
82
+ } ;
83
+ const handleChangePeer = ( nextChecked ) => {
84
+ setPeerreview ( nextChecked ) ;
85
+ } ;
86
+ const [ isPending , setIsPending ] = useState ( false ) ;
87
+
53
88
return (
54
89
< SectionLayout >
55
90
< PolicyContainer >
56
91
< Head > Create Journal Policies</ Head >
57
- < Form onSubmit = { handleSubmit } >
92
+ < Form onSubmit = { addJournal } >
58
93
< Label > Journal titile</ Label >
59
- < Input
60
- type = 'text'
61
- required
62
- value = { title }
63
- onChange = { ( e ) =>
64
- dispatch ( {
65
- type : 'SET_TITLE' ,
66
- payload : e . target . value ,
67
- } )
68
- }
69
- />
94
+ < Input type = 'text' required value = { title } onChange = { ( e ) => setTitile ( e . target . value ) } />
70
95
< FirstDiv >
71
96
< div >
72
97
< Label > Journal Type</ Label >
73
98
< Input
74
99
type = 'text'
75
100
required
76
- value = { journaltype }
77
- onChange = { ( e ) =>
78
- dispatch ( {
79
- type : 'SET_JOURNALTYPE' ,
80
- payload : e . target . value ,
81
- } )
82
- }
101
+ value = { topic }
102
+ onChange = { ( e ) => setTopic ( e . target . value ) }
83
103
/>
84
104
</ div >
85
105
< div >
86
106
< Label > ISSN Number</ Label >
87
- < Input
88
- type = 'text'
89
- required
90
- value = { issn }
91
- onChange = { ( e ) =>
92
- dispatch ( {
93
- type : 'SET_ISSN' ,
94
- payload : e . target . value ,
95
- } )
96
- }
97
- />
107
+ < Input type = 'text' required value = { issn } onChange = { ( e ) => setIssn ( e . target . value ) } />
98
108
</ div >
99
109
< div >
100
110
< Label > Enforced Evidence</ Label >
101
111
< Input
102
112
type = 'text'
103
113
required
104
114
value = { evidence }
105
- onChange = { ( e ) =>
106
- dispatch ( {
107
- type : 'SET_EVIDENCE' ,
108
- payload : e . target . value ,
109
- } )
110
- }
115
+ onChange = { ( e ) => setEvidence ( e . target . value ) }
111
116
/>
112
117
</ div >
113
118
</ FirstDiv >
114
119
< FirstDiv >
115
- < div >
120
+ { /* <div>
116
121
<Label>Domain</Label>
117
122
<Input
118
123
type='text'
119
124
required
120
125
value={topic}
121
- onChange = { ( e ) =>
122
- dispatch ( {
123
- type : 'SET_TOPIC' ,
124
- payload : e . target . value ,
125
- } )
126
- }
126
+ onChange={(e) => setTopic(e.target.value)}
127
127
/>
128
- </ div >
128
+ </div> */ }
129
129
< div >
130
130
< Label > Source</ Label >
131
- < Input
132
- type = 'text'
133
- required
134
- value = { link }
135
- onChange = { ( e ) =>
136
- dispatch ( {
137
- type : 'SET_LINK' ,
138
- payload : e . target . value ,
139
- } )
140
- }
141
- />
131
+ < Input type = 'text' required value = { link } onChange = { ( e ) => setLink ( e . target . value ) } />
142
132
</ div >
143
- < div >
133
+ { /* <div>
144
134
<Label>Authors</Label>
145
135
<Input
146
136
type='text'
147
137
required
148
138
value={authors}
149
- onChange = { ( e ) =>
150
- dispatch ( {
151
- type : 'SET_AUTHORS' ,
152
- payload : e . target . value ,
153
- } )
154
- }
139
+ onChange={(e) => setAuthors(e.target.value)}
155
140
/>
156
- </ div >
141
+ </div> */ }
157
142
</ FirstDiv >
158
143
< Subhead >
159
144
< Icon >
@@ -163,35 +148,37 @@ const AddJournal = () => {
163
148
</ Subhead >
164
149
< Div >
165
150
< SecondDiv >
151
+ { /* <div>
152
+ <Label>First Year</Label>
153
+ <Input
154
+ type='text'
155
+ required
156
+ value={policyTitle}
157
+ onChange={(e) => setPolicyTitle(e.target.value)}
158
+ />
159
+ </div> */ }
160
+ < div >
161
+ < Label > Policy Title</ Label >
162
+ < Input
163
+ type = 'text'
164
+ required
165
+ value = { policyTitle }
166
+ onChange = { ( e ) => setPolicyTitle ( e . target . value ) }
167
+ />
168
+ </ div >
166
169
< div >
167
170
< Label > Policy Type:</ Label >
168
- < Select
169
- value = { policy }
170
- onChange = { ( e ) =>
171
- dispatch ( {
172
- type : 'SET_POLICY' ,
173
- payload : e . target . value ,
174
- } )
175
- }
176
- >
177
- < option value = 'policy 1' > Policy 1</ option >
178
- < option value = 'policy 2' > Policy 2</ option >
179
- < option value = 'policy 3' > Policy 3</ option >
171
+ < Select value = { policy } onChange = { ( e ) => setPolicy ( e . target . value ) } >
172
+ < option value = 'NUMBER_ONE' > NUMBER_ONE</ option >
173
+ < option value = 'NUMBER_TWO' > NUMBER_TWO</ option >
174
+ < option value = 'NUMBER_THREE' > NUMBER_THREE</ option >
180
175
</ Select >
181
176
</ div >
182
177
< div >
183
178
< Label > Enforced:</ Label >
184
- < Select
185
- value = { enforced }
186
- onChange = { ( e ) =>
187
- dispatch ( {
188
- type : 'ENFORCED' ,
189
- payload : e . target . value ,
190
- } )
191
- }
192
- >
193
- < option value = 'Yes - before publication' > Yes - before publication</ option >
194
- < option value = 'option 2' > Option 2</ option >
179
+ < Select value = { enforced } onChange = { ( e ) => setEnforced ( e . target . value ) } >
180
+ < option value = 'YES' > Yes - before publication</ option >
181
+ < option value = 'NO' > Option 2</ option >
195
182
</ Select >
196
183
</ div >
197
184
</ SecondDiv >
@@ -205,7 +192,7 @@ const AddJournal = () => {
205
192
onChange = { handleChangeData }
206
193
checked = { dataavail }
207
194
onColor = '#ef9c38'
208
- onHandleColor = '#'
195
+ // onHandleColor='#'
209
196
handleDiameter = { 22 }
210
197
uncheckedIcon = { false }
211
198
checkedIcon = { false }
@@ -227,7 +214,7 @@ const AddJournal = () => {
227
214
onChange = { handleChangePeer }
228
215
checked = { peerreview }
229
216
onColor = '#ef9c38'
230
- onHandleColor = '#'
217
+ // onHandleColor='#'
231
218
handleDiameter = { 22 }
232
219
uncheckedIcon = { false }
233
220
checkedIcon = { false }
@@ -249,7 +236,7 @@ const AddJournal = () => {
249
236
onChange = { handleChangeData2 }
250
237
checked = { datashared }
251
238
onColor = '#ef9c38'
252
- onHandleColor = '#'
239
+ // onHandleColor='#'
253
240
handleDiameter = { 22 }
254
241
uncheckedIcon = { false }
255
242
checkedIcon = { false }
@@ -266,8 +253,9 @@ const AddJournal = () => {
266
253
</ ToggleContainer >
267
254
</ SecondDiv >
268
255
</ Div >
269
- { ! isPending && < FormInputBtn > Add blog</ FormInputBtn > }
270
- { isPending && < FormInputBtn > Adding blog...</ FormInputBtn > }
256
+ < FormInputBtn > Add blog</ FormInputBtn >
257
+ { /* {!isPending && <FormInputBtn>Add blog</FormInputBtn>}
258
+ {isPending && <FormInputBtn>Adding blog...</FormInputBtn>} */ }
271
259
</ Form >
272
260
</ PolicyContainer >
273
261
</ SectionLayout >
0 commit comments