From 2ec449134915787a48d11400faca9d5cd20847f2 Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 11 Dec 2024 00:16:43 +0800 Subject: [PATCH 1/6] Add layout --- packages/frontend/app/admin/login/layout.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 packages/frontend/app/admin/login/layout.tsx diff --git a/packages/frontend/app/admin/login/layout.tsx b/packages/frontend/app/admin/login/layout.tsx new file mode 100644 index 0000000..55d4abc --- /dev/null +++ b/packages/frontend/app/admin/login/layout.tsx @@ -0,0 +1,17 @@ +export default function loginLayout({ + children, + }: { + children: React.ReactNode + }) { + return ( +
+ {children} +
+ ) + } \ No newline at end of file From 94422fee59f752b343445ed52b3509455812aa79 Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 11 Dec 2024 00:17:12 +0800 Subject: [PATCH 2/6] Add file --- packages/frontend/components/Login.tsx | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 packages/frontend/components/Login.tsx diff --git a/packages/frontend/components/Login.tsx b/packages/frontend/components/Login.tsx new file mode 100644 index 0000000..5022b54 --- /dev/null +++ b/packages/frontend/components/Login.tsx @@ -0,0 +1,83 @@ +"use client" + +import { useRouter } from 'next/navigation' +import { useState } from 'react' + +type UserCredentials = { + email: string + password: string +} + +// TODO replace react-form, zod +function isValidUser({ email, password }: UserCredentials): boolean { + const validUsersString = process.env.NEXT_PUBLIC_VALID_USERS + + if (!validUsersString) { + console.error('Environment variable NEXT_PUBLIC_VALID_USERS is not defined') + return false + } + + const validUsers = validUsersString.split(',') + + + return validUsers.some((user) => { + const [validEmail, validPassword] = user.split(':') + return validEmail === email && validPassword === password + }) +} + +const Login = () => { + const [email, setEmail] = useState('') + const [password, setPassword] = useState('') + const [error, setError] = useState('') + const router = useRouter() + + const handleLogin = (e: React.FormEvent) => { + e.preventDefault() + + const credentials: UserCredentials = { email, password } + + if (isValidUser(credentials)) { + localStorage.setItem('isLoggedIn', 'true') + router.push('/admin/dashboard') + } else { + setError('Invalid email or password') + } + } + + return ( +
+
+
+
+ logo +
+
+ + setEmail(e.target.value)} + /> +
+
+ + setPassword(e.target.value)} + /> +
+ + +
+ +
+ {error &&

{error}

} +
+ ) +} + +export default Login From a86d1864ff25ef5879f4e711a55731808de8c984 Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 11 Dec 2024 01:11:15 +0800 Subject: [PATCH 3/6] Move file --- packages/frontend/src/components/Login.tsx | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 packages/frontend/src/components/Login.tsx diff --git a/packages/frontend/src/components/Login.tsx b/packages/frontend/src/components/Login.tsx new file mode 100644 index 0000000..f7f4f1a --- /dev/null +++ b/packages/frontend/src/components/Login.tsx @@ -0,0 +1,83 @@ +"use client" + +import { useRouter } from 'next/navigation' +import { useState } from 'react' + +type UserCredentials = { + email: string + password: string +} + +// TODO replace react-form, zod +function isValidUser({ email, password }: UserCredentials): boolean { + const validUsersString = process.env.NEXT_PUBLIC_VALID_USERS + + if (!validUsersString) { + console.error('Environment variable NEXT_PUBLIC_VALID_USERS is not defined') + return false + } + + const validUsers = validUsersString.split(',') + + + return validUsers.some((user) => { + const [validEmail, validPassword] = user.split(':') + return validEmail === email && validPassword === password + }) +} + +const Login = () => { + const [email, setEmail] = useState('') + const [password, setPassword] = useState('') + const [error, setError] = useState('') + const router = useRouter() + + const handleLogin = (e: React.FormEvent) => { + e.preventDefault() + + const credentials: UserCredentials = { email, password } + + if (isValidUser(credentials)) { + localStorage.setItem('isLoggedIn', 'true') + router.push('/admin/dashboard') + } else { + setError('Invalid email or password') + } + } + + return ( +
+
+
+
+ logo +
+
+ + setEmail(e.target.value)} + /> +
+
+ + setPassword(e.target.value)} + /> +
+ + +
+ +
+ {error &&

{error}

} +
+ ) +} + +export default Login From 6a7da3fe745e2fdcfcac16be0e3e77d3d295a56d Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 11 Dec 2024 01:12:41 +0800 Subject: [PATCH 4/6] Chore: Add spacing and style --- packages/frontend/app/admin/login/layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend/app/admin/login/layout.tsx b/packages/frontend/app/admin/login/layout.tsx index 55d4abc..7ffa567 100644 --- a/packages/frontend/app/admin/login/layout.tsx +++ b/packages/frontend/app/admin/login/layout.tsx @@ -4,7 +4,7 @@ export default function loginLayout({ children: React.ReactNode }) { return ( -
Date: Wed, 11 Dec 2024 01:13:34 +0800 Subject: [PATCH 5/6] Chore: Add spacing and style --- packages/frontend/app/admin/login/page.tsx | 76 ++-------------------- 1 file changed, 5 insertions(+), 71 deletions(-) diff --git a/packages/frontend/app/admin/login/page.tsx b/packages/frontend/app/admin/login/page.tsx index aba5969..578c997 100644 --- a/packages/frontend/app/admin/login/page.tsx +++ b/packages/frontend/app/admin/login/page.tsx @@ -1,75 +1,9 @@ -"use client" - -import { useRouter } from 'next/navigation' -import { useState } from 'react' - -type UserCredentials = { - email: string - password: string -} - -// TODO replace react-form, zod -function isValidUser({ email, password }: UserCredentials): boolean { - const validUsersString = process.env.NEXT_PUBLIC_VALID_USERS - - if (!validUsersString) { - console.error('Environment variable NEXT_PUBLIC_VALID_USERS is not defined') - return false - } - - const validUsers = validUsersString.split(',') - - - return validUsers.some((user) => { - const [validEmail, validPassword] = user.split(':') - return validEmail === email && validPassword === password - }) -} - -const Login = () => { - const [email, setEmail] = useState('') - const [password, setPassword] = useState('') - const [error, setError] = useState('') - const router = useRouter() - - const handleLogin = (e: React.FormEvent) => { - e.preventDefault() - - const credentials: UserCredentials = { email, password } - - if (isValidUser(credentials)) { - localStorage.setItem('isLoggedIn', 'true') - router.push('/admin/dashboard') - } else { - setError('Invalid email or password') - } - } +import Login from "@/src/components/Login"; +export default function Home() { return ( -
-

Admin Login

-
-
- setEmail(e.target.value)} - /> -
-
- setPassword(e.target.value)} - /> -
- -
- {error &&

{error}

} +
+
- ) + ); } - -export default Login From 4dabc06c74dbeb38faa11504550cf3b83e27d37c Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 11 Dec 2024 01:14:10 +0800 Subject: [PATCH 6/6] Fix path --- packages/frontend/tailwind.config.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/frontend/tailwind.config.ts b/packages/frontend/tailwind.config.ts index 86c441d..84a5976 100644 --- a/packages/frontend/tailwind.config.ts +++ b/packages/frontend/tailwind.config.ts @@ -4,7 +4,7 @@ export default { content: [ "./src/pages/**/*.{js,ts,jsx,tsx,mdx}", "./src/components/**/*.{js,ts,jsx,tsx,mdx}", - "./src/app/**/*.{js,ts,jsx,tsx,mdx}", + "./app/**/*.{js,ts,jsx,tsx,mdx}", ], theme: { extend: { @@ -14,7 +14,9 @@ export default { "letter-grey": "#8D8D8B", "stroke-line": "#8B8484", "yellow-cta": "#F6C114", - "black-text": "1E1E1E" + "black-text": '1E1E1E', + 'nav-bg': '#1E1E1E', + 'nav-bg-hover': '#8D8D8B' }, fontFamily: { "bebas-neue": ['Bebas Neue', 'sans-serif'],