Skip to content

Commit 77875f2

Browse files
committed
feat: frontend finished (i think)
1 parent cf9b38b commit 77875f2

6 files changed

Lines changed: 121 additions & 14 deletions

File tree

onlineshop/source/client/src/App.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import React from 'react';
22

33
import './App.css';
44
import { Button, Grid2, TextField } from '@mui/material';
5-
import getProjects from './components/getProjects';
6-
import getUsers from './components/getUsers';
75
import deleteUser from './components/deleteUser';
86
import deleteProject from './components/deleteProject';
97
import CreateProjectForm from './components/createProject';
108
import CreateUserForm from './components/createUser';
119
import UpdateProjectForm from './components/updateProject';
1210
import UpdateUserForm from './components/updateUser';
11+
import UserList from './components/showUsers';
12+
import ProjectList from './components/showProjects';
1313

1414
const App: React.FC = () => (
1515
<div className="App" style={{paddingTop: 30}}>
@@ -19,31 +19,35 @@ const App: React.FC = () => (
1919
<div style={{paddingBottom: 10}}>
2020
<TextField defaultValue="-1" id="user_id" label="Outlined" variant="outlined"/>
2121
</div>
22-
<div style={{paddingBottom: 10}}>
23-
<Button variant="contained" onClick={getUsers}>Get all users</Button>
24-
</div>
2522
<div style={{paddingBottom: 10}}>
2623
<Button variant="contained" onClick={deleteUser}>Delete User</Button>
2724
</div>
2825
<div style={{paddingBottom: 10}}>
29-
<CreateUserForm/>
26+
<CreateUserForm/>
27+
</div>
28+
<div style={{paddingBottom: 10}}>
29+
<UpdateUserForm/>
30+
</div>
31+
<div style={{paddingBottom: 10}}>
32+
<UserList/>
3033
</div>
31-
<UpdateUserForm/>
3234
</Grid2>
3335
<Grid2>
3436
<div style={{paddingBottom: 10}}>
3537
<TextField defaultValue='-1' id="project_id" label="Outlined" variant="outlined"/>
3638
</div>
37-
<div style={{paddingBottom: 10}}>
38-
<Button variant="contained" onClick={getProjects}>Get all projects</Button>
39-
</div>
4039
<div style={{paddingBottom: 10}}>
4140
<Button variant="contained" onClick={deleteProject}>Delete Project</Button>
4241
</div>
4342
<div style={{paddingBottom: 10}}>
4443
<CreateProjectForm/>
4544
</div>
46-
<UpdateProjectForm/>
45+
<div style={{paddingBottom: 10}}>
46+
<UpdateProjectForm/>
47+
</div>
48+
<div style={{paddingBottom: 10}}>
49+
<ProjectList/>
50+
</div>
4751
</Grid2>
4852
</Grid2>
4953
</div>

onlineshop/source/client/src/components/getProjects.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default async function getProjects() {
3131
}
3232
console.log(JSON.stringify(data.data, null, 4));
3333
console.log('response status is: ', data.status);
34-
return data;
34+
return data.data;
3535
}
3636
catch (error) {
3737
if (axios.isAxiosError(error)) {

onlineshop/source/client/src/components/getUsers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default async function getUsers() {
3030
}
3131
console.log(JSON.stringify(data.data, null, 4));
3232
console.log('response status is: ', data.status);
33-
return data;
33+
return data.data;
3434
}
3535
catch (error) {
3636
if (axios.isAxiosError(error)) {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { useState } from 'react';
2+
import { Typography, List, ListItem, Button } from '@mui/material';
3+
import React from 'react';
4+
import { project } from '../types/project';
5+
import getProjects from './getProjects';
6+
7+
export default function ProjectList(){
8+
const [projects, setProjects] = useState<project[]>([]);
9+
const [error, setError] = useState<string | null>(null);
10+
11+
const handleLoadProjects = async () => {
12+
const result = await getProjects();
13+
14+
if (Array.isArray(result)) {
15+
setProjects(result);
16+
setError(null);
17+
} else if (typeof result === 'object' && result !== null && 'id' in result) {
18+
setProjects([result as unknown as project]);
19+
setError(null);
20+
} else {
21+
setError(String(result));
22+
setProjects([]);
23+
}
24+
};
25+
return (
26+
<div>
27+
<Button variant="contained" onClick={handleLoadProjects} style={{marginBottom: 10}}>
28+
Get Users
29+
</Button>
30+
<Typography variant="h5" gutterBottom>List of Projects</Typography>
31+
32+
{error && <Typography color="error">{error}</Typography>}
33+
34+
{projects.length === 0 && !error && (
35+
<Typography color="text.secondary">Empty list</Typography>
36+
)}
37+
38+
<List>
39+
{projects.map((project) => (
40+
<ListItem key={project.id} alignItems="flex-start">
41+
<div>
42+
<Typography variant="subtitle1"><strong>ID:</strong> {project.id}</Typography>
43+
<Typography variant="body2"><strong>NAME:</strong> {project.projectName}</Typography>
44+
<Typography variant="body2"><strong>DESC:</strong> {project.desription}</Typography>
45+
<Typography variant="body2"><strong>CREATOR:</strong> {project.user?.login ?? "Unknown user"}</Typography>
46+
</div>
47+
</ListItem>
48+
))}
49+
</List>
50+
</div>
51+
);
52+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { useState } from 'react';
2+
import { User } from '../types/user';
3+
import getUsers from './getUsers';
4+
import { Typography, List, ListItem, Button } from '@mui/material';
5+
import React from 'react';
6+
7+
export default function UserList(){
8+
const [users, setUsers] = useState<User[]>([]);
9+
const [error, setError] = useState<string | null>(null);
10+
11+
const handleLoadUsers = async () => {
12+
const result = await getUsers();
13+
14+
if (Array.isArray(result)) {
15+
setUsers(result);
16+
setError(null);
17+
} else if (typeof result === 'object' && result !== null && 'id' in result) {
18+
setUsers([result as unknown as User]);
19+
setError(null);
20+
} else {
21+
setError(String(result));
22+
setUsers([]);
23+
}
24+
};
25+
return (
26+
<div>
27+
<Button variant="contained" onClick={handleLoadUsers} style={{marginBottom: 10}}>
28+
Get Users
29+
</Button>
30+
<Typography variant="h5" gutterBottom>List of Users</Typography>
31+
32+
{error && <Typography color="error">{error}</Typography>}
33+
34+
{users.length === 0 && !error && (
35+
<Typography color="text.secondary">Empty list</Typography>
36+
)}
37+
38+
<List>
39+
{users.map((user) => (
40+
<ListItem key={user.id} alignItems="flex-start">
41+
<div>
42+
<Typography variant="subtitle1"><strong>ID:</strong> {user.id}</Typography>
43+
<Typography variant="body2"><strong>NICKNAME:</strong> {user.nickname}</Typography>
44+
<Typography variant="body2"><strong>EMAIL:</strong> {user.email}</Typography>
45+
</div>
46+
</ListItem>
47+
))}
48+
</List>
49+
</div>
50+
);
51+
}

onlineshop/source/client/src/types/project.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { User } from "./user";
33
export type project = {
44
id: number,
55
projectName: string,
6-
description: string,
6+
desription: string,
77
feeAmount: number,
88
alreadyCollected: number,
99
user: User,

0 commit comments

Comments
 (0)