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

initiated the frontend #1

Merged
merged 4 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
715 changes: 687 additions & 28 deletions frontend/package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
"preview": "vite preview"
},
"dependencies": {
"@emotion/react": "^11.11.3",
"@mui/material": "^5.15.4",
"axios": "^1.6.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-router-dom": "^6.21.1"
},
"devDependencies": {
"@types/react": "^18.2.43",
Expand Down
37 changes: 9 additions & 28 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
import InstructorApp from "./components/InstructorApp.tsx";
import {Route, Routes} from "react-router-dom";

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

return (
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
return (
<Routes>
<Route path="/instructors" element={<InstructorApp />}/>
</Routes>
)
}

export default App


35 changes: 35 additions & 0 deletions frontend/src/components/InstructorApp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

import {Instructor} from "../models/Instructor.ts";
import {useEffect, useState} from "react";
import axios from "axios";


export default function InstructorApp(){
const [instructors, setInstructors]=useState<Instructor[]>([])
const fetchData=() =>
axios.get("/api/instructors")
.then(response =>{
setInstructors(response.data)
console.log(instructors)
}
)
.catch(error =>
console.log(error.message)
)
useEffect(() => {
fetchData()
},[]
)

return(
<>
<h1>Instructor List</h1>
<ul>
{instructors.map((instructor) => (
<li key={instructor.id}>{instructor.firstName},{instructor.lastName},{instructor.email},{instructor.phoneNumber}</li>

))}
</ul>
</>
)
}
5 changes: 4 additions & 1 deletion frontend/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
import {BrowserRouter} from "react-router-dom";

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
<BrowserRouter>
<App/>
</BrowserRouter>
</React.StrictMode>,
)
10 changes: 10 additions & 0 deletions frontend/src/models/Instructor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {Qualification} from "./Qualification.ts";

export type Instructor={
id: string,
firstName: string,
lastName: string,
email: string,
phoneNumber: string,
qualification: Qualification,
}
9 changes: 9 additions & 0 deletions frontend/src/models/InstructorDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {Qualification} from "./Qualification.ts";

export type InstructorDto={
firstName: string,
lastName: string,
email: string,
phoneNumber: string,
qualification: Qualification,
}
6 changes: 6 additions & 0 deletions frontend/src/models/Qualification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type Qualification={
isSkiInstructor:boolean,
isSnowboardInstructor:boolean,
isNordicSkiInstructor:boolean,
isHikingGuide:boolean
}