Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions src/components/Login/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React, { useState } from 'react';
import Swal from 'sweetalert2';

const Login = ({ setIsAuthenticated }) => {
const adminEmail = '[email protected]';
const adminPassword = 'qwerty';

const [email, setEmail] = useState('[email protected]');
const [password, setPassword] = useState('qwerty');

const handleLogin = e => {
e.preventDefault();

if (email === adminEmail && password === adminPassword) {
Swal.fire({
timer: 1500,
showConfirmButton: false,
willOpen: () => {
Swal.showLoading();
},
willClose: () => {
localStorage.setItem('is_authenticated', true);
setIsAuthenticated(true);

Swal.fire({
icon: 'success',
title: 'Successfully logged in!',
showConfirmButton: false,
timer: 1500,
});
},
});
} else {
Swal.fire({
timer: 1500,
showConfirmButton: false,
willOpen: () => {
Swal.showLoading();
},
willClose: () => {
Swal.fire({
icon: 'error',
title: 'Error!',
text: 'Incorrect email or password.',
showConfirmButton: true,
});
},
});
}
};

return (
<div className="small-container">
<form onSubmit={handleLogin}>
<h1>Admin Login</h1>
<label htmlFor="email">Email</label>
<input
id="email"
type="email"
name="email"
placeholder="[email protected]"
value={email}
onChange={e => setEmail(e.target.value)}
/>
<label htmlFor="password">Password</label>
<input
id="password"
type="password"
name="password"
placeholder="qwerty"
value={password}
onChange={e => setPassword(e.target.value)}
/>
<input style={{ marginTop: '12px' }} type="submit" value="Login" />
</form>
</div>
);
};

export default Login;