diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx
index 77e9672a..9972f84e 100644
--- a/src/components/Navbar.tsx
+++ b/src/components/Navbar.tsx
@@ -6,6 +6,8 @@ import {useRouter} from "next/router";
import axios from "axios";
import {RiLogoutBoxFill} from "react-icons/ri";
import {BsPower} from "react-icons/bs";
+import clsx from "clsx";
+import moment from "moment";
interface Props {
user: User;
@@ -19,10 +21,22 @@ export default function Navbar({user, navDisabled = false, focusMode = false, on
const disableNavigation = preventNavigation(navDisabled, focusMode);
const router = useRouter();
- const logout = async () => {
- axios.post("/api/logout").finally(() => {
- setTimeout(() => router.reload(), 500);
- });
+ const expirationDateColor = (date: Date) => {
+ const momentDate = moment(date);
+ const today = moment(new Date());
+
+ if (today.add(1, "days").isAfter(momentDate)) return "!bg-mti-red-ultralight border-mti-red-light";
+ if (today.add(3, "days").isAfter(momentDate)) return "!bg-mti-rose-ultralight border-mti-rose-light";
+ if (today.add(7, "days").isAfter(momentDate)) return "!bg-mti-orange-ultralight border-mti-orange-light";
+ };
+
+ const showExpirationDate = () => {
+ if (!user.subscriptionExpirationDate) return false;
+
+ const momentDate = moment(user.subscriptionExpirationDate);
+ const today = moment(new Date());
+
+ return today.add(7, "days").isAfter(momentDate);
};
return (
@@ -31,12 +45,23 @@ export default function Navbar({user, navDisabled = false, focusMode = false, on
EnCoach
-
-
+
+ {showExpirationDate() && (
+
+ {!user.subscriptionExpirationDate && "Unlimited"}
+ {user.subscriptionExpirationDate && moment(user.subscriptionExpirationDate).format("DD/MM/YYYY")}
+
+ )}
{user.name}
diff --git a/src/pages/profile.tsx b/src/pages/profile.tsx
index cb8e3b9d..61451bc8 100644
--- a/src/pages/profile.tsx
+++ b/src/pages/profile.tsx
@@ -18,6 +18,7 @@ import countryCodes from "country-codes-list";
import {countries, TCountries} from "countries-list";
import CountrySelect from "@/components/Low/CountrySelect";
import {shouldRedirectHome} from "@/utils/navigation.disabled";
+import moment from "moment";
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
const user = req.session.user;
@@ -67,6 +68,15 @@ export default function Home() {
const {user, mutateUser} = useUser({redirectTo: "/login"});
+ const expirationDateColor = (date: Date) => {
+ const momentDate = moment(date);
+ const today = moment(new Date());
+
+ if (today.add(1, "days").isAfter(momentDate)) return "!bg-mti-red-ultralight border-mti-red-light";
+ if (today.add(3, "days").isAfter(momentDate)) return "!bg-mti-rose-ultralight border-mti-rose-light";
+ if (today.add(7, "days").isAfter(momentDate)) return "!bg-mti-orange-ultralight border-mti-orange-light";
+ };
+
useEffect(() => {
if (user) {
setName(user.name);
@@ -237,52 +247,70 @@ export default function Home() {
))}
-
-
-
-
- {({checked}) => (
-
- Male
-
- )}
-
-
- {({checked}) => (
-
- Female
-
- )}
-
-
- {({checked}) => (
-
- Other
-
- )}
-
-
+
+
+
+
+
+ {({checked}) => (
+
+ Male
+
+ )}
+
+
+ {({checked}) => (
+
+ Female
+
+ )}
+
+
+ {({checked}) => (
+
+ Other
+
+ )}
+
+
+
+
+
+
+ {!user.subscriptionExpirationDate && "Unlimited"}
+ {user.subscriptionExpirationDate && moment(user.subscriptionExpirationDate).format("DD/MM/YYYY")}
+
+