Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Milestone 1 #45

Merged
merged 140 commits into from Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
6e83d23
Install prisma
nujiak Sep 30, 2022
aadb9b5
Initialize prisma schema
nujiak Sep 30, 2022
6cbe992
Modify PON to contain multiple pictures
nujiak Sep 30, 2022
49f55d3
Add first name and last name columns for users
nujiak Sep 30, 2022
12c7881
Add table for admin users
nujiak Sep 30, 2022
f17cec9
Install typography module
nujiak Sep 30, 2022
22f52dd
Merge pull request #2 from reignnz/dev/hotfix-tailwind-typography
yulonglim Sep 30, 2022
e588cc4
Merge branch 'dev/main' into dev/add-prisma
nujiak Sep 30, 2022
7dd847c
Merge pull request #1 from reignnz/dev/add-prisma
yulonglim Sep 30, 2022
56db55f
Add prisma client
nujiak Sep 30, 2022
76d7c79
Merge pull request #3 from reignnz/dev/prisma-client
yulonglim Sep 30, 2022
1204030
Implement admin creator page
nujiak Sep 30, 2022
601b25f
Merge pull request #4 from reignnz/dev/admin-creator
yulonglim Sep 30, 2022
0d81836
Add password strength checker to admin creator
yulonglim Sep 30, 2022
3c7f214
Install mantine, react and tailwind dependencies
reignnz Sep 30, 2022
d72350e
Configure tailwind
reignnz Sep 30, 2022
9f049dd
Add skeleton layouts
reignnz Sep 30, 2022
b1ff70b
Merge pull request #5 from reignnz/dev/password-strength-meter
nujiak Sep 30, 2022
afbc62c
Merge branch 'dev/main' into dev/layouts
reignnz Sep 30, 2022
f001400
Update yarn file
reignnz Sep 30, 2022
6312840
Change to lowercase
reignnz Sep 30, 2022
50fa855
Merge pull request #6 from reignnz/dev/layouts
yulonglim Sep 30, 2022
7778b62
Add password strength meter to admin creation page
yulonglim Sep 30, 2022
f80f824
remove testid name
yulonglim Sep 30, 2022
1540b4c
Format code style
yulonglim Sep 30, 2022
d811ecc
Merge pull request #7 from reignnz/dev/password-strength-meter
yulonglim Sep 30, 2022
a84c859
Modify user relations to one-to-one
nujiak Sep 30, 2022
765c1e3
Merge pull request #8 from reignnz/dev/user-relation-fix
yulonglim Sep 30, 2022
5d2a157
Update database scheme to cascade on delete
yulonglim Sep 30, 2022
23aa4e8
Merge branch 'dev/main' into dev/login
nujiak Sep 30, 2022
d9c4531
Implement login
nujiak Sep 30, 2022
d989901
Merge pull request #9 from reignnz/dev/login
yulonglim Sep 30, 2022
8f7664f
Add user enrol page
nujiak Oct 1, 2022
9b11854
Fix missing import
nujiak Oct 1, 2022
8395275
Merge pull request #10 from reignnz/dev/user-enrol
yulonglim Oct 1, 2022
4cc88f6
Set dashboard as index page
nujiak Oct 1, 2022
40a17ef
Add first name display to index
nujiak Oct 1, 2022
4445116
Add PON page
reignnz Oct 1, 2022
3331692
Update layouts
reignnz Oct 1, 2022
b963414
Add password reset page
nujiak Oct 1, 2022
e662acd
Merge pull request #12 from reignnz/dev/layouts
yulonglim Oct 1, 2022
169b2f2
Merge branch 'dev/main' into dev/pages
nujiak Oct 1, 2022
72f2269
Change password inputs to PasswordInput
nujiak Oct 1, 2022
c15993e
Merge pull request #11 from reignnz/dev/pages
yulonglim Oct 1, 2022
5cd888d
Add request schema
yulonglim Oct 1, 2022
93c7712
rename user requests column
yulonglim Oct 1, 2022
449305f
Merge pull request #13 from reignnz/dev/request-schema
nujiak Oct 1, 2022
891a1ab
update schema for visibility
yulonglim Oct 1, 2022
951523e
Merge pull request #14 from reignnz/dev/visibility-schema
nujiak Oct 1, 2022
a3965c0
Refactor schema for user roles
nujiak Oct 1, 2022
438d92d
Merge pull request #15 from reignnz/dev/role-schema
yulonglim Oct 1, 2022
84dc809
Implement PON request
nujiak Oct 1, 2022
a6fcbb0
Change superjson from babel to SWC
nujiak Oct 1, 2022
1ec7c76
Add superjson to package.json
nujiak Oct 1, 2022
bfbce23
Merge pull request #16 from reignnz/dev/pon-request
yulonglim Oct 1, 2022
bb479ab
Set fields to optional in PON
nujiak Oct 1, 2022
b736bea
Rename item_descriptions column in PON table
nujiak Oct 1, 2022
88698ca
Merge pull request #17 from reignnz/dev/pon-optional-fields
yulonglim Oct 1, 2022
8c99d33
Add DO dashboard page
reignnz Oct 1, 2022
4e8d9d8
Merge pull request #18 from reignnz/dev/layouts
reignnz Oct 1, 2022
da61202
Implement PON issuing for designated officers
nujiak Oct 1, 2022
bd86904
Update layouts
reignnz Oct 1, 2022
73cc053
Merge pull request #19 from reignnz/dev/pon-issue
yulonglim Oct 1, 2022
3a64441
Merge branch 'dev/main' into dev/layouts
reignnz Oct 1, 2022
6686f96
Install mantine notification
reignnz Oct 1, 2022
d6f10c7
Merge pull request #20 from reignnz/dev/layouts
yulonglim Oct 1, 2022
401a993
Update error handling to include notification
reignnz Oct 1, 2022
d0a6ffa
Merge pull request #21 from reignnz/dev/error-handling
yulonglim Oct 1, 2022
47f066a
Update login page
reignnz Oct 1, 2022
6de469f
Merge pull request #22 from reignnz/dev/layouts
yulonglim Oct 1, 2022
79bbfdf
Implement PON display page
nujiak Oct 1, 2022
bae718c
Improve mobile responsiveness
reignnz Oct 1, 2022
ddd3b04
Update README.md
yulonglim Oct 1, 2022
6b73117
Implement PON editing
nujiak Oct 1, 2022
a332ec1
Merge pull request #23 from reignnz/dev/responsiveness
yulonglim Oct 1, 2022
8bb5762
Remove do/pon
nujiak Oct 1, 2022
711ae4f
Merge pull request #25 from reignnz/dev/README.md
meerian Oct 1, 2022
12be6b2
Fix company name type error
nujiak Oct 1, 2022
dab2460
Remove staff/pon
nujiak Oct 1, 2022
a4c26e1
Merge branch 'dev/main' into dev/pon-editing
nujiak Oct 1, 2022
fb4459f
Merge pull request #24 from reignnz/dev/pon-editing
meerian Oct 1, 2022
9593347
Update enrol page
reignnz Oct 1, 2022
cc620e8
Merge pull request #27 from reignnz/dev/enrol
yulonglim Oct 1, 2022
d811c58
Add color generation for PON number
meerian Oct 1, 2022
049f629
Add box shadow for PON number
meerian Oct 1, 2022
c36c510
Merge pull request #28 from reignnz/dev/pon-number-fix
reignnz Oct 1, 2022
bb22885
Add action chip for DO
reignnz Oct 1, 2022
f9d15b5
Add action chip for Staff
reignnz Oct 1, 2022
1597524
Add modal initial implementation for sharing user
reignnz Oct 1, 2022
265e79d
Merge branch 'dev/main' into dev/pon
reignnz Oct 1, 2022
cdffe59
Merge pull request #29 from reignnz/dev/pon
meerian Oct 2, 2022
3e0ebe1
Reduce authentication cache in session
nujiak Oct 2, 2022
2d790b4
Fix user session usage
nujiak Oct 2, 2022
6726ba5
Merge pull request #30 from reignnz/dev/authentication
meerian Oct 2, 2022
fd6630e
Update actionchip component
reignnz Oct 2, 2022
5545335
Merge pull request #31 from reignnz/dev/pon
meerian Oct 2, 2022
f3e5937
Update admin page
yulonglim Oct 2, 2022
8d93c62
Add custom 404 page
reignnz Oct 2, 2022
47a0431
Update input boxes
yulonglim Oct 2, 2022
2a1ddfb
Merge pull request #33 from reignnz/dev/404
yulonglim Oct 2, 2022
44152e2
Add buttons to enrol and direct to account page
yulonglim Oct 2, 2022
f607a13
Merge pull request #32 from reignnz/dev/admin-page
yulonglim Oct 2, 2022
821e19c
Merge pull request #34 from reignnz/dev/login-page-update
nujiak Oct 2, 2022
afe4fc1
Implment PON sharing
nujiak Oct 2, 2022
d27a268
Merge branch 'dev/main' into dev/pon-share
nujiak Oct 2, 2022
bcf0bf6
Update printable items in pon page
reignnz Oct 2, 2022
d3a9376
Merge pull request #35 from reignnz/dev/pon-share
meerian Oct 2, 2022
14c7b44
Fix styling for page
meerian Oct 2, 2022
e178e82
Merge pull request #37 from reignnz/dev/print
yulonglim Oct 2, 2022
4d29f54
Remove background for login button
meerian Oct 2, 2022
ac52875
Merge pull request #38 from reignnz/dev/page-style
yulonglim Oct 2, 2022
c41549b
Update font
reignnz Oct 2, 2022
bc60d6c
Add Login button animation
yulonglim Oct 2, 2022
4cecea9
Merge pull request #39 from reignnz/dev/fix-font
yulonglim Oct 2, 2022
37b437d
Update icons
reignnz Oct 2, 2022
2f33d7d
Merge pull request #40 from reignnz/dev/login-button
meerian Oct 2, 2022
ac4cb0b
Merge pull request #41 from reignnz/dev/account
meerian Oct 2, 2022
10ae7db
Add company placeholder
reignnz Oct 2, 2022
3c59e3a
Implement PON signing
nujiak Oct 2, 2022
60ca824
Merge branch 'dev/main' into dev/pon-share
nujiak Oct 2, 2022
d4bc2cc
add backnavigation to pages
yulonglim Oct 2, 2022
90a63fd
Adjust UI elements
nujiak Oct 2, 2022
55ebfe3
Merge pull request #43 from reignnz/dev/back-navigation
yulonglim Oct 2, 2022
4bae51e
Adjust PON page
nujiak Oct 2, 2022
f917829
Remove borders from home page
nujiak Oct 2, 2022
c5cf271
Fix status colors
nujiak Oct 2, 2022
560e38b
Add user role icon
reignnz Oct 2, 2022
18400dc
Merge pull request #44 from reignnz/dev/pon-company
meerian Oct 2, 2022
478e6ca
Fix Your PONs heading missing without existing PONs
nujiak Oct 2, 2022
11f2cb6
Merge branch 'dev/main' into dev/pon-share
nujiak Oct 2, 2022
737021f
Merge pull request #42 from reignnz/dev/pon-share
yulonglim Oct 2, 2022
26d37cb
Add back button to PON pages
yulonglim Oct 2, 2022
9aa8e9f
Fix missing imports
yulonglim Oct 2, 2022
1dcedf7
Fix pages missing imports
yulonglim Oct 2, 2022
cc9bd8b
Fix mobile repsonsiveness
reignnz Oct 2, 2022
256636e
Merge pull request #46 from reignnz/dev/pon-backNav
yulonglim Oct 2, 2022
ed23c86
Merge branch 'dev/main' into dev/pon-company
reignnz Oct 2, 2022
946c46e
Merge branch 'dev/main' into dev/pon-company
reignnz Oct 2, 2022
9790a75
Update link target
reignnz Oct 2, 2022
f2b1cca
Merge pull request #47 from reignnz/dev/pon-company
yulonglim Oct 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -34,3 +34,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

# environment variables
**/*.env
89 changes: 69 additions & 20 deletions README.md
@@ -1,34 +1,83 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
# LongKenKaiMy PSA Code Sprint

## Getting Started
[[_TOC_]]

First, run the development server:

```bash
npm run dev
# or
yarn dev
```
This is the repository for the LongKenKaiMy PSA Code Sprint. The code sprint is a 2-day event where participants will work on a project of their choice. The project can be anything from a simple script to a full-fledged application. Our goal is to have fun and learn something new.

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
## Team Members

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
- [Yu Long](https://github.com/yulonglim)
- [Kenneth Chow](https://github.com/reignnz)
- [Kai Jun](https://github.com/nujiak)
- [Myron](https://github.com/meerian)

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
## Project

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
### Project Name:

## Learn More
__PSAccess__ - A website to digitize the process of using Pass Out Note (PON) system in PSA.

To learn more about Next.js, take a look at the following resources:
### Problem Statement

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
Currently, the process of using POS system in PSA is not environmentally sustainable and error-prone. The process involves the following steps:

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
1. Request for PON from a designated officer.
2. Fill up the PON and 2 carbon copies are also required.
3. Submit the PON to a counter signing officer (CSO) for verification and signing.
4. Submit the PON to an AETOS officer for a final verification and archival of the PON

## Deploy on Vercel
The process is error-prone because the PON is a physical document that can be lost or tampered with. The process is also not environmentally sustainable because the PON is a physical document that is printed.

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
### Proposed Solution

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
We propose to digitize the process of using POS system in PSA. The proposed solution involves the following steps:

1. Request for PON from a designated officer on the website.
2. Designated officer will approve the request and the PON will be generated.
3. The PON can be filled up on the website.
4. The PON can be shared to a CSO for verification and signing.
5. The PON can be shared to an AETOS officer for a final verification and archival of the PON.

The proposed solution is less error-prone because the PON is a digital document that can be easily edited and shared. The proposed solution is also more environmentally sustainable because the PON is a digital document that is not printed.

# How To Use

## Prerequisites
- Internet connection is required to use the website.
- Initial setup requires an admin account to be created with sufficiently strong password.

## Initial Setup
1. Got to [PSAccess]() to create an admin account.
2. An admin account is required to create other accounts.
3. Roles of the accounts are as follows:
- Admin: Can create other accounts and view system metrics.
- Staff: Can request for PON or verify and sign PONs.
- Designated Officer (DO): Can issue PONs.
- AETOS Officer (AO): Can verify and archive PONs.

## Requesting for PON
1. Staff can login to the website.
2. Click on the `Request PON` button.
3. Wait for the designated officer to approve the request.

## Issuing PON
1. Designated officer can login to the website.
2. A list of PON requests will be shown.
3. Click on the `Issue PON` button beside the request to issue the PON.

## Filling up the PON
1. Staff can login to the website.
2. The staff can access the issued PON by clicking on the item.
3. There will be text fields for the staff to fill up the PON.
4. Once the PON is filled up, the staff can click on the `Submit` button to submit the PON and wait for the CSO to verify and sign the PON.

## Verifying and Signing PON
1. CSO (another staff) can login to the website.
2. The CSO can access the PON by clicking on the item.
3. The CSO would be able to verify the PON and sign the PON.

## Verifying and Archiving PON
1. AETOS officer can login to the website.
2. The AETOS officer can access the PON by clicking on the item.
3. The AETOS officer would be able to verify the PON and archive the PON.
21 changes: 21 additions & 0 deletions components/BackButton.tsx
@@ -0,0 +1,21 @@
// Make a custom back button component
import React from "react";
import { IoIosArrowBack } from "react-icons/io";
import Link from "next/link";
import { ActionIcon } from "@mantine/core";

export default function BackButton() {
return (
<ActionIcon
type="submit"
variant="transparent"
size="xl"
className="flex items-left justify-left pt-4 mt-4 hover:scale-110 duration-125"
sx={{}}
>
<Link href="/" passHref>
<IoIosArrowBack size={50} className="" color={"black"} />
</Link>
</ActionIcon>
);
}
30 changes: 30 additions & 0 deletions components/CsoActionChip.tsx
@@ -0,0 +1,30 @@
import { Group, Text } from "@mantine/core"
import { HiOutlineCheck, HiOutlineX } from "react-icons/hi"
import { TiArrowBackOutline } from "react-icons/ti"

export enum CsoActionType {
REJECT,
SIGN,
BACK
}

interface CsoActionChipProps {
onClick: () => void,
action: CsoActionType
className?: string
}

export function CsoActionChip({ onClick, action, className }: CsoActionChipProps) {
const mapActionToIcon = (action: CsoActionType) => (
action == CsoActionType.REJECT ? <HiOutlineX /> :
action == CsoActionType.SIGN ? <HiOutlineCheck /> :
<TiArrowBackOutline />)


return (
<Group className={`bg-contain rounded-full text-white px-8 py-3 hover:cursor-pointer ${className}`} onClick={onClick}>
{mapActionToIcon(action)}
<Text>{CsoActionType[action]}</Text>
</Group>
)
}
32 changes: 32 additions & 0 deletions components/StaffActionChip.tsx
@@ -0,0 +1,32 @@
import { AiOutlinePrinter } from "react-icons/ai"
import { BsFillPersonCheckFill, BsJournalCheck, BsShare } from "react-icons/bs"
import { TiArrowBackOutline } from "react-icons/ti"
import { ActionIcon } from "@mantine/core"

export enum staffActionType {
PRINT,
SHARE,
SUBMIT
}

interface StaffActionChipProps {
onClick: () => void,
action: staffActionType,
size?: number
}

export function StaffActionChip({ onClick, action }: StaffActionChipProps) {

const mapActionToIcon = (action: staffActionType) => (
action == staffActionType.PRINT ? <AiOutlinePrinter size={24} /> :
action == staffActionType.SHARE ? <BsShare size={24}/> :
action == staffActionType.SUBMIT ? <BsJournalCheck size={24}/> :
<TiArrowBackOutline size={24}/>
)

return (
<ActionIcon className='bg-white bg-contain rounded-full hover:cursor-pointer drop-shadow-md font-bold' size="xl" onClick={onClick}>
{mapActionToIcon(action)}
</ActionIcon>
)
}
47 changes: 47 additions & 0 deletions components/progressBar.tsx
@@ -0,0 +1,47 @@
import React from "react";
import zxcvbn from "zxcvbn";
import { Progress } from "@mantine/core";

const getPasswordAttrs = (score: number) => {
if (score == 2)
return {
desc: "Fair",
color: "yellow",
};
if (score == 3)
return {
desc: "Good",
color: "green",
};
if (score == 4)
return {
desc: "Strong",
color: "green",
};
return {
desc: "Weak",
color: "red",
};
};

export type PasswordStrengthMeterType = {
password: string;
};

const PasswordStrengthMeter: React.FC<PasswordStrengthMeterType> = ({
password,
}: {
password: string;
}) => {
const { score } = zxcvbn(password); // score: 0 - 4
const { desc, color } = getPasswordAttrs(score);
if (password.length === 0) return null; // don't render if password id empty

return (
<div>
<Progress value={(score / 4) * 100} color={color} />
</div>
);
};

export default PasswordStrengthMeter;
5 changes: 5 additions & 0 deletions global.d.ts
@@ -0,0 +1,5 @@
import { PrismaClient } from "@prisma/client";

declare global {
var prisma: PrismaClient;
}
25 changes: 25 additions & 0 deletions lib/color.ts
@@ -0,0 +1,25 @@
import { createHash } from "crypto";

export function mapToHsl(id:number) {
const hash = createHash('sha256');
hash.update(String(id));
const output = hash.digest().toString('hex');
return (
"hsl(" +
(parseInt(output.slice(0,2), 16) * 360 / 255) + "deg" +
" " +
(parseInt(output.slice(2,3), 16) + 84) + "%" +
" " +
"40%" +
")"
);
}

export enum statusToColor {
REQUESTED = "#0E80EACC",
ISSUED = "#430198CC",
PENDING = "#EA9F0ECC",
SIGNED = "#439801CC",
VERIFIED = "#90730ACC",
ARCHIVED = "#90730ACC",
}
5 changes: 5 additions & 0 deletions lib/hash.ts
@@ -0,0 +1,5 @@
import bcrypt from "bcrypt";

export default function hashPassword(password: string): string {
return bcrypt.hashSync(password, 10);
}
7 changes: 7 additions & 0 deletions lib/password_check.ts
@@ -0,0 +1,7 @@
import zxcvbn from "zxcvbn";

const MIN_STRENGTH = parseInt(process.env.PASSWORD_MIN_STRENGTH!, 10);

export default function validatePassword(password: string): boolean {
return zxcvbn(password).score >= MIN_STRENGTH;
}
14 changes: 14 additions & 0 deletions lib/prisma.ts
@@ -0,0 +1,14 @@
import { PrismaClient } from "@prisma/client";

let prisma: PrismaClient;

if (process.env.NODE_ENV === "production") {
prisma = new PrismaClient();
} else {
if (!global.prisma) {
global.prisma = new PrismaClient();
}
prisma = global.prisma;
}

export default prisma;
15 changes: 15 additions & 0 deletions lib/session.ts
@@ -0,0 +1,15 @@
import type { IronSessionOptions } from "iron-session";

export const sessionOptions: IronSessionOptions = {
cookieName: process.env.SESSION_COOKIE_NAME as string,
password: process.env.SESSION_COOKIE_SECRET as string,
cookieOptions: {
secure: process.env.NODE_ENV === "production",
},
};
// This is where we specify the typings of req.session.*
declare module "iron-session" {
interface IronSessionData {
id: number;
}
}
14 changes: 12 additions & 2 deletions next.config.js
Expand Up @@ -2,6 +2,16 @@
const nextConfig = {
reactStrictMode: true,
swcMinify: true,
}
experimental: {
swcPlugins: [
[
"next-superjson-plugin",
{
excluded: [],
},
],
],
},
};

module.exports = nextConfig
module.exports = nextConfig;