diff --git a/src/components/profile/SubscribeModal.js b/src/components/profile/subscription/SubscribeModal.js similarity index 100% rename from src/components/profile/SubscribeModal.js rename to src/components/profile/subscription/SubscribeModal.js diff --git a/src/components/profile/subscription/UserSubscription.js b/src/components/profile/subscription/UserSubscription.js new file mode 100644 index 0000000..5fe1b43 --- /dev/null +++ b/src/components/profile/subscription/UserSubscription.js @@ -0,0 +1,106 @@ +import React, { useState, useRef, useEffect } from "react"; +import { Button } from "primereact/button"; +import { Menu } from "primereact/menu"; +import { Message } from "primereact/message"; +import { Card } from "primereact/card"; +import SubscribeModal from "@/components/profile/subscription/SubscribeModal"; + +const UserSubscription = ({ user }) => { + const [subscribeModalVisible, setSubscribeModalVisible] = useState(false); + const [subscribed, setSubscribed] = useState(false); + const [subscribedUntil, setSubscribedUntil] = useState(null); + const [subscriptionExpiredAt, setSubscriptionExpiredAt] = useState(null); + const menu = useRef(null); + + useEffect(() => { + if (user && user.role) { + setSubscribed(user.role.subscribed); + const subscribedAt = new Date(user.role.lastPaymentAt); + const subscribedUntil = new Date(subscribedAt.getTime() + 31 * 24 * 60 * 60 * 1000); + setSubscribedUntil(subscribedUntil); + if (user.role.subscriptionExpiredAt) { + const expiredAt = new Date(user.role.subscriptionExpiredAt) + setSubscriptionExpiredAt(expiredAt); + } + } + }, [user]); + + const menuItems = [ + { + label: "Renew Subscription", + icon: "pi pi-bolt", + command: () => { + // Add your edit functionality here + }, + }, + { + label: "Schedule 1:1", + icon: "pi pi-calendar", + command: () => { + // Add your edit functionality here + }, + }, + { + label: "Cancel Subscription", + icon: "pi pi-trash", + command: () => { + // Add your delete functionality here + }, + }, + ]; + + const openSubscribeModal = () => { + setSubscribeModalVisible(true); + }; + + const subscriptionCardTitle = ( +
+ Plebdevs Subscription + menu.current.toggle(e)} + > + +
+ ); + + return ( + <> + + {subscribed && ( +
+ +

Thank you for your support 🎉

+

Pay-as-you-go subscription will renew on {subscribedUntil.toLocaleDateString()}

+
+ )} + {(!subscribed && !subscriptionExpiredAt) && ( +
+ +
+ )} + {subscriptionExpiredAt && ( +
+ +
+ )} +
+ setSubscribeModalVisible(false)} + /> + + ); +}; + +export default UserSubscription; diff --git a/src/pages/profile.js b/src/pages/profile.js index 7469d29..e5a0cf2 100644 --- a/src/pages/profile.js +++ b/src/pages/profile.js @@ -4,6 +4,7 @@ import { DataTable } from "primereact/datatable"; import { Menu } from "primereact/menu"; import { Column } from "primereact/column"; import { Message } from "primereact/message"; +import { Card } from "primereact/card"; import { useImageProxy } from "@/hooks/useImageProxy"; import { useSession } from 'next-auth/react'; import { ProgressSpinner } from "primereact/progressspinner"; @@ -13,34 +14,18 @@ import { formatDateTime } from "@/utils/time"; import UserContent from "@/components/profile/UserContent"; import Image from "next/image"; import BitcoinConnectButton from "@/components/bitcoinConnect/BitcoinConnect"; -import SubscribeModal from "@/components/profile/SubscribeModal"; +import UserSubscription from "@/components/profile/subscription/UserSubscription"; const Profile = () => { const [user, setUser] = useState(null); - const [subscribeModalVisible, setSubscribeModalVisible] = useState(false); // Add this state - const [subscribed, setSubscribed] = useState(false); - const [subscribedUntil, setSubscribedUntil] = useState(null); - const [subscriptionExpiredAt, setSubscriptionExpiredAt] = useState(null); - const { data: session } = useSession(); const { returnImageProxy } = useImageProxy(); const { ndk } = useNDKContext(); const menu = useRef(null); useEffect(() => { - if (session && session.user) { + if (session?.user) { setUser(session.user); - if (session.user.role) { - setSubscribed(session.user.role.subscribed); - const subscribedAt = new Date(session.user.role.lastPaymentAt); - // The user is subscribed until the date in subscribedAt + 31 days - const subscribedUntil = new Date(subscribedAt.getTime() + 31 * 24 * 60 * 60 * 1000); - setSubscribedUntil(subscribedUntil); - if (session.user.role.subscriptionExpiredAt) { - const expiredAt = new Date(session.user.role.subscriptionExpiredAt) - setSubscriptionExpiredAt(expiredAt); - } - } } }, [session]); @@ -71,6 +56,17 @@ const Profile = () => { setSubscribeModalVisible(true); }; + const subscriptionCardTitle = ( +
+ Plebdevs Subscription + menu.current.toggle(e)} + > + +
+ ); + return ( user && (
@@ -100,35 +96,9 @@ const Profile = () => {

Connect Your Lightning Wallet

-
- {subscribed && ( - <> - -

Thank you for your support 🎉

-

Pay-as-you-go subscription will renew on {subscribedUntil.toLocaleDateString()}

- - )} - {(!subscribed && !subscriptionExpiredAt) && ( - <> - -
+ {user && ( + + )} {!session || !session?.user || !ndk ? ( @@ -153,11 +123,6 @@ const Profile = () => { )} - setSubscribeModalVisible(false)} - /> - ) ); diff --git a/src/styles/globals.css b/src/styles/globals.css index a43cb6c..f3f7026 100644 --- a/src/styles/globals.css +++ b/src/styles/globals.css @@ -25,6 +25,14 @@ h3 { @apply text-h3 font-blinker; } +p { + @apply font-blinker; +} + +div { + @apply font-blinker; +} + .p-tabmenu .p-tabmenu-nav { background-color: transparent !important; border: none !important;