ranveersoni98 revised this gist . Go to revision
1 file changed, 67 insertions
gistfile1.txt(file created)
@@ -0,0 +1,67 @@ | |||
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 | + | } |
Newer
Older