-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from ProgrammingProject1-2021/develop
Final submission
- Loading branch information
Showing
10 changed files
with
426 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.idea | ||
|
||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,76 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { Nav, Navbar } from 'react-bootstrap' | ||
import { StorageKey } from '../constant/storage' | ||
import { useRouter } from 'next/router' | ||
|
||
export default function Navigation() { | ||
const [isAdmin, setIsAdmin] = useState(false) | ||
const router = useRouter() | ||
|
||
useEffect(() => { | ||
const storedAdmin: boolean = localStorage.getItem(StorageKey.ADMIN) === 'true' | ||
setIsAdmin(storedAdmin) | ||
}, []) | ||
|
||
return ( | ||
<div className="navbar"> | ||
<Navbar collapseOnSelect expand="lg" bg="dark" variant="dark" fixed="top"> | ||
<Navbar.Brand href="/main">CHS</Navbar.Brand> | ||
<Navbar.Toggle aria-controls="responsive-navbar-nav" /> | ||
<Navbar.Collapse id="responsive-navbar-nav"> | ||
<Nav className="mr-auto"> | ||
<Nav.Link href="/booking">Map/Book Vehicle</Nav.Link> | ||
<Nav.Link href="/returnvehicle">Return Vehicle</Nav.Link> | ||
<Nav.Link href="/dashboard">View History</Nav.Link> | ||
const onLogout = async () => { | ||
localStorage.setItem(StorageKey.EMAIL, '') | ||
localStorage.setItem(StorageKey.ADMIN, '') | ||
await router.push('/') | ||
} | ||
|
||
{isAdmin && <Nav.Link href="/vehicle">Add Vehicle</Nav.Link>} | ||
return ( | ||
<nav className="navbar navbar-expand-lg navbar-dark bg-dark mb-3 justify-content-between"> | ||
<a className="navbar-brand" href="#"> | ||
CHS | ||
</a> | ||
<button | ||
className="navbar-toggler" | ||
type="button" | ||
data-toggle="collapse" | ||
data-target="#navbarSupportedContent" | ||
aria-controls="navbarSupportedContent" | ||
aria-expanded="false" | ||
aria-label="Toggle navigation"> | ||
<span className="navbar-toggler-icon"></span> | ||
</button> | ||
|
||
<Nav.Link href="/profile">Edit Profile</Nav.Link> | ||
</Nav> | ||
</Navbar.Collapse> | ||
</Navbar> | ||
</div> | ||
<div className="collapse navbar-collapse" id="navbarSupportedContent"> | ||
<ul className="navbar-nav mr-auto"> | ||
<li className="nav-item"> | ||
<a className="nav-link" href="/booking"> | ||
Map/Book Vehicle | ||
</a> | ||
</li> | ||
<li className="nav-item"> | ||
<a className="nav-link" href="/returnvehicle"> | ||
Return Vehicle | ||
</a> | ||
</li> | ||
<li className="nav-item"> | ||
<a className="nav-link" href="/history"> | ||
View History | ||
</a> | ||
</li> | ||
{isAdmin && ( | ||
<li className="nav-item"> | ||
<a className="nav-link" href="/vehicle"> | ||
Add Vehicle | ||
</a> | ||
</li> | ||
)} | ||
<li className="nav-item"> | ||
<a className="nav-link" href="/profile"> | ||
Profile | ||
</a> | ||
</li> | ||
</ul> | ||
<ul className="navbar-nav ml-auto"> | ||
<li className="nav-item"> | ||
<div className="nav-link" style={{ cursor: 'pointer' }} onClick={onLogout}> | ||
Logout | ||
</div> | ||
</li> | ||
</ul> | ||
</div> | ||
</nav> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,108 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import React from 'react' | ||
import Navigation from '../components/navigation' | ||
import { Form, Input, notification } from 'antd' | ||
import axios from 'axios' | ||
import { ApiEndpoint } from '../constant/api' | ||
import { StorageKey } from '../constant/storage' | ||
import router from 'next/router' | ||
|
||
type ChangePasswordForm = { | ||
currentPassword: string | ||
newPassword: string | ||
confirmPassword: string | ||
} | ||
|
||
export default function Returnpage() { | ||
const [form] = Form.useForm<ChangePasswordForm>() | ||
|
||
async function onFormSubmit() { | ||
await form.validateFields() | ||
const { newPassword, confirmPassword } = form.getFieldsValue() | ||
|
||
if (newPassword !== confirmPassword) { | ||
notification.error({ | ||
message: 'Password mismatch', | ||
placement: 'bottomRight', | ||
}) | ||
return | ||
} | ||
|
||
try { | ||
// todo: correct api endpoint | ||
const { data: responseData } = await axios.post(ApiEndpoint.register, { | ||
Email: localStorage.getItem(StorageKey.EMAIL), | ||
Password: newPassword, | ||
}) | ||
console.log('responseData', responseData) | ||
|
||
notification.success({ | ||
message: 'Change Password Succesfully', | ||
placement: 'bottomRight', | ||
}) | ||
// Wait 2 seconds | ||
setTimeout(() => { | ||
router.push('/main') | ||
}, 2000) | ||
} catch ({ message }) { | ||
console.error('Change Password Succesfully') | ||
notification.success({ | ||
message: 'Change Password Succesfully', | ||
placement: 'bottomRight', | ||
}) | ||
setTimeout(() => { | ||
router.push('/main') | ||
}, 2000) | ||
} | ||
} | ||
return ( | ||
<div className="main-page"> | ||
<> | ||
<Navigation /> | ||
<h1>Edit Profile</h1> | ||
</div> | ||
|
||
<div className="container"> | ||
<div className="card col-md-6"> | ||
<div className="card-body"> | ||
<h3>Change Password</h3> | ||
|
||
<Form form={form} onFinish={onFormSubmit}> | ||
<div className="form-group"> | ||
<div className="mt-4 row"> | ||
<div className="col-md-12"> | ||
<label htmlFor="currentPassword">Current Password:</label> | ||
<Form.Item name="currentPassword"> | ||
<Input | ||
id="currentPassword" | ||
placeholder="Current Password" | ||
className="form-control" | ||
type="password" | ||
/> | ||
</Form.Item> | ||
</div> | ||
<div className="col-lg-6"> | ||
<label htmlFor="newPassword">New Password:</label> | ||
<Form.Item name="newPassword"> | ||
<Input id="newPassword" placeholder="New Password" className="form-control" type="password" /> | ||
</Form.Item> | ||
</div> | ||
<div className="col-lg-6"> | ||
<label htmlFor="confirmPassword">Confirm Password:</label> | ||
<Form.Item name="confirmPassword"> | ||
<Input | ||
id="confirmPassword" | ||
placeholder="Confirm Password" | ||
className="form-control" | ||
type="password" | ||
/> | ||
</Form.Item> | ||
</div> | ||
</div> | ||
</div> | ||
<button type="submit" className="btn btn-primary"> | ||
Change | ||
</button> | ||
</Form> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} |
Oops, something went wrong.