gistfile1.txt
· 1.6 KiB · Text
Bruto
import { useEffect, useState } from 'react';
import UserPage from '@/components/Global/User';
import { NextSeo } from "next-seo";
export default function UserProfilePage({ url }) {
const [userData, setUserData] = useState(null);
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
useEffect(() => {
const fetchData = async () => {
try {
const response = await fetch(`${apiUrl}/v1/entity/${url}`);
if (response.ok) {
const data = await response.json();
setUserData(data.data);
} else {
console.error('Failed to fetch user data');
}
} catch (error) {
console.error('Error fetching user data:', error);
}
};
fetchData();
}, [apiUrl, url]);
return (
<>
<NextSeo
title="Profile"
description="View the selected user's profile"
openGraph={{
images: [
{
url: `https://cdn.dscinflux.xyz/assets/png/influx.png`,
width: 800,
height: 600,
alt: "Influx Logo",
},
],
}}
twitter={{
cardType: "summary",
}}
/>
<div>
{/* Render the UserPage component with fetched userData */}
{userData && <UserPage data={userData} />}
</div>
</>
);
}
// This function will be called at build time
export async function getServerSideProps(ctx) {
// Extract the user URL from the context
const { url } = ctx.query;
// Pass the user URL as a prop to the component
return {
props: {
url
}
};
}
1 | import { useEffect, useState } from 'react'; |
2 | import UserPage from '@/components/Global/User'; |
3 | import { NextSeo } from "next-seo"; |
4 | |
5 | export default function UserProfilePage({ url }) { |
6 | const [userData, setUserData] = useState(null); |
7 | const apiUrl = process.env.NEXT_PUBLIC_API_URL; |
8 | |
9 | useEffect(() => { |
10 | const fetchData = async () => { |
11 | try { |
12 | const response = await fetch(`${apiUrl}/v1/entity/${url}`); |
13 | if (response.ok) { |
14 | const data = await response.json(); |
15 | setUserData(data.data); |
16 | } else { |
17 | console.error('Failed to fetch user data'); |
18 | } |
19 | } catch (error) { |
20 | console.error('Error fetching user data:', error); |
21 | } |
22 | }; |
23 | |
24 | fetchData(); |
25 | }, [apiUrl, url]); |
26 | |
27 | return ( |
28 | <> |
29 | <NextSeo |
30 | title="Profile" |
31 | |
32 | description="View the selected user's profile" |
33 | |
34 | openGraph={{ |
35 | images: [ |
36 | { |
37 | url: `https://cdn.dscinflux.xyz/assets/png/influx.png`, |
38 | width: 800, |
39 | height: 600, |
40 | alt: "Influx Logo", |
41 | }, |
42 | ], |
43 | }} |
44 | twitter={{ |
45 | cardType: "summary", |
46 | }} |
47 | /> |
48 | <div> |
49 | {/* Render the UserPage component with fetched userData */} |
50 | {userData && <UserPage data={userData} />} |
51 | </div> |
52 | </> |
53 | ); |
54 | } |
55 | |
56 | // This function will be called at build time |
57 | export async function getServerSideProps(ctx) { |
58 | // Extract the user URL from the context |
59 | const { url } = ctx.query; |
60 | |
61 | // Pass the user URL as a prop to the component |
62 | return { |
63 | props: { |
64 | url |
65 | } |
66 | }; |
67 | } |
68 |