Skip to content

Commit 446a56c

Browse files
committed
create-journals
1 parent df4fe85 commit 446a56c

File tree

10 files changed

+395
-245
lines changed

10 files changed

+395
-245
lines changed

src/App.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ const errorLink = onError(({ graphqlErrors, networkError }) => {
2828
}
2929
});
3030

31-
const link = from([errorLink, new HttpLink({ uri: 'http://localhost:4000/graphql' })]);
31+
const link = from([
32+
errorLink,
33+
new HttpLink({ uri: 'http://localhost:4000/graphql', credentials: 'include' }),
34+
]);
3235

3336
const client = new ApolloClient({
3437
cache: new InMemoryCache(),
38+
// credentials: 'include',
3539
link,
3640
});
3741

@@ -53,7 +57,7 @@ function App() {
5357
<Route exact path='/addjournal'>
5458
<AddJournal />
5559
</Route>
56-
<Route path='/edit/:id'>
60+
<Route path='/edit/:issn'>
5761
<Edit />
5862
</Route>
5963
<Route path='/policy/:issn'>

src/components/AddJournal/AddJournal.js

Lines changed: 99 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { useHistory } from 'react-router-dom';
99
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
1010
import { faBookmark } from '@fortawesome/free-solid-svg-icons';
1111
import Switch from 'react-switch';
12+
import { useMutation } from '@apollo/client';
13+
import CREATE_JOURNAL from '../../graphql/mutation/createJournal';
1214
import {
1315
Container,
1416
Head,
@@ -30,130 +32,113 @@ import { useGlobalContext } from '../../context/DataContext';
3032
import { SectionLayout, PolicyContainer } from '../marginals';
3133

3234
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+
5388
return (
5489
<SectionLayout>
5590
<PolicyContainer>
5691
<Head>Create Journal Policies</Head>
57-
<Form onSubmit={handleSubmit}>
92+
<Form onSubmit={addJournal}>
5893
<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)} />
7095
<FirstDiv>
7196
<div>
7297
<Label>Journal Type</Label>
7398
<Input
7499
type='text'
75100
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)}
83103
/>
84104
</div>
85105
<div>
86106
<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)} />
98108
</div>
99109
<div>
100110
<Label>Enforced Evidence</Label>
101111
<Input
102112
type='text'
103113
required
104114
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)}
111116
/>
112117
</div>
113118
</FirstDiv>
114119
<FirstDiv>
115-
<div>
120+
{/* <div>
116121
<Label>Domain</Label>
117122
<Input
118123
type='text'
119124
required
120125
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)}
127127
/>
128-
</div>
128+
</div> */}
129129
<div>
130130
<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)} />
142132
</div>
143-
<div>
133+
{/* <div>
144134
<Label>Authors</Label>
145135
<Input
146136
type='text'
147137
required
148138
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)}
155140
/>
156-
</div>
141+
</div> */}
157142
</FirstDiv>
158143
<Subhead>
159144
<Icon>
@@ -163,35 +148,37 @@ const AddJournal = () => {
163148
</Subhead>
164149
<Div>
165150
<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>
166169
<div>
167170
<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>
180175
</Select>
181176
</div>
182177
<div>
183178
<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>
195182
</Select>
196183
</div>
197184
</SecondDiv>
@@ -205,7 +192,7 @@ const AddJournal = () => {
205192
onChange={handleChangeData}
206193
checked={dataavail}
207194
onColor='#ef9c38'
208-
onHandleColor='#'
195+
// onHandleColor='#'
209196
handleDiameter={22}
210197
uncheckedIcon={false}
211198
checkedIcon={false}
@@ -227,7 +214,7 @@ const AddJournal = () => {
227214
onChange={handleChangePeer}
228215
checked={peerreview}
229216
onColor='#ef9c38'
230-
onHandleColor='#'
217+
// onHandleColor='#'
231218
handleDiameter={22}
232219
uncheckedIcon={false}
233220
checkedIcon={false}
@@ -249,7 +236,7 @@ const AddJournal = () => {
249236
onChange={handleChangeData2}
250237
checked={datashared}
251238
onColor='#ef9c38'
252-
onHandleColor='#'
239+
// onHandleColor='#'
253240
handleDiameter={22}
254241
uncheckedIcon={false}
255242
checkedIcon={false}
@@ -266,8 +253,9 @@ const AddJournal = () => {
266253
</ToggleContainer>
267254
</SecondDiv>
268255
</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>} */}
271259
</Form>
272260
</PolicyContainer>
273261
</SectionLayout>

0 commit comments

Comments
 (0)