feat: created UserPage.tsx
This commit is contained in:
parent
827431bb2f
commit
fd0ca4411b
3 changed files with 160 additions and 34 deletions
|
|
@ -1,39 +1,8 @@
|
|||
import React, { useEffect, useState } from "react";
|
||||
import { DefaultService } from "./api/services/DefaultService"; // adjust path if needed
|
||||
import type { User } from "./api/models/User"; // adjust path if needed
|
||||
import React from "react";
|
||||
import UserPage from "./components/UserPage/UserPage";
|
||||
|
||||
const App: React.FC = () => {
|
||||
const [user, setUser] = useState<User | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const getUserInfo = async () => {
|
||||
try {
|
||||
const userInfo = await DefaultService.getUsers("1", "all");
|
||||
setUser(userInfo);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
setError("Failed to fetch user info.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
getUserInfo();
|
||||
}, []);
|
||||
|
||||
if (loading) return <div>Loading...</div>;
|
||||
if (error) return <div>{error}</div>;
|
||||
if (!user) return <div>No user found.</div>;
|
||||
|
||||
return (
|
||||
<div style={{ padding: "2rem" }}>
|
||||
<h1>User Info</h1>
|
||||
<p><strong>ID:</strong> {user.user_id}</p>
|
||||
<p><strong>Name:</strong> {user.nickname}</p>
|
||||
<p><strong>Email:</strong> {user.mail}</p>
|
||||
</div>
|
||||
);
|
||||
return <UserPage />;
|
||||
};
|
||||
|
||||
export default App;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue