2024-09-04 17:09:46 -05:00
|
|
|
import React, { useState, useEffect } from "react";
|
|
|
|
import { TabView, TabPanel } from "primereact/tabview";
|
|
|
|
import UserProfile from "@/components/profile/UserProfile";
|
2024-08-06 14:50:32 -05:00
|
|
|
import UserContent from "@/components/profile/UserContent";
|
2024-09-01 16:31:47 -05:00
|
|
|
import UserSubscription from "@/components/profile/subscription/UserSubscription";
|
2024-09-04 17:09:46 -05:00
|
|
|
import { useRouter } from "next/router";
|
2024-09-11 16:48:56 -05:00
|
|
|
import { useSession } from "next-auth/react";
|
|
|
|
import { useIsAdmin } from "@/hooks/useIsAdmin";
|
|
|
|
import { ProgressSpinner } from "primereact/progressspinner";
|
2024-02-11 16:26:33 -06:00
|
|
|
|
2025-03-27 13:23:39 -05:00
|
|
|
//todo: Link below connect wallet, relays hidden in ... (open modal)
|
2024-02-11 16:26:33 -06:00
|
|
|
const Profile = () => {
|
2024-09-04 17:09:46 -05:00
|
|
|
const router = useRouter();
|
2024-09-11 16:48:56 -05:00
|
|
|
const { data: session, status } = useSession();
|
2024-09-04 17:09:46 -05:00
|
|
|
const [activeTab, setActiveTab] = useState(0);
|
2024-09-11 16:48:56 -05:00
|
|
|
const {isAdmin, isLoading} = useIsAdmin();
|
|
|
|
|
2025-03-28 10:59:52 -05:00
|
|
|
const tabs = ["profile", "content", "subscribe"];
|
2024-08-06 19:52:06 -05:00
|
|
|
|
2024-08-09 19:00:31 -05:00
|
|
|
useEffect(() => {
|
2024-09-04 17:09:46 -05:00
|
|
|
const { tab } = router.query;
|
|
|
|
if (tab) {
|
|
|
|
const index = tabs.indexOf(tab.toLowerCase());
|
|
|
|
if (index !== -1) {
|
|
|
|
setActiveTab(index);
|
|
|
|
}
|
2024-08-08 16:29:16 -05:00
|
|
|
}
|
2024-09-04 17:09:46 -05:00
|
|
|
}, [router.query]);
|
2024-08-08 16:29:16 -05:00
|
|
|
|
2024-09-11 16:48:56 -05:00
|
|
|
useEffect(() => {
|
|
|
|
if (status === 'unauthenticated') {
|
|
|
|
router.push('/auth/signin');
|
|
|
|
}
|
|
|
|
}, [status, router]);
|
|
|
|
|
2024-09-04 17:09:46 -05:00
|
|
|
const onTabChange = (e) => {
|
|
|
|
const newIndex = e.index;
|
|
|
|
setActiveTab(newIndex);
|
|
|
|
router.push(`/profile?tab=${tabs[newIndex]}`, undefined, { shallow: true });
|
2024-08-30 19:37:13 -05:00
|
|
|
};
|
|
|
|
|
2024-09-11 16:48:56 -05:00
|
|
|
if (status === 'loading' || isLoading) {
|
|
|
|
return (
|
2024-09-17 13:28:58 -05:00
|
|
|
<div className='w-full h-full flex items-center justify-center'><ProgressSpinner /></div>
|
2024-09-11 16:48:56 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status === 'unauthenticated') {
|
|
|
|
router.push('/auth/signin');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!session) return null;
|
|
|
|
|
2024-08-08 16:29:16 -05:00
|
|
|
return (
|
2025-03-29 12:37:55 -05:00
|
|
|
<div className="w-full min-h-full mx-auto px-10 max-mob:px-2">
|
2024-09-04 17:09:46 -05:00
|
|
|
<TabView
|
|
|
|
pt={{
|
|
|
|
root: {
|
|
|
|
className: "bg-transparent",
|
|
|
|
},
|
|
|
|
panelContainer: {
|
|
|
|
className: "bg-transparent m-0 p-0"
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
onTabChange={onTabChange}
|
|
|
|
activeIndex={activeTab}
|
|
|
|
>
|
|
|
|
<TabPanel header="Profile" pt={{
|
|
|
|
headerAction: {
|
|
|
|
className: "bg-transparent"
|
|
|
|
},
|
|
|
|
}}>
|
|
|
|
<UserProfile />
|
|
|
|
</TabPanel>
|
2024-09-11 16:48:56 -05:00
|
|
|
{isAdmin && (
|
|
|
|
<TabPanel header="Content" pt={{
|
|
|
|
headerAction: {
|
2024-09-04 17:09:46 -05:00
|
|
|
className: "bg-transparent"
|
|
|
|
},
|
|
|
|
}}>
|
2024-09-11 16:48:56 -05:00
|
|
|
<UserContent />
|
|
|
|
</TabPanel>
|
|
|
|
)}
|
2024-09-04 17:09:46 -05:00
|
|
|
<TabPanel header="Subscribe" pt={{
|
|
|
|
headerAction: {
|
|
|
|
className: "bg-transparent"
|
|
|
|
},
|
|
|
|
}}>
|
|
|
|
<UserSubscription />
|
|
|
|
</TabPanel>
|
|
|
|
</TabView>
|
|
|
|
</div>
|
2024-08-08 16:29:16 -05:00
|
|
|
);
|
2024-08-06 14:50:32 -05:00
|
|
|
};
|
2024-02-11 16:26:33 -06:00
|
|
|
|
2024-08-06 14:50:32 -05:00
|
|
|
export default Profile;
|