Skip to content

Commit

Permalink
Merge pull request #3 from ucmo-cs/frontend/init
Browse files Browse the repository at this point in the history
(Frontend): init the front end + login page layout
  • Loading branch information
michaelharlow authored Oct 18, 2024
2 parents 4a5ecac + f7e4b00 commit 5cacc9b
Show file tree
Hide file tree
Showing 19 changed files with 436 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/main/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" type="image/png" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<script type="module" src="./src/main.tsx"></script>
</body>
</html>
91 changes: 90 additions & 1 deletion src/main/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/main/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
},
"dependencies": {
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-slot": "^1.1.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.453.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.27.0",
"tailwind-merge": "^2.5.4",
"tailwindcss-animate": "^1.0.7"
},
Expand Down
Binary file added src/main/frontend/public/commerce_globe_45x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/frontend/public/favicon.ico
Binary file not shown.
1 change: 0 additions & 1 deletion src/main/frontend/public/vite.svg

This file was deleted.

101 changes: 82 additions & 19 deletions src/main/frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,87 @@
import { useState } from 'react'
import {Button} from "@/components/ui/button.tsx";
import "@/index.css"
import {useCallback, useEffect, useState} from 'react';
import {Button} from "@/components/ui/button";
import {
Table,
TableBody,
TableCaption,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import "@/index.css";

function App() {
const [count, setCount] = useState(0)

return (
<div className={"flex m-auto w-1/2 h-screen justify-center flex-col items-center"}>
<h1>Vite + React</h1>
<Button onClick={() => setCount((count) => count + 1)} variant={"destructive"}>
count is {count}
</Button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</div>
)
const [accounts, setAccounts] = useState<Account[]>([]);

const getFakeAccounts = useCallback(() => {
fetch("http://localhost:8080/accounts")
.then(response => response.json())
.then(data => setAccounts(data))
.catch(error => console.error(error));
}, [accounts]);

const postFakeAccount = () => {
fetch("http://localhost:8080/account", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"acctId": 12,
"userType": 0,
"username": "test",
"password": "password",
"email": "[email protected]",
"phoneNumber": "123-456-7890",
})
}).then(response => response.json())
.then(data => console.log(data))
.then(() => getFakeAccounts())
.catch(error => console.error(error));
};

useEffect(() => {
console.log("mounted"); // TODO remove

getFakeAccounts();

return () => {
console.log("unmounted"); // TODO remove
}
}, []);

return (
<div className={"flex flex-col items-center"}>
<h1>Commerce Bank Frontend</h1>
<Button className="my-6" onClick={postFakeAccount}>This creates a fake class</Button>
<Table>
<TableCaption>list of Accounts in DB</TableCaption>
<TableHeader>
<TableRow>
<TableHead>Id</TableHead>
<TableHead>Type</TableHead>
<TableHead>username</TableHead>
<TableHead>Password</TableHead>
<TableHead>email</TableHead>
<TableHead>phoneNumber</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{accounts.map((account) => (
<TableRow key={account.acctId}>
<TableCell>{account.acctId}</TableCell>
<TableCell>{account.userType}</TableCell>
<TableCell>{account.username}</TableCell>
<TableCell>{account.password}</TableCell>
<TableCell>{account.email}</TableCell>
<TableCell>{account.phoneNumber}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
)
}

export default App
18 changes: 18 additions & 0 deletions src/main/frontend/src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {Outlet} from "react-router-dom";

function Layout() {
return (
<>
<nav className={"py-3 w-11/12 mx-auto"}>
<div className={"flex items-center bg-commerce-green rounded-full px-2 py-1 nav-shadow"}>
<img src={"/commerce_globe_45x48.png"} alt={"Logo"} />
</div>
</nav>
<div className={"grow flex justify-center items-center"}>
<Outlet />
</div>
</>
);
}

export default Layout;
25 changes: 25 additions & 0 deletions src/main/frontend/src/components/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from "react"

import { cn } from "@/lib/utils"

export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {}

const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
className
)}
ref={ref}
{...props}
/>
)
}
)
Input.displayName = "Input"

export { Input }
24 changes: 24 additions & 0 deletions src/main/frontend/src/components/ui/label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from "react"
import * as LabelPrimitive from "@radix-ui/react-label"
import { cva, type VariantProps } from "class-variance-authority"

import { cn } from "@/lib/utils"

const labelVariants = cva(
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
)

const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants>
>(({ className, ...props }, ref) => (
<LabelPrimitive.Root
ref={ref}
className={cn(labelVariants(), className)}
{...props}
/>
))
Label.displayName = LabelPrimitive.Root.displayName

export { Label }
Loading

0 comments on commit 5cacc9b

Please sign in to comment.