Skip to content

Commit afe567a

Browse files
authored
Merge branch 'development' into development
2 parents bf11172 + 963c61d commit afe567a

File tree

12 files changed

+413
-208
lines changed

12 files changed

+413
-208
lines changed

src/components/AddJournal.js

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* eslint-disable no-alert */
22
import { React, useState } from 'react';
33
import { Row, Col, Form, Button } from 'react-bootstrap';
4+
import { showSuccessMessage, showErrorMessage } from "../helpers/alerts"
5+
import { JournalValidation } from '../helpers/validate';
46

57
function AddJournal() {
68
const [title, setTitle] = useState('');
@@ -13,10 +15,28 @@ function AddJournal() {
1315
const [lastYear, setLastYear] = useState('');
1416
const [policyType, setPolicyType] = useState('');
1517
const [domain, setDomain] = useState('');
18+
const [success,setSuccess] = useState("");
19+
const [error,setError]=useState("");
1620

21+
const emptyFields=()=>{
22+
setTitle("");
23+
setUrl("");
24+
setIssn("");
25+
setRating("");
26+
setDate("");
27+
setPolicyTitle("");
28+
setFirstYear("");
29+
setLastYear("");
30+
setPolicyType("");
31+
setDomain("");
32+
}
1733
const handleSubmit = (e) => {
1834
e.preventDefault();
19-
35+
setSuccess("");
36+
setError("");
37+
const check = JournalValidation(title, url, issn, rating, policyTitle, firstYear,
38+
lastYear, policyType, domain, date)
39+
if(check){
2040
const policies = {
2141
title: policyTitle,
2242
first_year: firstYear,
@@ -25,37 +45,55 @@ function AddJournal() {
2545
};
2646
const journal = { title, url, issn, rating, date, policies, domain };
2747

48+
try{
49+
window.scrollTo(0,0);
2850
fetch('https://journal-policy-tracker.herokuapp.com/api/journals', {
2951
method: 'POST',
3052
headers: { 'Content-Type': 'application/json' },
3153
body: JSON.stringify(journal),
32-
}).then(() => {
33-
alert('Journal added successfully!');
34-
});
54+
})
55+
emptyFields();
56+
setSuccess("Journal Added Successfuly")
57+
}
58+
catch(err)
59+
{
60+
setError("Cannot Add Journal")
61+
}
62+
}
63+
else{
64+
window.scrollTo(0,0);
65+
setError("Invalid Input")
66+
}
67+
3568
};
3669

3770
return (
3871
<Row>
3972
<Col className='m-auto'>
4073
<Form className='login-form responsive' onSubmit={handleSubmit}>
4174
<Form.Group className='mb-3' controlId='formBasicTitle'>
75+
{success && showSuccessMessage(success)}
76+
{error && showErrorMessage(error)}
4277
<Form.Label>Title</Form.Label>
4378
<Form.Control
4479
type='text'
4580
placeholder='Journal title'
4681
onChange={(e) => setTitle(e.target.value)}
82+
value={title}
4783
/>
4884
</Form.Group>
4985
<Form.Group className='mb-3' controlId='formBasicUrl'>
5086
<Form.Label>URL</Form.Label>
51-
<Form.Control type='text' placeholder='URL' onChange={(e) => setUrl(e.target.value)} />
87+
<Form.Control type='text' placeholder='URL'
88+
onChange={(e) => setUrl(e.target.value)} value={url} />
5289
</Form.Group>
5390
<Form.Group className='mb-3' controlId='formBasicIssn'>
5491
<Form.Label>ISSN</Form.Label>
5592
<Form.Control
5693
type='text'
5794
placeholder='ISSN'
5895
onChange={(e) => setIssn(e.target.value)}
96+
value={issn}
5997
/>
6098
</Form.Group>
6199
<Form.Group className='mb-3' controlId='formBasicRating'>
@@ -64,6 +102,7 @@ function AddJournal() {
64102
type='text'
65103
placeholder='Rating'
66104
onChange={(e) => setRating(e.target.value)}
105+
value={rating}
67106
/>
68107
</Form.Group>
69108
<Form.Group className='mb-3' controlId='formBasicDate'>
@@ -72,6 +111,7 @@ function AddJournal() {
72111
type='date'
73112
placeholder='Date'
74113
onChange={(e) => setDate(e.target.value)}
114+
value={date}
75115
/>
76116
</Form.Group>
77117
<Form.Group className='mb-3' controlId='formBasicPolicies'>
@@ -80,21 +120,25 @@ function AddJournal() {
80120
type='text'
81121
placeholder='Policy Title'
82122
onChange={(e) => setPolicyTitle(e.target.value)}
123+
value={policyTitle}
83124
/>
84125
<Form.Control
85126
type='text'
86127
placeholder='First Year'
87128
onChange={(e) => setFirstYear(e.target.value)}
129+
value={firstYear}
88130
/>
89131
<Form.Control
90132
type='text'
91133
placeholder='Last Year'
92134
onChange={(e) => setLastYear(e.target.value)}
135+
value={lastYear}
93136
/>
94137
<Form.Control
95138
type='text'
96139
placeholder='Type'
97140
onChange={(e) => setPolicyType(e.target.value)}
141+
value={policyType}
98142
/>
99143
</Form.Group>
100144
<Form.Group className='mb-3' controlId='formBasicDomain'>
@@ -103,6 +147,7 @@ function AddJournal() {
103147
type='text'
104148
placeholder='Domain'
105149
onChange={(e) => setDomain(e.target.value)}
150+
value={domain}
106151
/>
107152
</Form.Group>
108153
<Button variant='primary' type='submit'>

src/components/Footer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function Footer() {
1111
<Container fluid>
1212
<Row className='footer-above'>
1313
<Col xs={12} md={3}>
14-
<img src={RocketImg} alt='' height={130} width={69} />
14+
<img src={RocketImg} alt='rocket' height={130} width={69} />
1515
</Col>
1616
<Col xs={12} sm={12} md={3}>
1717
<h4>Useful Links</h4>
@@ -55,7 +55,7 @@ function Footer() {
5555
</li>
5656
<li className='footer-link'>
5757
<a href='https://twitter.com/codeisscience' target='_blank' rel='noreferrer'>
58-
<ImTwitter className='twitter-icon icons'/>
58+
<ImTwitter className='twitter-icon icons'/>
5959
&nbsp;Twitter
6060
</a>
6161
</li>

src/components/LandingSection.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function LandingSection() {
1313
<Container>
1414
<Row>
1515
<Col xs={12} sm={12} md={6}>
16-
<Image src={Img} height={342} width={456} alt='' fluid />
16+
<Image src={Img} height={342} width={456} alt= 'people working with laptops' fluid />
1717
</Col>
1818
<Col xs={12} sm={12} md={6}>
1919
<h1>Premise</h1>
@@ -41,7 +41,7 @@ function LandingSection() {
4141
If software is required to perform science, it stands to reason that errors in your
4242
software mean errors in your science.
4343
</p>
44-
<Image src={ClockImg} height={252} width={220} fluid />
44+
<Image src={ClockImg} height={252} width={220} alt='clock' fluid />
4545
</Col>
4646
<Col xs={12} sm={12} md={6}>
4747
<h1>Possible Solution?</h1>
@@ -50,7 +50,7 @@ function LandingSection() {
5050
That’s easier said than done. Getting there requires awareness, culture shift, and
5151
adherence to best practices.
5252
</p>
53-
<Image src={TalkingImg} height={266} width={456} fluid />
53+
<Image src={TalkingImg} height={266} width={456} alt='animated talking girls'fluid />
5454
</Col>
5555
</Row>
5656
</Container>

src/components/Navigation.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ function Navigation() {
1313
bg='light'
1414
variant='light'
1515
style={{ paddingLeft: '30px', paddingRight: '30px' }}
16-
fixed="top"
16+
fixed='top'
1717
>
1818
<Navbar.Brand href='#home'>
19-
<img src={Logo} alt='' srcSet='' height={81} width={150} />
19+
<img src={Logo} alt='code is science' srcSet='' height={81} width={150} />
2020
</Navbar.Brand>
2121
<Navbar.Toggle aria-controls='responsive-navbar-nav' />
2222
<Navbar.Collapse id='responsive-navbar-nav' className='justify-content-evenly'>
2323
<Nav>
2424
<LinkContainer to='/' exact>
25-
<Nav.Link>Home</Nav.Link>
25+
<Nav.Link active={false}>Home</Nav.Link>
2626
</LinkContainer>
2727
<LinkContainer to='/journal' exact>
28-
<Nav.Link>Journals</Nav.Link>
28+
<Nav.Link active={false}>Journals</Nav.Link>
2929
</LinkContainer>
3030
<LinkContainer to='/manifesto' exact>
31-
<Nav.Link>Manifesto</Nav.Link>
31+
<Nav.Link active={false}>Manifesto</Nav.Link>
3232
</LinkContainer>
3333
<LinkContainer to='/contact' exact>
34-
<Nav.Link>Contact</Nav.Link>
34+
<Nav.Link active={false}>Contact</Nav.Link>
3535
</LinkContainer>
3636
<LinkContainer to='/login' exact>
37-
<Nav.Link>Login</Nav.Link>
37+
<Nav.Link active={false}>Login</Nav.Link>
3838
</LinkContainer>
3939
<LinkContainer to='/signup' exact>
40-
<Nav.Link>Sign Up</Nav.Link>
40+
<Nav.Link active={false}>Sign Up</Nav.Link>
4141
</LinkContainer>
4242
</Nav>
4343
<SearchBar />

src/helpers/alerts.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import React from 'react';
2+
3+
export const showSuccessMessage = success => <div className="alert alert-success">{success}</div>;
4+
export const showErrorMessage = error => <div className="alert alert-danger">{error}</div>;

src/helpers/validate.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* eslint-disable-next-line max-len */
2+
// ----------------------------------Journal Validation------------------------------
3+
4+
export const JournalValidation = (title, url, issn, rating, policyTitle,
5+
firstYear, lastYear, policyType, domain, date) =>{
6+
if(title.length<3 || url.length < 5 || issn.length<1 || rating.length<1 ||
7+
date.length<1 || policyTitle.length<1 || firstYear.length<1 || lastYear.length<1 ||
8+
policyType.length<1 || domain.length<1 || !date){
9+
10+
return false
11+
12+
}
13+
14+
return true;
15+
16+
}
17+
18+
// ----------------------------------Signup Validation------------------------------
19+
20+
export const SignupValidation = ({username,email,password}) => {
21+
if(username<1||email<1||password<1)
22+
{
23+
return false;
24+
}
25+
return true;
26+
}
27+
28+
// ----------------------------------Login Validation------------------------------
29+
30+
export const LoginValidation = ({email,password}) => {
31+
if(email<1||password<1)
32+
{
33+
return false;
34+
}
35+
return true;
36+
}

0 commit comments

Comments
 (0)