ENCOA-128: Display the position of the Corporate in the topbar
This commit is contained in:
@@ -1,219 +1,163 @@
|
|||||||
import { User } from "@/interfaces/user";
|
import {User} from "@/interfaces/user";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import FocusLayer from "@/components/FocusLayer";
|
import FocusLayer from "@/components/FocusLayer";
|
||||||
import { preventNavigation } from "@/utils/navigation.disabled";
|
import {preventNavigation} from "@/utils/navigation.disabled";
|
||||||
import { useRouter } from "next/router";
|
import {useRouter} from "next/router";
|
||||||
import { BsList, BsQuestionCircle, BsQuestionCircleFill } from "react-icons/bs";
|
import {BsList, BsQuestionCircle, BsQuestionCircleFill} from "react-icons/bs";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import MobileMenu from "./MobileMenu";
|
import MobileMenu from "./MobileMenu";
|
||||||
import { useEffect, useState } from "react";
|
import {useEffect, useState} from "react";
|
||||||
import { Type } from "@/interfaces/user";
|
import {Type} from "@/interfaces/user";
|
||||||
import { USER_TYPE_LABELS } from "@/resources/user";
|
import {USER_TYPE_LABELS} from "@/resources/user";
|
||||||
import useGroups from "@/hooks/useGroups";
|
import useGroups from "@/hooks/useGroups";
|
||||||
import { isUserFromCorporate } from "@/utils/groups";
|
import {isUserFromCorporate} from "@/utils/groups";
|
||||||
import Button from "./Low/Button";
|
import Button from "./Low/Button";
|
||||||
import Modal from "./Modal";
|
import Modal from "./Modal";
|
||||||
import Input from "./Low/Input";
|
import Input from "./Low/Input";
|
||||||
import TicketSubmission from "./High/TicketSubmission";
|
import TicketSubmission from "./High/TicketSubmission";
|
||||||
import { Module } from "@/interfaces";
|
import {Module} from "@/interfaces";
|
||||||
import Badge from "./Low/Badge";
|
import Badge from "./Low/Badge";
|
||||||
|
|
||||||
import {
|
import {BsArrowRepeat, BsBook, BsCheck, BsCheckCircle, BsClipboard, BsHeadphones, BsMegaphone, BsPen, BsXCircle} from "react-icons/bs";
|
||||||
BsArrowRepeat,
|
|
||||||
BsBook,
|
|
||||||
BsCheck,
|
|
||||||
BsCheckCircle,
|
|
||||||
BsClipboard,
|
|
||||||
BsHeadphones,
|
|
||||||
BsMegaphone,
|
|
||||||
BsPen,
|
|
||||||
BsXCircle,
|
|
||||||
} from "react-icons/bs";
|
|
||||||
interface Props {
|
interface Props {
|
||||||
user: User;
|
user: User;
|
||||||
navDisabled?: boolean;
|
navDisabled?: boolean;
|
||||||
focusMode?: boolean;
|
focusMode?: boolean;
|
||||||
onFocusLayerMouseEnter?: () => void;
|
onFocusLayerMouseEnter?: () => void;
|
||||||
path: string;
|
path: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable @next/next/no-img-element */
|
/* eslint-disable @next/next/no-img-element */
|
||||||
export default function Navbar({
|
export default function Navbar({user, path, navDisabled = false, focusMode = false, onFocusLayerMouseEnter}: Props) {
|
||||||
user,
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||||
path,
|
const [disablePaymentPage, setDisablePaymentPage] = useState(true);
|
||||||
navDisabled = false,
|
const [isTicketOpen, setIsTicketOpen] = useState(false);
|
||||||
focusMode = false,
|
|
||||||
onFocusLayerMouseEnter,
|
|
||||||
}: Props) {
|
|
||||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
|
||||||
const [disablePaymentPage, setDisablePaymentPage] = useState(true);
|
|
||||||
const [isTicketOpen, setIsTicketOpen] = useState(false);
|
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const disableNavigation = preventNavigation(navDisabled, focusMode);
|
const disableNavigation = preventNavigation(navDisabled, focusMode);
|
||||||
|
|
||||||
const expirationDateColor = (date: Date) => {
|
const expirationDateColor = (date: Date) => {
|
||||||
const momentDate = moment(date);
|
const momentDate = moment(date);
|
||||||
const today = moment(new Date());
|
const today = moment(new Date());
|
||||||
|
|
||||||
if (today.add(1, "days").isAfter(momentDate))
|
if (today.add(1, "days").isAfter(momentDate)) return "!bg-mti-red-ultralight border-mti-red-light";
|
||||||
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(3, "days").isAfter(momentDate))
|
if (today.add(7, "days").isAfter(momentDate)) return "!bg-mti-orange-ultralight border-mti-orange-light";
|
||||||
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 = () => {
|
const showExpirationDate = () => {
|
||||||
if (!user.subscriptionExpirationDate) return false;
|
if (!user.subscriptionExpirationDate) return false;
|
||||||
|
|
||||||
const momentDate = moment(user.subscriptionExpirationDate);
|
const momentDate = moment(user.subscriptionExpirationDate);
|
||||||
const today = moment(new Date());
|
const today = moment(new Date());
|
||||||
|
|
||||||
return today.add(7, "days").isAfter(momentDate);
|
return today.add(7, "days").isAfter(momentDate);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user.type !== "student" && user.type !== "teacher")
|
if (user.type !== "student" && user.type !== "teacher") return setDisablePaymentPage(false);
|
||||||
return setDisablePaymentPage(false);
|
isUserFromCorporate(user.id).then((result) => setDisablePaymentPage(result));
|
||||||
isUserFromCorporate(user.id).then((result) =>
|
}, [user]);
|
||||||
setDisablePaymentPage(result)
|
|
||||||
);
|
|
||||||
}, [user]);
|
|
||||||
|
|
||||||
const badges = [
|
const badges = [
|
||||||
{
|
{
|
||||||
module: "reading",
|
module: "reading",
|
||||||
icon: () => <BsBook className="h-4 w-4 text-white" />,
|
icon: () => <BsBook className="h-4 w-4 text-white" />,
|
||||||
achieved: user.levels.reading >= user.desiredLevels.reading,
|
achieved: user.levels.reading >= user.desiredLevels.reading,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
module: "listening",
|
module: "listening",
|
||||||
icon: () => <BsHeadphones className="h-4 w-4 text-white" />,
|
icon: () => <BsHeadphones className="h-4 w-4 text-white" />,
|
||||||
achieved: user.levels.listening >= user.desiredLevels.listening,
|
achieved: user.levels.listening >= user.desiredLevels.listening,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
module: "writing",
|
module: "writing",
|
||||||
icon: () => <BsPen className="h-4 w-4 text-white" />,
|
icon: () => <BsPen className="h-4 w-4 text-white" />,
|
||||||
achieved: user.levels.writing >= user.desiredLevels.writing,
|
achieved: user.levels.writing >= user.desiredLevels.writing,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
module: "speaking",
|
module: "speaking",
|
||||||
icon: () => <BsMegaphone className="h-4 w-4 text-white" />,
|
icon: () => <BsMegaphone className="h-4 w-4 text-white" />,
|
||||||
achieved: user.levels.speaking >= user.desiredLevels.speaking,
|
achieved: user.levels.speaking >= user.desiredLevels.speaking,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
module: "level",
|
module: "level",
|
||||||
icon: () => <BsClipboard className="h-4 w-4 text-white" />,
|
icon: () => <BsClipboard className="h-4 w-4 text-white" />,
|
||||||
achieved: user.levels.level >= user.desiredLevels.level,
|
achieved: user.levels.level >= user.desiredLevels.level,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Modal
|
<Modal isOpen={isTicketOpen} onClose={() => setIsTicketOpen(false)} title="Submit a ticket">
|
||||||
isOpen={isTicketOpen}
|
<TicketSubmission user={user} page={router.asPath} onClose={() => setIsTicketOpen(false)} />
|
||||||
onClose={() => setIsTicketOpen(false)}
|
</Modal>
|
||||||
title="Submit a ticket"
|
|
||||||
>
|
|
||||||
<TicketSubmission
|
|
||||||
user={user}
|
|
||||||
page={router.asPath}
|
|
||||||
onClose={() => setIsTicketOpen(false)}
|
|
||||||
/>
|
|
||||||
</Modal>
|
|
||||||
|
|
||||||
{user && (
|
{user && (
|
||||||
<MobileMenu
|
<MobileMenu disableNavigation={disableNavigation} path={path} isOpen={isMenuOpen} onClose={() => setIsMenuOpen(false)} user={user} />
|
||||||
disableNavigation={disableNavigation}
|
)}
|
||||||
path={path}
|
<header className="-md:justify-between -md:px-4 relative flex w-full items-center bg-transparent py-2 md:gap-12 md:py-4">
|
||||||
isOpen={isMenuOpen}
|
<Link href={disableNavigation ? "" : "/"} className=" flex items-center gap-8 md:px-8">
|
||||||
onClose={() => setIsMenuOpen(false)}
|
<img src="/logo.png" alt="EnCoach's Logo" className="w-8 md:w-12" />
|
||||||
user={user}
|
<h1 className="-md:hidden w-1/6 text-2xl font-bold">EnCoach</h1>
|
||||||
/>
|
</Link>
|
||||||
)}
|
<div className="flex items-center justify-end gap-4 md:mr-8 md:w-5/6">
|
||||||
<header className="-md:justify-between -md:px-4 relative flex w-full items-center bg-transparent py-2 md:gap-12 md:py-4">
|
{user.type === "student" &&
|
||||||
<Link
|
badges.map((badge) => (
|
||||||
href={disableNavigation ? "" : "/"}
|
<div
|
||||||
className=" flex items-center gap-8 md:px-8"
|
key={badge.module}
|
||||||
>
|
className={`${
|
||||||
<img src="/logo.png" alt="EnCoach's Logo" className="w-8 md:w-12" />
|
badge.achieved ? `bg-ielts-${badge.module}` : "bg-mti-gray-anti-flash"
|
||||||
<h1 className="-md:hidden w-1/6 text-2xl font-bold">EnCoach</h1>
|
} flex h-8 w-8 items-center justify-center rounded-full`}>
|
||||||
</Link>
|
{badge.icon()}
|
||||||
<div className="flex items-center justify-end gap-4 md:mr-8 md:w-5/6">
|
</div>
|
||||||
{user.type === "student" &&
|
))}
|
||||||
badges.map((badge) => (
|
{/* OPEN TICKET SYSTEM */}
|
||||||
<div
|
<button
|
||||||
key={badge.module}
|
className={clsx(
|
||||||
className={`${badge.achieved ? `bg-ielts-${badge.module}`: 'bg-mti-gray-anti-flash'} flex h-8 w-8 items-center justify-center rounded-full`}
|
"border-mti-purple-light tooltip tooltip-bottom flex h-8 w-8 flex-col items-center justify-center rounded-full border p-1",
|
||||||
>
|
"hover:bg-mti-purple-light transition duration-300 ease-in-out hover:text-white z-20",
|
||||||
{badge.icon()}
|
)}
|
||||||
</div>
|
data-tip="Submit a help/feedback ticket"
|
||||||
))}
|
onClick={() => setIsTicketOpen(true)}>
|
||||||
{/* OPEN TICKET SYSTEM */}
|
<BsQuestionCircleFill />
|
||||||
<button
|
</button>
|
||||||
className={clsx(
|
|
||||||
"border-mti-purple-light tooltip tooltip-bottom flex h-8 w-8 flex-col items-center justify-center rounded-full border p-1",
|
|
||||||
"hover:bg-mti-purple-light transition duration-300 ease-in-out hover:text-white z-20"
|
|
||||||
)}
|
|
||||||
data-tip="Submit a help/feedback ticket"
|
|
||||||
onClick={() => setIsTicketOpen(true)}
|
|
||||||
>
|
|
||||||
<BsQuestionCircleFill />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{showExpirationDate() && (
|
{showExpirationDate() && (
|
||||||
<Link
|
<Link
|
||||||
href={
|
href={!!user.subscriptionExpirationDate && !disablePaymentPage ? "/payment" : ""}
|
||||||
!!user.subscriptionExpirationDate && !disablePaymentPage
|
data-tip="Expiry date"
|
||||||
? "/payment"
|
className={clsx(
|
||||||
: ""
|
"flex w-fit cursor-pointer justify-center rounded-full border px-6 py-2 text-sm font-normal focus:outline-none",
|
||||||
}
|
"tooltip tooltip-bottom transition duration-300 ease-in-out",
|
||||||
data-tip="Expiry date"
|
!user.subscriptionExpirationDate
|
||||||
className={clsx(
|
? "bg-mti-green-ultralight border-mti-green-light"
|
||||||
"flex w-fit cursor-pointer justify-center rounded-full border px-6 py-2 text-sm font-normal focus:outline-none",
|
: expirationDateColor(user.subscriptionExpirationDate),
|
||||||
"tooltip tooltip-bottom transition duration-300 ease-in-out",
|
"border-mti-gray-platinum bg-white",
|
||||||
!user.subscriptionExpirationDate
|
)}>
|
||||||
? "bg-mti-green-ultralight border-mti-green-light"
|
{!user.subscriptionExpirationDate && "Unlimited"}
|
||||||
: expirationDateColor(user.subscriptionExpirationDate),
|
{user.subscriptionExpirationDate && moment(user.subscriptionExpirationDate).format("DD/MM/YYYY")}
|
||||||
"border-mti-gray-platinum bg-white"
|
</Link>
|
||||||
)}
|
)}
|
||||||
>
|
<Link href={disableNavigation ? "" : "/profile"} className="-md:hidden flex items-center justify-end gap-6">
|
||||||
{!user.subscriptionExpirationDate && "Unlimited"}
|
<img src={user.profilePicture} alt={user.name} className="h-10 w-10 rounded-full object-cover" />
|
||||||
{user.subscriptionExpirationDate &&
|
<span className="-md:hidden text-right">
|
||||||
moment(user.subscriptionExpirationDate).format("DD/MM/YYYY")}
|
{user.type === "corporate" ? `${user.corporateInformation?.companyInformation.name} |` : ""} {user.name} |{" "}
|
||||||
</Link>
|
{USER_TYPE_LABELS[user.type]}
|
||||||
)}
|
{user.type === "corporate" &&
|
||||||
<Link
|
!!user.demographicInformation?.position &&
|
||||||
href={disableNavigation ? "" : "/profile"}
|
` | ${user.demographicInformation?.position || "N/A"}`}
|
||||||
className="-md:hidden flex items-center justify-end gap-6"
|
</span>
|
||||||
>
|
</Link>
|
||||||
<img
|
<div className="cursor-pointer md:hidden" onClick={() => setIsMenuOpen(true)}>
|
||||||
src={user.profilePicture}
|
<BsList className="text-mti-purple-light h-8 w-8" />
|
||||||
alt={user.name}
|
</div>
|
||||||
className="h-10 w-10 rounded-full object-cover"
|
</div>
|
||||||
/>
|
{focusMode && <FocusLayer onFocusLayerMouseEnter={onFocusLayerMouseEnter} />}
|
||||||
<span className="-md:hidden text-right">
|
</header>
|
||||||
{user.type === "corporate"
|
</>
|
||||||
? `${user.corporateInformation?.companyInformation.name} |`
|
);
|
||||||
: ""}{" "}
|
|
||||||
{user.name} | {USER_TYPE_LABELS[user.type]}
|
|
||||||
</span>
|
|
||||||
</Link>
|
|
||||||
<div
|
|
||||||
className="cursor-pointer md:hidden"
|
|
||||||
onClick={() => setIsMenuOpen(true)}
|
|
||||||
>
|
|
||||||
<BsList className="text-mti-purple-light h-8 w-8" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{focusMode && (
|
|
||||||
<FocusLayer onFocusLayerMouseEnter={onFocusLayerMouseEnter} />
|
|
||||||
)}
|
|
||||||
</header>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user