Initial approach where I replaced all the entries for checkAccess
This commit is contained in:
@@ -16,6 +16,7 @@ import ShortUniqueId from "short-unique-id";
|
||||
import Button from "../Low/Button";
|
||||
import Input from "../Low/Input";
|
||||
import Select from "../Low/Select";
|
||||
import { checkAccess } from "@/utils/permissions";
|
||||
|
||||
interface Props {
|
||||
user: User;
|
||||
@@ -137,13 +138,13 @@ export default function TicketDisplay({ user, ticket, onClose }: Props) {
|
||||
options={[
|
||||
{ value: "me", label: "Assign to me" },
|
||||
...users
|
||||
.filter((x) => ["admin", "developer", "agent"].includes(x.type))
|
||||
.filter((x) => checkAccess(x, ["admin", "developer", "agent"]))
|
||||
.map((u) => ({
|
||||
value: u.id,
|
||||
label: `${u.name} - ${u.email}`,
|
||||
})),
|
||||
]}
|
||||
disabled={user.type === "agent"}
|
||||
disabled={checkAccess(user, ["agent"])}
|
||||
value={
|
||||
assignedTo
|
||||
? {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import {User} from "@/interfaces/user";
|
||||
import {Dialog, Transition} from "@headlessui/react";
|
||||
import { User } from "@/interfaces/user";
|
||||
import { Dialog, Transition } from "@headlessui/react";
|
||||
import axios from "axios";
|
||||
import clsx from "clsx";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import {useRouter} from "next/router";
|
||||
import {Fragment} from "react";
|
||||
import {BsXLg} from "react-icons/bs";
|
||||
import { useRouter } from "next/router";
|
||||
import { Fragment } from "react";
|
||||
import { BsXLg } from "react-icons/bs";
|
||||
import { checkAccess, getTypesOfUser } from "@/utils/permissions";
|
||||
|
||||
interface Props {
|
||||
isOpen: boolean;
|
||||
@@ -16,7 +17,13 @@ interface Props {
|
||||
disableNavigation?: boolean;
|
||||
}
|
||||
|
||||
export default function MobileMenu({isOpen, onClose, path, user, disableNavigation}: Props) {
|
||||
export default function MobileMenu({
|
||||
isOpen,
|
||||
onClose,
|
||||
path,
|
||||
user,
|
||||
disableNavigation,
|
||||
}: Props) {
|
||||
const router = useRouter();
|
||||
|
||||
const logout = async () => {
|
||||
@@ -35,7 +42,8 @@ export default function MobileMenu({isOpen, onClose, path, user, disableNavigati
|
||||
enterTo="opacity-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0">
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<div className="fixed inset-0 bg-black bg-opacity-25" />
|
||||
</Transition.Child>
|
||||
|
||||
@@ -48,14 +56,30 @@ export default function MobileMenu({isOpen, onClose, path, user, disableNavigati
|
||||
enterTo="opacity-100 scale-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100 scale-100"
|
||||
leaveTo="opacity-0 scale-95">
|
||||
leaveTo="opacity-0 scale-95"
|
||||
>
|
||||
<Dialog.Panel className="flex h-screen w-full transform flex-col gap-8 overflow-hidden bg-white text-left align-middle text-black shadow-xl transition-all">
|
||||
<Dialog.Title as="header" className="-md:flex w-full items-center justify-between px-8 py-2 shadow-sm md:hidden">
|
||||
<Dialog.Title
|
||||
as="header"
|
||||
className="-md:flex w-full items-center justify-between px-8 py-2 shadow-sm md:hidden"
|
||||
>
|
||||
<Link href={disableNavigation ? "" : "/"}>
|
||||
<Image src="/logo_title.png" alt="EnCoach logo" width={69} height={69} />
|
||||
<Image
|
||||
src="/logo_title.png"
|
||||
alt="EnCoach logo"
|
||||
width={69}
|
||||
height={69}
|
||||
/>
|
||||
</Link>
|
||||
<div className="cursor-pointer" onClick={onClose} tabIndex={0}>
|
||||
<BsXLg className="text-mti-purple-light text-2xl" onClick={onClose} />
|
||||
<div
|
||||
className="cursor-pointer"
|
||||
onClick={onClose}
|
||||
tabIndex={0}
|
||||
>
|
||||
<BsXLg
|
||||
className="text-mti-purple-light text-2xl"
|
||||
onClick={onClose}
|
||||
/>
|
||||
</div>
|
||||
</Dialog.Title>
|
||||
<div className="flex h-full flex-col gap-6 px-8 text-lg">
|
||||
@@ -63,18 +87,22 @@ export default function MobileMenu({isOpen, onClose, path, user, disableNavigati
|
||||
href={disableNavigation ? "" : "/"}
|
||||
className={clsx(
|
||||
"w-fit transition duration-300 ease-in-out",
|
||||
path === "/" && "text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold ",
|
||||
)}>
|
||||
path === "/" &&
|
||||
"text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold "
|
||||
)}
|
||||
>
|
||||
Dashboard
|
||||
</Link>
|
||||
{(user.type === "student" || user.type === "teacher" || user.type === "developer") && (
|
||||
{checkAccess(user, ["student", "teacher", "developer"]) && (
|
||||
<>
|
||||
<Link
|
||||
href={disableNavigation ? "" : "/exam"}
|
||||
className={clsx(
|
||||
"w-fit transition duration-300 ease-in-out",
|
||||
path === "/exam" && "text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold ",
|
||||
)}>
|
||||
path === "/exam" &&
|
||||
"text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold "
|
||||
)}
|
||||
>
|
||||
Exams
|
||||
</Link>
|
||||
<Link
|
||||
@@ -82,8 +110,9 @@ export default function MobileMenu({isOpen, onClose, path, user, disableNavigati
|
||||
className={clsx(
|
||||
"w-fit transition duration-300 ease-in-out",
|
||||
path === "/exercises" &&
|
||||
"text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold ",
|
||||
)}>
|
||||
"text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold "
|
||||
)}
|
||||
>
|
||||
Exercises
|
||||
</Link>
|
||||
</>
|
||||
@@ -92,46 +121,67 @@ export default function MobileMenu({isOpen, onClose, path, user, disableNavigati
|
||||
href={disableNavigation ? "" : "/stats"}
|
||||
className={clsx(
|
||||
"w-fit transition duration-300 ease-in-out",
|
||||
path === "/stats" && "text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold ",
|
||||
)}>
|
||||
path === "/stats" &&
|
||||
"text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold "
|
||||
)}
|
||||
>
|
||||
Stats
|
||||
</Link>
|
||||
<Link
|
||||
href={disableNavigation ? "" : "/record"}
|
||||
className={clsx(
|
||||
"w-fit transition duration-300 ease-in-out",
|
||||
path === "/record" && "text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold ",
|
||||
)}>
|
||||
path === "/record" &&
|
||||
"text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold "
|
||||
)}
|
||||
>
|
||||
Record
|
||||
</Link>
|
||||
{["admin", "developer", "agent", "corporate", "mastercorporate"].includes(user.type) && (
|
||||
{checkAccess(user, [
|
||||
"admin",
|
||||
"developer",
|
||||
"agent",
|
||||
"corporate",
|
||||
"mastercorporate",
|
||||
]) && (
|
||||
<Link
|
||||
href={disableNavigation ? "" : "/payment-record"}
|
||||
className={clsx(
|
||||
"w-fit transition duration-300 ease-in-out",
|
||||
path === "/payment-record" &&
|
||||
"text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold ",
|
||||
)}>
|
||||
"text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold "
|
||||
)}
|
||||
>
|
||||
Payment Record
|
||||
</Link>
|
||||
)}
|
||||
{["admin", "developer", "corporate", "teacher", "mastercorporate"].includes(user.type) && (
|
||||
{checkAccess(user, [
|
||||
"admin",
|
||||
"developer",
|
||||
"corporate",
|
||||
"teacher",
|
||||
"mastercorporate",
|
||||
]) && (
|
||||
<Link
|
||||
href={disableNavigation ? "" : "/settings"}
|
||||
className={clsx(
|
||||
"w-fit transition duration-300 ease-in-out",
|
||||
path === "/settings" && "text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold ",
|
||||
)}>
|
||||
path === "/settings" &&
|
||||
"text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold "
|
||||
)}
|
||||
>
|
||||
Settings
|
||||
</Link>
|
||||
)}
|
||||
{["admin", "developer", "agent"].includes(user.type) && (
|
||||
{checkAccess(user, ["admin", "developer", "agent"]) && (
|
||||
<Link
|
||||
href={disableNavigation ? "" : "/tickets"}
|
||||
className={clsx(
|
||||
"w-fit transition duration-300 ease-in-out",
|
||||
path === "/tickets" && "text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold ",
|
||||
)}>
|
||||
path === "/tickets" &&
|
||||
"text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold "
|
||||
)}
|
||||
>
|
||||
Tickets
|
||||
</Link>
|
||||
)}
|
||||
@@ -139,14 +189,19 @@ export default function MobileMenu({isOpen, onClose, path, user, disableNavigati
|
||||
href={disableNavigation ? "" : "/profile"}
|
||||
className={clsx(
|
||||
"w-fit transition duration-300 ease-in-out",
|
||||
path === "/profile" && "text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold ",
|
||||
)}>
|
||||
path === "/profile" &&
|
||||
"text-mti-purple-light border-b-mti-purple-light border-b-2 font-semibold "
|
||||
)}
|
||||
>
|
||||
Profile
|
||||
</Link>
|
||||
|
||||
<span
|
||||
className={clsx("w-fit cursor-pointer justify-self-end transition duration-300 ease-in-out")}
|
||||
onClick={logout}>
|
||||
className={clsx(
|
||||
"w-fit cursor-pointer justify-self-end transition duration-300 ease-in-out"
|
||||
)}
|
||||
onClick={logout}
|
||||
>
|
||||
Logout
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
import useStats from "@/hooks/useStats";
|
||||
import {CorporateInformation, CorporateUser, EMPLOYMENT_STATUS, User} from "@/interfaces/user";
|
||||
import {groupBySession, averageScore} from "@/utils/stats";
|
||||
import {RadioGroup} from "@headlessui/react";
|
||||
import {
|
||||
CorporateInformation,
|
||||
CorporateUser,
|
||||
EMPLOYMENT_STATUS,
|
||||
User,
|
||||
} from "@/interfaces/user";
|
||||
import { groupBySession, averageScore } from "@/utils/stats";
|
||||
import { RadioGroup } from "@headlessui/react";
|
||||
import axios from "axios";
|
||||
import clsx from "clsx";
|
||||
import moment from "moment";
|
||||
import {Divider} from "primereact/divider";
|
||||
import {useEffect, useState} from "react";
|
||||
import { Divider } from "primereact/divider";
|
||||
import { useEffect, useState } from "react";
|
||||
import ReactDatePicker from "react-datepicker";
|
||||
import {BsFileEarmarkText, BsPencil, BsPerson, BsPersonAdd, BsStar} from "react-icons/bs";
|
||||
import {toast} from "react-toastify";
|
||||
import {
|
||||
BsFileEarmarkText,
|
||||
BsPencil,
|
||||
BsPerson,
|
||||
BsPersonAdd,
|
||||
BsStar,
|
||||
} from "react-icons/bs";
|
||||
import { toast } from "react-toastify";
|
||||
import Button from "./Low/Button";
|
||||
import Checkbox from "./Low/Checkbox";
|
||||
import CountrySelect from "./Low/CountrySelect";
|
||||
@@ -17,17 +28,21 @@ import Input from "./Low/Input";
|
||||
import ProfileSummary from "./ProfileSummary";
|
||||
import Select from "react-select";
|
||||
import useUsers from "@/hooks/useUsers";
|
||||
import {USER_TYPE_LABELS} from "@/resources/user";
|
||||
import {CURRENCIES} from "@/resources/paypal";
|
||||
import { USER_TYPE_LABELS } from "@/resources/user";
|
||||
import { CURRENCIES } from "@/resources/paypal";
|
||||
import useCodes from "@/hooks/useCodes";
|
||||
import { checkAccess, getTypesOfUser } from "@/utils/permissions";
|
||||
|
||||
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";
|
||||
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";
|
||||
};
|
||||
|
||||
interface Props {
|
||||
@@ -63,39 +78,86 @@ const USER_TYPE_OPTIONS = Object.keys(USER_TYPE_LABELS).map((type) => ({
|
||||
label: USER_TYPE_LABELS[type as keyof typeof USER_TYPE_LABELS],
|
||||
}));
|
||||
|
||||
const CURRENCIES_OPTIONS = CURRENCIES.map(({label, currency}) => ({
|
||||
const CURRENCIES_OPTIONS = CURRENCIES.map(({ label, currency }) => ({
|
||||
value: currency,
|
||||
label,
|
||||
}));
|
||||
|
||||
const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, onViewCorporate, disabled = false, disabledFields = {}}: Props) => {
|
||||
const [expiryDate, setExpiryDate] = useState<Date | null | undefined>(user.subscriptionExpirationDate);
|
||||
const UserCard = ({
|
||||
user,
|
||||
loggedInUser,
|
||||
onClose,
|
||||
onViewStudents,
|
||||
onViewTeachers,
|
||||
onViewCorporate,
|
||||
disabled = false,
|
||||
disabledFields = {},
|
||||
}: Props) => {
|
||||
const [expiryDate, setExpiryDate] = useState<Date | null | undefined>(
|
||||
user.subscriptionExpirationDate
|
||||
);
|
||||
const [type, setType] = useState(user.type);
|
||||
const [status, setStatus] = useState(user.status);
|
||||
const [referralAgentLabel, setReferralAgentLabel] = useState<string>();
|
||||
const [position, setPosition] = useState<string | undefined>(user.type === "corporate" ? user.demographicInformation?.position : undefined);
|
||||
const [passport_id, setPassportID] = useState<string | undefined>(user.type === "student" ? user.demographicInformation?.passport_id : undefined);
|
||||
const [position, setPosition] = useState<string | undefined>(
|
||||
user.type === "corporate"
|
||||
? user.demographicInformation?.position
|
||||
: undefined
|
||||
);
|
||||
const [passport_id, setPassportID] = useState<string | undefined>(
|
||||
user.type === "student"
|
||||
? user.demographicInformation?.passport_id
|
||||
: undefined
|
||||
);
|
||||
|
||||
const [referralAgent, setReferralAgent] = useState(user.type === "corporate" ? user.corporateInformation?.referralAgent : undefined);
|
||||
const [referralAgent, setReferralAgent] = useState(
|
||||
user.type === "corporate"
|
||||
? user.corporateInformation?.referralAgent
|
||||
: undefined
|
||||
);
|
||||
const [companyName, setCompanyName] = useState(
|
||||
user.type === "corporate"
|
||||
? user.corporateInformation?.companyInformation.name
|
||||
: user.type === "agent"
|
||||
? user.agentInformation?.companyName
|
||||
: undefined,
|
||||
: undefined
|
||||
);
|
||||
const [arabName, setArabName] = useState(
|
||||
user.type === "agent" ? user.agentInformation?.companyArabName : undefined
|
||||
);
|
||||
const [arabName, setArabName] = useState(user.type === "agent" ? user.agentInformation?.companyArabName : undefined);
|
||||
const [commercialRegistration, setCommercialRegistration] = useState(
|
||||
user.type === "agent" ? user.agentInformation?.commercialRegistration : undefined,
|
||||
user.type === "agent"
|
||||
? user.agentInformation?.commercialRegistration
|
||||
: undefined
|
||||
);
|
||||
const [userAmount, setUserAmount] = useState(user.type === "corporate" ? user.corporateInformation?.companyInformation.userAmount : undefined);
|
||||
const [paymentValue, setPaymentValue] = useState(user.type === "corporate" ? user.corporateInformation?.payment?.value : undefined);
|
||||
const [paymentCurrency, setPaymentCurrency] = useState(user.type === "corporate" ? user.corporateInformation?.payment?.currency : "EUR");
|
||||
const [monthlyDuration, setMonthlyDuration] = useState(user.type === "corporate" ? user.corporateInformation?.monthlyDuration : undefined);
|
||||
const [commissionValue, setCommission] = useState(user.type === "corporate" ? user.corporateInformation?.payment?.commission : undefined);
|
||||
const {stats} = useStats(user.id);
|
||||
const {users} = useUsers();
|
||||
const {codes} = useCodes(user.id);
|
||||
const [userAmount, setUserAmount] = useState(
|
||||
user.type === "corporate"
|
||||
? user.corporateInformation?.companyInformation.userAmount
|
||||
: undefined
|
||||
);
|
||||
const [paymentValue, setPaymentValue] = useState(
|
||||
user.type === "corporate"
|
||||
? user.corporateInformation?.payment?.value
|
||||
: undefined
|
||||
);
|
||||
const [paymentCurrency, setPaymentCurrency] = useState(
|
||||
user.type === "corporate"
|
||||
? user.corporateInformation?.payment?.currency
|
||||
: "EUR"
|
||||
);
|
||||
const [monthlyDuration, setMonthlyDuration] = useState(
|
||||
user.type === "corporate"
|
||||
? user.corporateInformation?.monthlyDuration
|
||||
: undefined
|
||||
);
|
||||
const [commissionValue, setCommission] = useState(
|
||||
user.type === "corporate"
|
||||
? user.corporateInformation?.payment?.commission
|
||||
: undefined
|
||||
);
|
||||
const { stats } = useStats(user.id);
|
||||
const { users } = useUsers();
|
||||
const { codes } = useCodes(user.id);
|
||||
|
||||
useEffect(() => {
|
||||
if (users && users.length > 0) {
|
||||
@@ -111,11 +173,14 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
|
||||
const updateUser = () => {
|
||||
if (user.type === "corporate" && (!paymentValue || paymentValue < 0))
|
||||
return toast.error("Please set a price for the user's package before updating!");
|
||||
if (!confirm(`Are you sure you want to update ${user.name}'s account?`)) return;
|
||||
return toast.error(
|
||||
"Please set a price for the user's package before updating!"
|
||||
);
|
||||
if (!confirm(`Are you sure you want to update ${user.name}'s account?`))
|
||||
return;
|
||||
|
||||
axios
|
||||
.post<{user?: User; ok?: boolean}>(`/api/users/update?id=${user.id}`, {
|
||||
.post<{ user?: User; ok?: boolean }>(`/api/users/update?id=${user.id}`, {
|
||||
...user,
|
||||
subscriptionExpirationDate: expiryDate,
|
||||
type,
|
||||
@@ -140,7 +205,9 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
payment: {
|
||||
value: paymentValue,
|
||||
currency: paymentCurrency,
|
||||
...(referralAgent === "" ? {} : {commission: commissionValue}),
|
||||
...(referralAgent === ""
|
||||
? {}
|
||||
: { commission: commissionValue }),
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
@@ -150,13 +217,15 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
onClose(true);
|
||||
})
|
||||
.catch(() => {
|
||||
toast.error("Something went wrong!", {toastId: "update-error"});
|
||||
toast.error("Something went wrong!", { toastId: "update-error" });
|
||||
});
|
||||
};
|
||||
|
||||
const generalProfileItems = [
|
||||
{
|
||||
icon: <BsFileEarmarkText className="w-6 h-6 md:w-8 md:h-8 text-mti-red-light" />,
|
||||
icon: (
|
||||
<BsFileEarmarkText className="w-6 h-6 md:w-8 md:h-8 text-mti-red-light" />
|
||||
),
|
||||
value: Object.keys(groupBySession(stats)).length,
|
||||
label: "Exams",
|
||||
},
|
||||
@@ -176,12 +245,16 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
user.type === "corporate"
|
||||
? [
|
||||
{
|
||||
icon: <BsPerson className="w-6 h-6 md:w-8 md:h-8 text-mti-red-light" />,
|
||||
icon: (
|
||||
<BsPerson className="w-6 h-6 md:w-8 md:h-8 text-mti-red-light" />
|
||||
),
|
||||
value: codes.length,
|
||||
label: "Users Used",
|
||||
},
|
||||
{
|
||||
icon: <BsPersonAdd className="w-6 h-6 md:w-8 md:h-8 text-mti-red-light" />,
|
||||
icon: (
|
||||
<BsPersonAdd className="w-6 h-6 md:w-8 md:h-8 text-mti-red-light" />
|
||||
),
|
||||
value: user.corporateInformation.companyInformation.userAmount,
|
||||
label: "Number of Users",
|
||||
},
|
||||
@@ -190,7 +263,14 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
|
||||
return (
|
||||
<>
|
||||
<ProfileSummary user={user} items={user.type === "corporate" ? corporateProfileItems : generalProfileItems} />
|
||||
<ProfileSummary
|
||||
user={user}
|
||||
items={
|
||||
user.type === "corporate"
|
||||
? corporateProfileItems
|
||||
: generalProfileItems
|
||||
}
|
||||
/>
|
||||
|
||||
{user.type === "agent" && (
|
||||
<>
|
||||
@@ -260,7 +340,9 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
disabled={disabled}
|
||||
/>
|
||||
<div className="flex flex-col gap-3 w-full lg:col-span-3">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Pricing</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Pricing
|
||||
</label>
|
||||
<div className="w-full grid grid-cols-6 gap-2">
|
||||
<Input
|
||||
name="paymentValue"
|
||||
@@ -273,14 +355,17 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
<Select
|
||||
className={clsx(
|
||||
"px-4 py-4 col-span-3 w-full text-sm font-normal placeholder:text-mti-gray-cool bg-white rounded-full border border-mti-gray-platinum focus:outline-none",
|
||||
disabled && "!bg-mti-gray-platinum/40 !text-mti-gray-dim cursor-not-allowed",
|
||||
disabled &&
|
||||
"!bg-mti-gray-platinum/40 !text-mti-gray-dim cursor-not-allowed"
|
||||
)}
|
||||
options={CURRENCIES_OPTIONS}
|
||||
value={CURRENCIES_OPTIONS.find((c) => c.value === paymentCurrency)}
|
||||
value={CURRENCIES_OPTIONS.find(
|
||||
(c) => c.value === paymentCurrency
|
||||
)}
|
||||
onChange={(value) => setPaymentCurrency(value?.value)}
|
||||
menuPortalTarget={document?.body}
|
||||
styles={{
|
||||
menuPortal: (base) => ({...base, zIndex: 9999}),
|
||||
menuPortal: (base) => ({ ...base, zIndex: 9999 }),
|
||||
control: (styles) => ({
|
||||
...styles,
|
||||
paddingLeft: "4px",
|
||||
@@ -292,7 +377,11 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
}),
|
||||
option: (styles, state) => ({
|
||||
...styles,
|
||||
backgroundColor: state.isFocused ? "#D5D9F0" : state.isSelected ? "#7872BF" : "white",
|
||||
backgroundColor: state.isFocused
|
||||
? "#D5D9F0"
|
||||
: state.isSelected
|
||||
? "#7872BF"
|
||||
: "white",
|
||||
color: state.isFocused ? "black" : styles.color,
|
||||
}),
|
||||
}}
|
||||
@@ -303,16 +392,22 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
</div>
|
||||
<div className="flex gap-3 w-full">
|
||||
<div className="flex flex-col gap-3 w-8/12">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Country Manager</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Country Manager
|
||||
</label>
|
||||
{referralAgentLabel && (
|
||||
<Select
|
||||
className={clsx(
|
||||
"px-4 py-4 w-full text-sm font-normal placeholder:text-mti-gray-cool bg-white rounded-full border border-mti-gray-platinum focus:outline-none",
|
||||
(!["developer", "admin"].includes(loggedInUser.type) || disabledFields.countryManager) &&
|
||||
"!bg-mti-gray-platinum/40 !text-mti-gray-dim cursor-not-allowed",
|
||||
(checkAccess(
|
||||
loggedInUser,
|
||||
getTypesOfUser(["developer", "admin"])
|
||||
) ||
|
||||
disabledFields.countryManager) &&
|
||||
"!bg-mti-gray-platinum/40 !text-mti-gray-dim cursor-not-allowed"
|
||||
)}
|
||||
options={[
|
||||
{value: "", label: "No referral"},
|
||||
{ value: "", label: "No referral" },
|
||||
...users
|
||||
.filter((u) => u.type === "agent")
|
||||
.map((x) => ({
|
||||
@@ -327,7 +422,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
menuPortalTarget={document?.body}
|
||||
onChange={(value) => setReferralAgent(value?.value)}
|
||||
styles={{
|
||||
menuPortal: (base) => ({...base, zIndex: 9999}),
|
||||
menuPortal: (base) => ({ ...base, zIndex: 9999 }),
|
||||
control: (styles) => ({
|
||||
...styles,
|
||||
paddingLeft: "4px",
|
||||
@@ -339,19 +434,30 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
}),
|
||||
option: (styles, state) => ({
|
||||
...styles,
|
||||
backgroundColor: state.isFocused ? "#D5D9F0" : state.isSelected ? "#7872BF" : "white",
|
||||
backgroundColor: state.isFocused
|
||||
? "#D5D9F0"
|
||||
: state.isSelected
|
||||
? "#7872BF"
|
||||
: "white",
|
||||
color: state.isFocused ? "black" : styles.color,
|
||||
}),
|
||||
}}
|
||||
// editing country manager should only be available for dev/admin
|
||||
isDisabled={!["developer", "admin"].includes(loggedInUser.type) || disabledFields.countryManager}
|
||||
isDisabled={
|
||||
checkAccess(
|
||||
loggedInUser,
|
||||
getTypesOfUser(["developer", "admin"])
|
||||
) || disabledFields.countryManager
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-col gap-3 w-4/12">
|
||||
{referralAgent !== "" && loggedInUser.type !== "corporate" ? (
|
||||
<>
|
||||
<label className="font-normal text-base text-mti-gray-dim">Commission</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Commission
|
||||
</label>
|
||||
<Input
|
||||
name="commissionValue"
|
||||
onChange={(e) => setCommission(e ? parseInt(e) : undefined)}
|
||||
@@ -393,8 +499,13 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
|
||||
<div className="flex flex-col md:flex-row gap-8 w-full">
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Country</label>
|
||||
<CountrySelect disabled value={user.demographicInformation?.country} />
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Country
|
||||
</label>
|
||||
<CountrySelect
|
||||
disabled
|
||||
value={user.demographicInformation?.country}
|
||||
/>
|
||||
</div>
|
||||
<Input
|
||||
type="tel"
|
||||
@@ -414,31 +525,39 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
label="Passport/National ID"
|
||||
onChange={() => null}
|
||||
placeholder="Enter National ID or Passport number"
|
||||
value={user.type === "student" ? user.demographicInformation?.passport_id : undefined}
|
||||
value={
|
||||
user.type === "student"
|
||||
? user.demographicInformation?.passport_id
|
||||
: undefined
|
||||
}
|
||||
disabled
|
||||
required
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col md:flex-row gap-8 w-full">
|
||||
{user.type !== "corporate" && user.type !== 'mastercorporate' && (
|
||||
{user.type !== "corporate" && user.type !== "mastercorporate" && (
|
||||
<div className="relative flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Employment Status</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Employment Status
|
||||
</label>
|
||||
<RadioGroup
|
||||
value={user.demographicInformation?.employment}
|
||||
className="grid grid-cols-2 items-center gap-4 place-items-center"
|
||||
disabled={disabled}>
|
||||
{EMPLOYMENT_STATUS.map(({status, label}) => (
|
||||
disabled={disabled}
|
||||
>
|
||||
{EMPLOYMENT_STATUS.map(({ status, label }) => (
|
||||
<RadioGroup.Option value={status} key={status}>
|
||||
{({checked}) => (
|
||||
{({ checked }) => (
|
||||
<span
|
||||
className={clsx(
|
||||
"px-6 py-4 w-40 md:w-48 flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
|
||||
"transition duration-300 ease-in-out",
|
||||
!checked
|
||||
? "bg-white border-mti-gray-platinum"
|
||||
: "bg-mti-purple-light border-mti-purple-dark text-white",
|
||||
)}>
|
||||
: "bg-mti-purple-light border-mti-purple-dark text-white"
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
)}
|
||||
@@ -461,49 +580,55 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
)}
|
||||
<div className="flex flex-col gap-8 w-full">
|
||||
<div className="relative flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Gender</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Gender
|
||||
</label>
|
||||
<RadioGroup
|
||||
value={user.demographicInformation?.gender}
|
||||
className="flex flex-row gap-4 justify-between"
|
||||
disabled={disabled}>
|
||||
disabled={disabled}
|
||||
>
|
||||
<RadioGroup.Option value="male">
|
||||
{({checked}) => (
|
||||
{({ checked }) => (
|
||||
<span
|
||||
className={clsx(
|
||||
"px-6 py-4 w-28 flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
|
||||
"transition duration-300 ease-in-out",
|
||||
!checked
|
||||
? "bg-white border-mti-gray-platinum"
|
||||
: "bg-mti-purple-light border-mti-purple-dark text-white",
|
||||
)}>
|
||||
: "bg-mti-purple-light border-mti-purple-dark text-white"
|
||||
)}
|
||||
>
|
||||
Male
|
||||
</span>
|
||||
)}
|
||||
</RadioGroup.Option>
|
||||
<RadioGroup.Option value="female">
|
||||
{({checked}) => (
|
||||
{({ checked }) => (
|
||||
<span
|
||||
className={clsx(
|
||||
"px-6 py-4 w-28 flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
|
||||
"transition duration-300 ease-in-out",
|
||||
!checked
|
||||
? "bg-white border-mti-gray-platinum"
|
||||
: "bg-mti-purple-light border-mti-purple-dark text-white",
|
||||
)}>
|
||||
: "bg-mti-purple-light border-mti-purple-dark text-white"
|
||||
)}
|
||||
>
|
||||
Female
|
||||
</span>
|
||||
)}
|
||||
</RadioGroup.Option>
|
||||
<RadioGroup.Option value="other">
|
||||
{({checked}) => (
|
||||
{({ checked }) => (
|
||||
<span
|
||||
className={clsx(
|
||||
"px-6 py-4 w-28 flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
|
||||
"transition duration-300 ease-in-out",
|
||||
!checked
|
||||
? "bg-white border-mti-gray-platinum"
|
||||
: "bg-mti-purple-light border-mti-purple-dark text-white",
|
||||
)}>
|
||||
: "bg-mti-purple-light border-mti-purple-dark text-white"
|
||||
)}
|
||||
>
|
||||
Other
|
||||
</span>
|
||||
)}
|
||||
@@ -512,11 +637,20 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
</div>
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex justify-between items-center">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Expiry Date</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Expiry Date
|
||||
</label>
|
||||
<Checkbox
|
||||
isChecked={!!expiryDate}
|
||||
onChange={(checked) => setExpiryDate(checked ? user.subscriptionExpirationDate || new Date() : null)}
|
||||
disabled={disabled}>
|
||||
onChange={(checked) =>
|
||||
setExpiryDate(
|
||||
checked
|
||||
? user.subscriptionExpirationDate || new Date()
|
||||
: null
|
||||
)
|
||||
}
|
||||
disabled={disabled}
|
||||
>
|
||||
Enabled
|
||||
</Checkbox>
|
||||
</div>
|
||||
@@ -525,9 +659,12 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
className={clsx(
|
||||
"p-6 w-full flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
|
||||
"transition duration-300 ease-in-out",
|
||||
!expiryDate ? "!bg-mti-green-ultralight !border-mti-green-light" : expirationDateColor(expiryDate),
|
||||
"bg-white border-mti-gray-platinum",
|
||||
)}>
|
||||
!expiryDate
|
||||
? "!bg-mti-green-ultralight !border-mti-green-light"
|
||||
: expirationDateColor(expiryDate),
|
||||
"bg-white border-mti-gray-platinum"
|
||||
)}
|
||||
>
|
||||
{!expiryDate && "Unlimited"}
|
||||
{expiryDate && moment(expiryDate).format("DD/MM/YYYY")}
|
||||
</div>
|
||||
@@ -538,12 +675,14 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
"p-6 w-full min-h-[70px] flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
|
||||
"hover:border-mti-purple tooltip",
|
||||
expirationDateColor(expiryDate),
|
||||
"transition duration-300 ease-in-out",
|
||||
"transition duration-300 ease-in-out"
|
||||
)}
|
||||
filterDate={(date) =>
|
||||
moment(date).isAfter(new Date()) &&
|
||||
(loggedInUser.subscriptionExpirationDate
|
||||
? moment(date).isBefore(moment(loggedInUser.subscriptionExpirationDate))
|
||||
? moment(date).isBefore(
|
||||
moment(loggedInUser.subscriptionExpirationDate)
|
||||
)
|
||||
: true)
|
||||
}
|
||||
dateFormat="dd/MM/yyyy"
|
||||
@@ -555,18 +694,22 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{(loggedInUser.type === "developer" || loggedInUser.type === "admin") && (
|
||||
{checkAccess(loggedInUser, ["developer", "admin"]) && (
|
||||
<>
|
||||
<Divider className="w-full !m-0" />
|
||||
<div className="flex flex-col md:flex-row gap-8 w-full">
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Status</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Status
|
||||
</label>
|
||||
<Select
|
||||
className="px-4 py-4 w-full text-sm font-normal placeholder:text-mti-gray-cool disabled:bg-mti-gray-platinum/40 disabled:text-mti-gray-dim disabled:cursor-not-allowed bg-white rounded-full border border-mti-gray-platinum focus:outline-none"
|
||||
options={USER_STATUS_OPTIONS}
|
||||
menuPortalTarget={document?.body}
|
||||
value={USER_STATUS_OPTIONS.find((o) => o.value === status)}
|
||||
onChange={(value) => setStatus(value?.value as typeof user.status)}
|
||||
onChange={(value) =>
|
||||
setStatus(value?.value as typeof user.status)
|
||||
}
|
||||
styles={{
|
||||
control: (styles) => ({
|
||||
...styles,
|
||||
@@ -577,10 +720,14 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
outline: "none",
|
||||
},
|
||||
}),
|
||||
menuPortal: (base) => ({...base, zIndex: 9999}),
|
||||
menuPortal: (base) => ({ ...base, zIndex: 9999 }),
|
||||
option: (styles, state) => ({
|
||||
...styles,
|
||||
backgroundColor: state.isFocused ? "#D5D9F0" : state.isSelected ? "#7872BF" : "white",
|
||||
backgroundColor: state.isFocused
|
||||
? "#D5D9F0"
|
||||
: state.isSelected
|
||||
? "#7872BF"
|
||||
: "white",
|
||||
color: state.isFocused ? "black" : styles.color,
|
||||
}),
|
||||
}}
|
||||
@@ -588,13 +735,17 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Type</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Type
|
||||
</label>
|
||||
<Select
|
||||
className="px-4 py-4 w-full text-sm font-normal placeholder:text-mti-gray-cool disabled:bg-mti-gray-platinum/40 disabled:text-mti-gray-dim disabled:cursor-not-allowed bg-white rounded-full border border-mti-gray-platinum focus:outline-none"
|
||||
options={USER_TYPE_OPTIONS}
|
||||
menuPortalTarget={document?.body}
|
||||
value={USER_TYPE_OPTIONS.find((o) => o.value === type)}
|
||||
onChange={(value) => setType(value?.value as typeof user.type)}
|
||||
onChange={(value) =>
|
||||
setType(value?.value as typeof user.type)
|
||||
}
|
||||
styles={{
|
||||
control: (styles) => ({
|
||||
...styles,
|
||||
@@ -605,10 +756,14 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
outline: "none",
|
||||
},
|
||||
}),
|
||||
menuPortal: (base) => ({...base, zIndex: 9999}),
|
||||
menuPortal: (base) => ({ ...base, zIndex: 9999 }),
|
||||
option: (styles, state) => ({
|
||||
...styles,
|
||||
backgroundColor: state.isFocused ? "#D5D9F0" : state.isSelected ? "#7872BF" : "white",
|
||||
backgroundColor: state.isFocused
|
||||
? "#D5D9F0"
|
||||
: state.isSelected
|
||||
? "#7872BF"
|
||||
: "white",
|
||||
color: state.isFocused ? "black" : styles.color,
|
||||
}),
|
||||
}}
|
||||
@@ -623,26 +778,49 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers,
|
||||
<div className="flex gap-4 justify-between mt-4 w-full">
|
||||
<div className="self-start flex gap-4 justify-start items-center w-full">
|
||||
{onViewCorporate && ["student", "teacher"].includes(user.type) && (
|
||||
<Button className="w-full max-w-[200px]" variant="outline" color="rose" onClick={onViewCorporate}>
|
||||
<Button
|
||||
className="w-full max-w-[200px]"
|
||||
variant="outline"
|
||||
color="rose"
|
||||
onClick={onViewCorporate}
|
||||
>
|
||||
View Corporate
|
||||
</Button>
|
||||
)}
|
||||
{onViewStudents && ["corporate", "teacher"].includes(user.type) && (
|
||||
<Button className="w-full max-w-[200px]" variant="outline" color="rose" onClick={onViewStudents}>
|
||||
<Button
|
||||
className="w-full max-w-[200px]"
|
||||
variant="outline"
|
||||
color="rose"
|
||||
onClick={onViewStudents}
|
||||
>
|
||||
View Students
|
||||
</Button>
|
||||
)}
|
||||
{onViewTeachers && ["student", "corporate"].includes(user.type) && (
|
||||
<Button className="w-full max-w-[200px]" variant="outline" color="rose" onClick={onViewTeachers}>
|
||||
<Button
|
||||
className="w-full max-w-[200px]"
|
||||
variant="outline"
|
||||
color="rose"
|
||||
onClick={onViewTeachers}
|
||||
>
|
||||
View Teachers
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<div className="self-end flex gap-4 w-full justify-end">
|
||||
<Button className="w-full max-w-[200px]" variant="outline" onClick={onClose}>
|
||||
<Button
|
||||
className="w-full max-w-[200px]"
|
||||
variant="outline"
|
||||
onClick={onClose}
|
||||
>
|
||||
Close
|
||||
</Button>
|
||||
<Button disabled={disabled} onClick={updateUser} className="w-full max-w-[200px]">
|
||||
<Button
|
||||
disabled={disabled}
|
||||
onClick={updateUser}
|
||||
className="w-full max-w-[200px]"
|
||||
>
|
||||
Update
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import Head from "next/head";
|
||||
import {withIronSessionSsr} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import { withIronSessionSsr } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import useUser from "@/hooks/useUser";
|
||||
import {toast, ToastContainer} from "react-toastify";
|
||||
import { toast, ToastContainer } from "react-toastify";
|
||||
import Layout from "@/components/High/Layout";
|
||||
import {shouldRedirectHome} from "@/utils/navigation.disabled";
|
||||
import {useState} from "react";
|
||||
import {Module} from "@/interfaces";
|
||||
import {RadioGroup, Tab} from "@headlessui/react";
|
||||
import { shouldRedirectHome } from "@/utils/navigation.disabled";
|
||||
import { useState } from "react";
|
||||
import { Module } from "@/interfaces";
|
||||
import { RadioGroup, Tab } from "@headlessui/react";
|
||||
import clsx from "clsx";
|
||||
import {MODULE_ARRAY} from "@/utils/moduleUtils";
|
||||
import {capitalize} from "lodash";
|
||||
import { MODULE_ARRAY } from "@/utils/moduleUtils";
|
||||
import { capitalize } from "lodash";
|
||||
import Button from "@/components/Low/Button";
|
||||
import {Exercise, ReadingPart} from "@/interfaces/exam";
|
||||
import { Exercise, ReadingPart } from "@/interfaces/exam";
|
||||
import Input from "@/components/Low/Input";
|
||||
import axios from "axios";
|
||||
import ReadingGeneration from "./(generation)/ReadingGeneration";
|
||||
@@ -21,8 +21,9 @@ import ListeningGeneration from "./(generation)/ListeningGeneration";
|
||||
import WritingGeneration from "./(generation)/WritingGeneration";
|
||||
import LevelGeneration from "./(generation)/LevelGeneration";
|
||||
import SpeakingGeneration from "./(generation)/SpeakingGeneration";
|
||||
import { checkAccess, getTypesOfUser } from "@/utils/permissions";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
||||
const user = req.session.user;
|
||||
|
||||
if (!user || !user.isVerified) {
|
||||
@@ -30,28 +31,31 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
redirect: {
|
||||
destination: "/login",
|
||||
permanent: false,
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (shouldRedirectHome(user) || user.type !== "developer") {
|
||||
if (
|
||||
shouldRedirectHome(user) ||
|
||||
checkAccess(user, getTypesOfUser(["developer"]))
|
||||
) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/",
|
||||
permanent: false,
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
props: {user: req.session.user},
|
||||
props: { user: req.session.user },
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
export default function Generation() {
|
||||
const [module, setModule] = useState<Module>("reading");
|
||||
|
||||
const {user} = useUser({redirectTo: "/login"});
|
||||
const { user } = useUser({ redirectTo: "/login" });
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -69,14 +73,17 @@ export default function Generation() {
|
||||
<Layout user={user} className="gap-6">
|
||||
<h1 className="text-2xl font-semibold">Exam Generation</h1>
|
||||
<div className="flex flex-col gap-3">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Module</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Module
|
||||
</label>
|
||||
<RadioGroup
|
||||
value={module}
|
||||
onChange={setModule}
|
||||
className="flex flex-row -2xl:flex-wrap w-full gap-4 -md:justify-center justify-between">
|
||||
className="flex flex-row -2xl:flex-wrap w-full gap-4 -md:justify-center justify-between"
|
||||
>
|
||||
{[...MODULE_ARRAY].map((x) => (
|
||||
<RadioGroup.Option value={x} key={x}>
|
||||
{({checked}) => (
|
||||
{({ checked }) => (
|
||||
<span
|
||||
className={clsx(
|
||||
"px-6 py-4 w-64 flex justify-center text-sm font-normal rounded-full border focus:outline-none cursor-pointer",
|
||||
@@ -100,8 +107,9 @@ export default function Generation() {
|
||||
x === "level" &&
|
||||
(!checked
|
||||
? "bg-white border-mti-gray-platinum"
|
||||
: "bg-ielts-level/70 border-ielts-level text-white"),
|
||||
)}>
|
||||
: "bg-ielts-level/70 border-ielts-level text-white")
|
||||
)}
|
||||
>
|
||||
{capitalize(x)}
|
||||
</span>
|
||||
)}
|
||||
|
||||
@@ -1,25 +1,33 @@
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import Head from "next/head";
|
||||
import Navbar from "@/components/Navbar";
|
||||
import {BsFileEarmarkText, BsPencil, BsStar, BsBook, BsHeadphones, BsPen, BsMegaphone} from "react-icons/bs";
|
||||
import {withIronSessionSsr} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {useEffect, useState} from "react";
|
||||
import {
|
||||
BsFileEarmarkText,
|
||||
BsPencil,
|
||||
BsStar,
|
||||
BsBook,
|
||||
BsHeadphones,
|
||||
BsPen,
|
||||
BsMegaphone,
|
||||
} from "react-icons/bs";
|
||||
import { withIronSessionSsr } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import { useEffect, useState } from "react";
|
||||
import useStats from "@/hooks/useStats";
|
||||
import {averageScore, groupBySession, totalExams} from "@/utils/stats";
|
||||
import { averageScore, groupBySession, totalExams } from "@/utils/stats";
|
||||
import useUser from "@/hooks/useUser";
|
||||
import Diagnostic from "@/components/Diagnostic";
|
||||
import {ToastContainer} from "react-toastify";
|
||||
import {capitalize} from "lodash";
|
||||
import {Module} from "@/interfaces";
|
||||
import { ToastContainer } from "react-toastify";
|
||||
import { capitalize } from "lodash";
|
||||
import { Module } from "@/interfaces";
|
||||
import ProgressBar from "@/components/Low/ProgressBar";
|
||||
import Layout from "@/components/High/Layout";
|
||||
import {calculateAverageLevel} from "@/utils/score";
|
||||
import { calculateAverageLevel } from "@/utils/score";
|
||||
import axios from "axios";
|
||||
import DemographicInformationInput from "@/components/DemographicInformationInput";
|
||||
import moment from "moment";
|
||||
import Link from "next/link";
|
||||
import {MODULE_ARRAY} from "@/utils/moduleUtils";
|
||||
import { MODULE_ARRAY } from "@/utils/moduleUtils";
|
||||
import ProfileSummary from "@/components/ProfileSummary";
|
||||
import StudentDashboard from "@/dashboards/Student";
|
||||
import AdminDashboard from "@/dashboards/Admin";
|
||||
@@ -28,16 +36,22 @@ import TeacherDashboard from "@/dashboards/Teacher";
|
||||
import AgentDashboard from "@/dashboards/Agent";
|
||||
import MasterCorporateDashboard from "@/dashboards/MasterCorporate";
|
||||
import PaymentDue from "./(status)/PaymentDue";
|
||||
import {useRouter} from "next/router";
|
||||
import {PayPalScriptProvider} from "@paypal/react-paypal-js";
|
||||
import {CorporateUser, MasterCorporateUser, Type, userTypes} from "@/interfaces/user";
|
||||
import { useRouter } from "next/router";
|
||||
import { PayPalScriptProvider } from "@paypal/react-paypal-js";
|
||||
import {
|
||||
CorporateUser,
|
||||
MasterCorporateUser,
|
||||
Type,
|
||||
userTypes,
|
||||
} from "@/interfaces/user";
|
||||
import Select from "react-select";
|
||||
import {USER_TYPE_LABELS} from "@/resources/user";
|
||||
import { USER_TYPE_LABELS } from "@/resources/user";
|
||||
import { checkAccess, getTypesOfUser } from "@/utils/permissions";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
||||
const user = req.session.user;
|
||||
|
||||
const envVariables: {[key: string]: string} = {};
|
||||
const envVariables: { [key: string]: string } = {};
|
||||
Object.keys(process.env)
|
||||
.filter((x) => x.startsWith("NEXT_PUBLIC"))
|
||||
.forEach((x: string) => {
|
||||
@@ -54,21 +68,21 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
}
|
||||
|
||||
return {
|
||||
props: {user: req.session.user, envVariables},
|
||||
props: { user: req.session.user, envVariables },
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
interface Props {
|
||||
user: any;
|
||||
envVariables: {[key: string]: string};
|
||||
envVariables: { [key: string]: string };
|
||||
}
|
||||
export default function Home(props: Props) {
|
||||
const {envVariables} = props;
|
||||
const { envVariables } = props;
|
||||
const [showDiagnostics, setShowDiagnostics] = useState(false);
|
||||
const [showDemographicInput, setShowDemographicInput] = useState(false);
|
||||
const [selectedScreen, setSelectedScreen] = useState<Type>("admin");
|
||||
|
||||
const {user, mutateUser} = useUser({redirectTo: "/login"});
|
||||
const { user, mutateUser } = useUser({ redirectTo: "/login" });
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
@@ -77,7 +91,7 @@ export default function Home(props: Props) {
|
||||
!user.demographicInformation ||
|
||||
!user.demographicInformation.country ||
|
||||
!user.demographicInformation.gender ||
|
||||
!user.demographicInformation.phone,
|
||||
!user.demographicInformation.phone
|
||||
);
|
||||
setShowDiagnostics(user.isFirstLogin && user.type === "student");
|
||||
}
|
||||
@@ -92,7 +106,12 @@ export default function Home(props: Props) {
|
||||
return true;
|
||||
};
|
||||
|
||||
if (user && (user.status === "paymentDue" || user.status === "disabled" || checkIfUserExpired())) {
|
||||
if (
|
||||
user &&
|
||||
(user.status === "paymentDue" ||
|
||||
user.status === "disabled" ||
|
||||
checkIfUserExpired())
|
||||
) {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
@@ -107,12 +126,19 @@ export default function Home(props: Props) {
|
||||
{user.status === "disabled" && (
|
||||
<Layout user={user} navDisabled>
|
||||
<div className="flex flex-col items-center justify-center text-center w-full gap-4">
|
||||
<span className="font-bold text-lg">Your account has been disabled!</span>
|
||||
<span>Please contact an administrator if you believe this to be a mistake.</span>
|
||||
<span className="font-bold text-lg">
|
||||
Your account has been disabled!
|
||||
</span>
|
||||
<span>
|
||||
Please contact an administrator if you believe this to be a
|
||||
mistake.
|
||||
</span>
|
||||
</div>
|
||||
</Layout>
|
||||
)}
|
||||
{(user.status === "paymentDue" || checkIfUserExpired()) && <PaymentDue hasExpired user={user} reload={router.reload} />}
|
||||
{(user.status === "paymentDue" || checkIfUserExpired()) && (
|
||||
<PaymentDue hasExpired user={user} reload={router.reload} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -169,24 +195,44 @@ export default function Home(props: Props) {
|
||||
<ToastContainer />
|
||||
{user && (
|
||||
<Layout user={user}>
|
||||
{user.type === "student" && <StudentDashboard user={user} />}
|
||||
{user.type === "teacher" && <TeacherDashboard user={user} />}
|
||||
{user.type === "corporate" && <CorporateDashboard user={user} />}
|
||||
{user.type === "mastercorporate" && <MasterCorporateDashboard user={user} />}
|
||||
{user.type === "agent" && <AgentDashboard user={user} />}
|
||||
{user.type === "admin" && <AdminDashboard user={user} />}
|
||||
{user.type === "developer" && (
|
||||
{checkAccess(user, ["student"]) && <StudentDashboard user={user} />}
|
||||
{checkAccess(user, ["teacher"]) && <TeacherDashboard user={user} />}
|
||||
{checkAccess(user, ["corporate"]) && (
|
||||
<CorporateDashboard user={user as CorporateUser} />
|
||||
)}
|
||||
{checkAccess(user, ["mastercorporate"]) && (
|
||||
<MasterCorporateDashboard user={user as MasterCorporateUser} />
|
||||
)}
|
||||
{checkAccess(user, ["agent"]) && <AgentDashboard user={user} />}
|
||||
{checkAccess(user, ["admin"]) && <AdminDashboard user={user} />}
|
||||
{checkAccess(user, ["developer"]) && (
|
||||
<>
|
||||
<Select
|
||||
options={userTypes.map((u) => ({value: u, label: USER_TYPE_LABELS[u]}))}
|
||||
value={{value: selectedScreen, label: USER_TYPE_LABELS[selectedScreen]}}
|
||||
onChange={(value) => (value ? setSelectedScreen(value.value) : setSelectedScreen("admin"))}
|
||||
options={userTypes.map((u) => ({
|
||||
value: u,
|
||||
label: USER_TYPE_LABELS[u],
|
||||
}))}
|
||||
value={{
|
||||
value: selectedScreen,
|
||||
label: USER_TYPE_LABELS[selectedScreen],
|
||||
}}
|
||||
onChange={(value) =>
|
||||
value
|
||||
? setSelectedScreen(value.value)
|
||||
: setSelectedScreen("admin")
|
||||
}
|
||||
/>
|
||||
|
||||
{selectedScreen === "student" && <StudentDashboard user={user} />}
|
||||
{selectedScreen === "teacher" && <TeacherDashboard user={user} />}
|
||||
{selectedScreen === "corporate" && <CorporateDashboard user={user as unknown as CorporateUser} />}
|
||||
{selectedScreen === "mastercorporate" && <MasterCorporateDashboard user={user as unknown as MasterCorporateUser} />}
|
||||
{selectedScreen === "corporate" && (
|
||||
<CorporateDashboard user={user as unknown as CorporateUser} />
|
||||
)}
|
||||
{selectedScreen === "mastercorporate" && (
|
||||
<MasterCorporateDashboard
|
||||
user={user as unknown as MasterCorporateUser}
|
||||
/>
|
||||
)}
|
||||
{selectedScreen === "agent" && <AgentDashboard user={user} />}
|
||||
{selectedScreen === "admin" && <AdminDashboard user={user} />}
|
||||
</>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,39 +1,56 @@
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
import Head from "next/head";
|
||||
import {withIronSessionSsr} from "iron-session/next";
|
||||
import {sessionOptions} from "@/lib/session";
|
||||
import {ChangeEvent, Dispatch, ReactNode, SetStateAction, useEffect, useRef, useState} from "react";
|
||||
import { withIronSessionSsr } from "iron-session/next";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import {
|
||||
ChangeEvent,
|
||||
Dispatch,
|
||||
ReactNode,
|
||||
SetStateAction,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from "react";
|
||||
import useUser from "@/hooks/useUser";
|
||||
import {toast, ToastContainer} from "react-toastify";
|
||||
import { toast, ToastContainer } from "react-toastify";
|
||||
import Layout from "@/components/High/Layout";
|
||||
import Input from "@/components/Low/Input";
|
||||
import Button from "@/components/Low/Button";
|
||||
import Link from "next/link";
|
||||
import axios from "axios";
|
||||
import {ErrorMessage} from "@/constants/errors";
|
||||
import { ErrorMessage } from "@/constants/errors";
|
||||
import clsx from "clsx";
|
||||
import {CorporateUser, EmploymentStatus, EMPLOYMENT_STATUS, Gender, User} from "@/interfaces/user";
|
||||
import {
|
||||
CorporateUser,
|
||||
EmploymentStatus,
|
||||
EMPLOYMENT_STATUS,
|
||||
Gender,
|
||||
User,
|
||||
DemographicInformation,
|
||||
} from "@/interfaces/user";
|
||||
import CountrySelect from "@/components/Low/CountrySelect";
|
||||
import {shouldRedirectHome} from "@/utils/navigation.disabled";
|
||||
import { shouldRedirectHome } from "@/utils/navigation.disabled";
|
||||
import moment from "moment";
|
||||
import {BsCamera, BsQuestionCircleFill} from "react-icons/bs";
|
||||
import {USER_TYPE_LABELS} from "@/resources/user";
|
||||
import { BsCamera, BsQuestionCircleFill } from "react-icons/bs";
|
||||
import { USER_TYPE_LABELS } from "@/resources/user";
|
||||
import useGroups from "@/hooks/useGroups";
|
||||
import useUsers from "@/hooks/useUsers";
|
||||
import {convertBase64} from "@/utils";
|
||||
import {Divider} from "primereact/divider";
|
||||
import { convertBase64 } from "@/utils";
|
||||
import { Divider } from "primereact/divider";
|
||||
import GenderInput from "@/components/High/GenderInput";
|
||||
import EmploymentStatusInput from "@/components/High/EmploymentStatusInput";
|
||||
import TimezoneSelect from "@/components/Low/TImezoneSelect";
|
||||
import Modal from "@/components/Modal";
|
||||
import {Module} from "@/interfaces";
|
||||
import { Module } from "@/interfaces";
|
||||
import ModuleLevelSelector from "@/components/Medium/ModuleLevelSelector";
|
||||
import Select from "@/components/Low/Select";
|
||||
import {InstructorGender} from "@/interfaces/exam";
|
||||
import {capitalize} from "lodash";
|
||||
import { InstructorGender } from "@/interfaces/exam";
|
||||
import { capitalize } from "lodash";
|
||||
import TopicModal from "@/components/Medium/TopicModal";
|
||||
import {v4} from "uuid";
|
||||
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
import { v4 } from "uuid";
|
||||
import { checkAccess, getTypesOfUser } from "@/utils/permissions";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
||||
const user = req.session.user;
|
||||
|
||||
if (!user || !user.isVerified) {
|
||||
@@ -55,7 +72,7 @@ export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||
}
|
||||
|
||||
return {
|
||||
props: {user: req.session.user},
|
||||
props: { user: req.session.user },
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
@@ -64,9 +81,11 @@ interface Props {
|
||||
mutateUser: Function;
|
||||
}
|
||||
|
||||
const DoubleColumnRow = ({children}: {children: ReactNode}) => <div className="flex flex-col lg:flex-row gap-8 w-full">{children}</div>;
|
||||
const DoubleColumnRow = ({ children }: { children: ReactNode }) => (
|
||||
<div className="flex flex-col lg:flex-row gap-8 w-full">{children}</div>
|
||||
);
|
||||
|
||||
function UserProfile({user, mutateUser}: Props) {
|
||||
function UserProfile({ user, mutateUser }: Props) {
|
||||
const [bio, setBio] = useState(user.bio || "");
|
||||
const [name, setName] = useState(user.name || "");
|
||||
const [email, setEmail] = useState(user.email || "");
|
||||
@@ -75,49 +94,88 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [profilePicture, setProfilePicture] = useState(user.profilePicture);
|
||||
|
||||
const [desiredLevels, setDesiredLevels] = useState<{[key in Module]: number} | undefined>(
|
||||
["developer", "student"].includes(user.type) ? user.desiredLevels : undefined,
|
||||
const [desiredLevels, setDesiredLevels] = useState<
|
||||
{ [key in Module]: number } | undefined
|
||||
>(
|
||||
checkAccess(user, ["developer", "student"]) ? user.desiredLevels : undefined
|
||||
);
|
||||
const [focus, setFocus] = useState<"academic" | "general">(user.focus);
|
||||
|
||||
const [country, setCountry] = useState<string>(user.demographicInformation?.country || "");
|
||||
const [phone, setPhone] = useState<string>(user.demographicInformation?.phone || "");
|
||||
const [gender, setGender] = useState<Gender | undefined>(user.demographicInformation?.gender || undefined);
|
||||
const [employment, setEmployment] = useState<EmploymentStatus | undefined>(
|
||||
user.type === "corporate" || user.type === "mastercorporate" ? undefined : user.demographicInformation?.employment,
|
||||
const [country, setCountry] = useState<string>(
|
||||
user.demographicInformation?.country || ""
|
||||
);
|
||||
const [phone, setPhone] = useState<string>(
|
||||
user.demographicInformation?.phone || ""
|
||||
);
|
||||
const [gender, setGender] = useState<Gender | undefined>(
|
||||
user.demographicInformation?.gender || undefined
|
||||
);
|
||||
const [employment, setEmployment] = useState<EmploymentStatus | undefined>(
|
||||
checkAccess(user, ["corporate", "mastercorporate"])
|
||||
? undefined
|
||||
: (user.demographicInformation as DemographicInformation)?.employment
|
||||
);
|
||||
const [passport_id, setPassportID] = useState<string | undefined>(
|
||||
checkAccess(user, ["student"])
|
||||
? (user.demographicInformation as DemographicInformation)?.passport_id
|
||||
: undefined
|
||||
);
|
||||
const [passport_id, setPassportID] = useState<string | undefined>(user.type === "student" ? user.demographicInformation?.passport_id : undefined);
|
||||
|
||||
const [preferredGender, setPreferredGender] = useState<InstructorGender | undefined>(
|
||||
user.type === "student" || user.type === "developer" ? user.preferredGender || "varied" : undefined,
|
||||
const [preferredGender, setPreferredGender] = useState<
|
||||
InstructorGender | undefined
|
||||
>(
|
||||
user.type === "student" || user.type === "developer"
|
||||
? user.preferredGender || "varied"
|
||||
: undefined
|
||||
);
|
||||
const [preferredTopics, setPreferredTopics] = useState<string[] | undefined>(
|
||||
user.type === "student" || user.type === "developer" ? user.preferredTopics : undefined,
|
||||
user.type === "student" || user.type === "developer"
|
||||
? user.preferredTopics
|
||||
: undefined
|
||||
);
|
||||
|
||||
const [position, setPosition] = useState<string | undefined>(user.type === "corporate" ? user.demographicInformation?.position : undefined);
|
||||
const [corporateInformation, setCorporateInformation] = useState(user.type === "corporate" ? user.corporateInformation : undefined);
|
||||
const [companyName, setCompanyName] = useState<string | undefined>(user.type === "agent" ? user.agentInformation?.companyName : undefined);
|
||||
const [commercialRegistration, setCommercialRegistration] = useState<string | undefined>(
|
||||
user.type === "agent" ? user.agentInformation?.commercialRegistration : undefined,
|
||||
const [position, setPosition] = useState<string | undefined>(
|
||||
user.type === "corporate"
|
||||
? user.demographicInformation?.position
|
||||
: undefined
|
||||
);
|
||||
const [corporateInformation, setCorporateInformation] = useState(
|
||||
user.type === "corporate" ? user.corporateInformation : undefined
|
||||
);
|
||||
const [companyName, setCompanyName] = useState<string | undefined>(
|
||||
user.type === "agent" ? user.agentInformation?.companyName : undefined
|
||||
);
|
||||
const [commercialRegistration, setCommercialRegistration] = useState<
|
||||
string | undefined
|
||||
>(
|
||||
user.type === "agent"
|
||||
? user.agentInformation?.commercialRegistration
|
||||
: undefined
|
||||
);
|
||||
const [arabName, setArabName] = useState<string | undefined>(
|
||||
user.type === "agent" ? user.agentInformation?.companyArabName : undefined
|
||||
);
|
||||
const [arabName, setArabName] = useState<string | undefined>(user.type === "agent" ? user.agentInformation?.companyArabName : undefined);
|
||||
|
||||
const [timezone, setTimezone] = useState<string>(user.demographicInformation?.timezone || moment.tz.guess());
|
||||
const [timezone, setTimezone] = useState<string>(
|
||||
user.demographicInformation?.timezone || moment.tz.guess()
|
||||
);
|
||||
|
||||
const [isPreferredTopicsOpen, setIsPreferredTopicsOpen] = useState(false);
|
||||
|
||||
const {groups} = useGroups();
|
||||
const {users} = useUsers();
|
||||
const { groups } = useGroups();
|
||||
const { users } = useUsers();
|
||||
|
||||
const profilePictureInput = useRef(null);
|
||||
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";
|
||||
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 uploadProfilePicture = async (event: ChangeEvent<HTMLInputElement>) => {
|
||||
@@ -137,15 +195,20 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
}
|
||||
|
||||
if (newPassword && !password) {
|
||||
toast.error("To update your password you need to input your current one!");
|
||||
toast.error(
|
||||
"To update your password you need to input your current one!"
|
||||
);
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (email !== user?.email) {
|
||||
const userAdmins = groups.filter((x) => x.participants.includes(user.id)).map((x) => x.admin);
|
||||
const userAdmins = groups
|
||||
.filter((x) => x.participants.includes(user.id))
|
||||
.map((x) => x.admin);
|
||||
const message =
|
||||
users.filter((x) => userAdmins.includes(x.id) && x.type === "corporate").length > 0
|
||||
users.filter((x) => userAdmins.includes(x.id) && x.type === "corporate")
|
||||
.length > 0
|
||||
? "If you change your e-mail address, you will lose all benefits from your university/institute. Are you sure you want to continue?"
|
||||
: "Are you sure you want to update your e-mail address?";
|
||||
|
||||
@@ -176,7 +239,7 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
passport_id,
|
||||
timezone,
|
||||
},
|
||||
...(user.type === "corporate" ? {corporateInformation} : {}),
|
||||
...(user.type === "corporate" ? { corporateInformation } : {}),
|
||||
...(user.type === "agent"
|
||||
? {
|
||||
agentInformation: {
|
||||
@@ -190,7 +253,7 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
.then((response) => {
|
||||
if (response.status === 200) {
|
||||
toast.success("Your profile has been updated!");
|
||||
mutateUser((response.data as {user: User}).user);
|
||||
mutateUser((response.data as { user: User }).user);
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
@@ -206,7 +269,9 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
|
||||
const ExpirationDate = () => (
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Expiry Date (click to purchase)</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Expiry Date (click to purchase)
|
||||
</label>
|
||||
<Link
|
||||
href="/payment"
|
||||
className={clsx(
|
||||
@@ -215,22 +280,30 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
!user.subscriptionExpirationDate
|
||||
? "!bg-mti-green-ultralight !border-mti-green-light"
|
||||
: expirationDateColor(user.subscriptionExpirationDate),
|
||||
"bg-white border-mti-gray-platinum",
|
||||
)}>
|
||||
"bg-white border-mti-gray-platinum"
|
||||
)}
|
||||
>
|
||||
{!user.subscriptionExpirationDate && "Unlimited"}
|
||||
{user.subscriptionExpirationDate && moment(user.subscriptionExpirationDate).format("DD/MM/YYYY")}
|
||||
{user.subscriptionExpirationDate &&
|
||||
moment(user.subscriptionExpirationDate).format("DD/MM/YYYY")}
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
|
||||
const TimezoneInput = () => (
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Timezone</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Timezone
|
||||
</label>
|
||||
<TimezoneSelect value={timezone} onChange={setTimezone} />
|
||||
</div>
|
||||
);
|
||||
|
||||
const manualDownloadLink = ["student", "teacher", "corporate"].includes(user.type) ? `/manuals/${user.type}.pdf` : "";
|
||||
const manualDownloadLink = ["student", "teacher", "corporate"].includes(
|
||||
user.type
|
||||
)
|
||||
? `/manuals/${user.type}.pdf`
|
||||
: "";
|
||||
|
||||
return (
|
||||
<Layout user={user}>
|
||||
@@ -239,7 +312,10 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
<div className="flex -md:flex-col-reverse -md:items-center w-full justify-between">
|
||||
<div className="flex flex-col gap-8 w-full md:w-2/3">
|
||||
<h1 className="text-4xl font-bold mb-6 -md:hidden">Edit Profile</h1>
|
||||
<form className="flex flex-col items-center gap-6 w-full" onSubmit={(e) => e.preventDefault()}>
|
||||
<form
|
||||
className="flex flex-col items-center gap-6 w-full"
|
||||
onSubmit={(e) => e.preventDefault()}
|
||||
>
|
||||
<DoubleColumnRow>
|
||||
{user.type !== "corporate" ? (
|
||||
<Input
|
||||
@@ -335,7 +411,9 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
|
||||
<DoubleColumnRow>
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Country *</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Country *
|
||||
</label>
|
||||
<CountrySelect value={country} onChange={setCountry} />
|
||||
</div>
|
||||
<Input
|
||||
@@ -368,26 +446,37 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
|
||||
<Divider />
|
||||
|
||||
{desiredLevels && ["developer", "student"].includes(user.type) && (
|
||||
{desiredLevels &&
|
||||
["developer", "student"].includes(user.type) && (
|
||||
<>
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Desired Levels</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Desired Levels
|
||||
</label>
|
||||
<ModuleLevelSelector
|
||||
levels={desiredLevels}
|
||||
setLevels={setDesiredLevels as Dispatch<SetStateAction<{[key in Module]: number}>>}
|
||||
setLevels={
|
||||
setDesiredLevels as Dispatch<
|
||||
SetStateAction<{ [key in Module]: number }>
|
||||
>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Focus</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Focus
|
||||
</label>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-y-4 gap-x-16 w-full">
|
||||
<button
|
||||
onClick={() => setFocus("academic")}
|
||||
className={clsx(
|
||||
"w-full border border-mti-gray-platinum rounded-full px-6 py-4 flex justify-center items-center gap-12 bg-white",
|
||||
"hover:bg-mti-purple-light hover:text-white",
|
||||
focus === "academic" && "!bg-mti-purple-light !text-white",
|
||||
"transition duration-300 ease-in-out",
|
||||
)}>
|
||||
focus === "academic" &&
|
||||
"!bg-mti-purple-light !text-white",
|
||||
"transition duration-300 ease-in-out"
|
||||
)}
|
||||
>
|
||||
Academic
|
||||
</button>
|
||||
<button
|
||||
@@ -395,9 +484,11 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
className={clsx(
|
||||
"w-full border border-mti-gray-platinum rounded-full px-6 py-4 flex justify-center items-center gap-12 bg-white",
|
||||
"hover:bg-mti-purple-light hover:text-white",
|
||||
focus === "general" && "!bg-mti-purple-light !text-white",
|
||||
"transition duration-300 ease-in-out",
|
||||
)}>
|
||||
focus === "general" &&
|
||||
"!bg-mti-purple-light !text-white",
|
||||
"transition duration-300 ease-in-out"
|
||||
)}
|
||||
>
|
||||
General
|
||||
</button>
|
||||
</div>
|
||||
@@ -405,22 +496,31 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
</>
|
||||
)}
|
||||
|
||||
{preferredGender && ["developer", "student"].includes(user.type) && (
|
||||
{preferredGender &&
|
||||
["developer", "student"].includes(user.type) && (
|
||||
<>
|
||||
<Divider />
|
||||
<DoubleColumnRow>
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Speaking Instructor's Gender</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Speaking Instructor's Gender
|
||||
</label>
|
||||
<Select
|
||||
value={{
|
||||
value: preferredGender,
|
||||
label: capitalize(preferredGender),
|
||||
}}
|
||||
onChange={(value) => (value ? setPreferredGender(value.value as InstructorGender) : null)}
|
||||
onChange={(value) =>
|
||||
value
|
||||
? setPreferredGender(
|
||||
value.value as InstructorGender
|
||||
)
|
||||
: null
|
||||
}
|
||||
options={[
|
||||
{value: "male", label: "Male"},
|
||||
{value: "female", label: "Female"},
|
||||
{value: "varied", label: "Varied"},
|
||||
{ value: "male", label: "Male" },
|
||||
{ value: "female", label: "Female" },
|
||||
{ value: "varied", label: "Varied" },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
@@ -429,12 +529,18 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
Preferred Topics{" "}
|
||||
<span
|
||||
className="tooltip"
|
||||
data-tip="These topics will be considered for speaking and writing modules, aiming to include at least one exercise containing of the these in the selected exams.">
|
||||
data-tip="These topics will be considered for speaking and writing modules, aiming to include at least one exercise containing of the these in the selected exams."
|
||||
>
|
||||
<BsQuestionCircleFill />
|
||||
</span>
|
||||
</label>
|
||||
<Button className="w-full" variant="outline" onClick={() => setIsPreferredTopicsOpen(true)}>
|
||||
Select Topics ({preferredTopics?.length || "All"} selected)
|
||||
<Button
|
||||
className="w-full"
|
||||
variant="outline"
|
||||
onClick={() => setIsPreferredTopicsOpen(true)}
|
||||
>
|
||||
Select Topics ({preferredTopics?.length || "All"}{" "}
|
||||
selected)
|
||||
</Button>
|
||||
</div>
|
||||
</DoubleColumnRow>
|
||||
@@ -459,7 +565,9 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
name="companyUsers"
|
||||
onChange={() => null}
|
||||
label="Number of users"
|
||||
defaultValue={user.corporateInformation.companyInformation.userAmount}
|
||||
defaultValue={
|
||||
user.corporateInformation.companyInformation.userAmount
|
||||
}
|
||||
disabled
|
||||
required
|
||||
/>
|
||||
@@ -503,14 +611,20 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
</>
|
||||
)}
|
||||
|
||||
{user.type === "corporate" && user.corporateInformation.referralAgent && (
|
||||
{user.type === "corporate" &&
|
||||
user.corporateInformation.referralAgent && (
|
||||
<>
|
||||
<Divider />
|
||||
<DoubleColumnRow>
|
||||
<Input
|
||||
name="agentName"
|
||||
onChange={() => null}
|
||||
defaultValue={users.find((x) => x.id === user.corporateInformation.referralAgent)?.name}
|
||||
defaultValue={
|
||||
users.find(
|
||||
(x) =>
|
||||
x.id === user.corporateInformation.referralAgent
|
||||
)?.name
|
||||
}
|
||||
type="text"
|
||||
label="Country Manager's Name"
|
||||
placeholder="Not available"
|
||||
@@ -520,7 +634,12 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
<Input
|
||||
name="agentEmail"
|
||||
onChange={() => null}
|
||||
defaultValue={users.find((x) => x.id === user.corporateInformation.referralAgent)?.email}
|
||||
defaultValue={
|
||||
users.find(
|
||||
(x) =>
|
||||
x.id === user.corporateInformation.referralAgent
|
||||
)?.email
|
||||
}
|
||||
type="text"
|
||||
label="Country Manager's E-mail"
|
||||
placeholder="Not available"
|
||||
@@ -530,11 +649,15 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
</DoubleColumnRow>
|
||||
<DoubleColumnRow>
|
||||
<div className="flex flex-col gap-2 w-full">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Country Manager's Country *</label>
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
Country Manager's Country *
|
||||
</label>
|
||||
<CountrySelect
|
||||
value={
|
||||
users.find((x) => x.id === user.corporateInformation.referralAgent)?.demographicInformation
|
||||
?.country
|
||||
users.find(
|
||||
(x) =>
|
||||
x.id === user.corporateInformation.referralAgent
|
||||
)?.demographicInformation?.country
|
||||
}
|
||||
onChange={() => null}
|
||||
disabled
|
||||
@@ -548,7 +671,10 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
onChange={() => null}
|
||||
placeholder="Not available"
|
||||
defaultValue={
|
||||
users.find((x) => x.id === user.corporateInformation.referralAgent)?.demographicInformation?.phone
|
||||
users.find(
|
||||
(x) =>
|
||||
x.id === user.corporateInformation.referralAgent
|
||||
)?.demographicInformation?.phone
|
||||
}
|
||||
disabled
|
||||
required
|
||||
@@ -559,7 +685,10 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
|
||||
{user.type !== "corporate" && (
|
||||
<DoubleColumnRow>
|
||||
<EmploymentStatusInput value={employment} onChange={setEmployment} />
|
||||
<EmploymentStatusInput
|
||||
value={employment}
|
||||
onChange={setEmployment}
|
||||
/>
|
||||
|
||||
<div className="flex flex-col gap-8 w-full">
|
||||
<GenderInput value={gender} onChange={setGender} />
|
||||
@@ -572,37 +701,62 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
<div className="flex flex-col gap-6 w-48">
|
||||
<div
|
||||
className="flex flex-col gap-3 items-center h-fit cursor-pointer group"
|
||||
onClick={() => (profilePictureInput.current as any)?.click()}>
|
||||
onClick={() => (profilePictureInput.current as any)?.click()}
|
||||
>
|
||||
<div className="relative overflow-hidden h-48 w-48 rounded-full">
|
||||
<div
|
||||
className={clsx(
|
||||
"absolute top-0 left-0 bg-mti-purple-light/60 w-full h-full z-20 flex items-center justify-center opacity-0 group-hover:opacity-100",
|
||||
"transition ease-in-out duration-300",
|
||||
)}>
|
||||
"transition ease-in-out duration-300"
|
||||
)}
|
||||
>
|
||||
<BsCamera className="text-6xl text-mti-purple-ultralight/80" />
|
||||
</div>
|
||||
<img src={profilePicture} alt={user.name} className="aspect-square drop-shadow-xl self-end object-cover" />
|
||||
<img
|
||||
src={profilePicture}
|
||||
alt={user.name}
|
||||
className="aspect-square drop-shadow-xl self-end object-cover"
|
||||
/>
|
||||
</div>
|
||||
<input type="file" className="hidden" onChange={uploadProfilePicture} accept="image/*" ref={profilePictureInput} />
|
||||
<input
|
||||
type="file"
|
||||
className="hidden"
|
||||
onChange={uploadProfilePicture}
|
||||
accept="image/*"
|
||||
ref={profilePictureInput}
|
||||
/>
|
||||
<span
|
||||
onClick={() => (profilePictureInput.current as any)?.click()}
|
||||
className="cursor-pointer text-mti-purple-light text-sm">
|
||||
className="cursor-pointer text-mti-purple-light text-sm"
|
||||
>
|
||||
Change picture
|
||||
</span>
|
||||
<h6 className="font-normal text-base text-mti-gray-taupe">{USER_TYPE_LABELS[user.type]}</h6>
|
||||
<h6 className="font-normal text-base text-mti-gray-taupe">
|
||||
{USER_TYPE_LABELS[user.type]}
|
||||
</h6>
|
||||
</div>
|
||||
{user.type === "agent" && (
|
||||
<div className="flag items-center h-fit">
|
||||
<img
|
||||
alt={user.demographicInformation?.country.toLowerCase() + "_flag"}
|
||||
alt={
|
||||
user.demographicInformation?.country.toLowerCase() + "_flag"
|
||||
}
|
||||
src={`https://flagcdn.com/w320/${user.demographicInformation?.country.toLowerCase()}.png`}
|
||||
width="320"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{manualDownloadLink && (
|
||||
<a href={manualDownloadLink} className="max-w-[200px] self-end w-full" download>
|
||||
<Button color="purple" variant="outline" className="max-w-[200px] self-end w-full">
|
||||
<a
|
||||
href={manualDownloadLink}
|
||||
className="max-w-[200px] self-end w-full"
|
||||
download
|
||||
>
|
||||
<Button
|
||||
color="purple"
|
||||
variant="outline"
|
||||
className="max-w-[200px] self-end w-full"
|
||||
>
|
||||
Download Manual
|
||||
</Button>
|
||||
</a>
|
||||
@@ -621,11 +775,20 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
|
||||
<div className="self-end flex justify-between w-full gap-8 absolute bottom-8 left-0 px-8">
|
||||
<Link href="/" className="max-w-[200px] self-end w-full">
|
||||
<Button color="purple" variant="outline" className="max-w-[200px] self-end w-full">
|
||||
<Button
|
||||
color="purple"
|
||||
variant="outline"
|
||||
className="max-w-[200px] self-end w-full"
|
||||
>
|
||||
Back
|
||||
</Button>
|
||||
</Link>
|
||||
<Button color="purple" className="max-w-[200px] self-end w-full" onClick={updateUser} disabled={isLoading}>
|
||||
<Button
|
||||
color="purple"
|
||||
className="max-w-[200px] self-end w-full"
|
||||
onClick={updateUser}
|
||||
disabled={isLoading}
|
||||
>
|
||||
Save Changes
|
||||
</Button>
|
||||
</div>
|
||||
@@ -635,7 +798,7 @@ function UserProfile({user, mutateUser}: Props) {
|
||||
}
|
||||
|
||||
export default function Home() {
|
||||
const {user, mutateUser} = useUser({redirectTo: "/login"});
|
||||
const { user, mutateUser } = useUser({ redirectTo: "/login" });
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user