Updated the profile to also have the focus in it
This commit is contained in:
@@ -1,53 +1,39 @@
|
|||||||
/* eslint-disable @next/next/no-img-element */
|
/* eslint-disable @next/next/no-img-element */
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import { withIronSessionSsr } from "iron-session/next";
|
import {withIronSessionSsr} from "iron-session/next";
|
||||||
import { sessionOptions } from "@/lib/session";
|
import {sessionOptions} from "@/lib/session";
|
||||||
import {
|
import {ChangeEvent, Dispatch, ReactNode, SetStateAction, useEffect, useRef, useState} from "react";
|
||||||
ChangeEvent,
|
|
||||||
Dispatch,
|
|
||||||
ReactNode,
|
|
||||||
SetStateAction,
|
|
||||||
useEffect,
|
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
} from "react";
|
|
||||||
import useUser from "@/hooks/useUser";
|
import useUser from "@/hooks/useUser";
|
||||||
import { toast, ToastContainer } from "react-toastify";
|
import {toast, ToastContainer} from "react-toastify";
|
||||||
import Layout from "@/components/High/Layout";
|
import Layout from "@/components/High/Layout";
|
||||||
import Input from "@/components/Low/Input";
|
import Input from "@/components/Low/Input";
|
||||||
import Button from "@/components/Low/Button";
|
import Button from "@/components/Low/Button";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { ErrorMessage } from "@/constants/errors";
|
import {ErrorMessage} from "@/constants/errors";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import {
|
import {CorporateUser, EmploymentStatus, EMPLOYMENT_STATUS, Gender, User} from "@/interfaces/user";
|
||||||
CorporateUser,
|
|
||||||
EmploymentStatus,
|
|
||||||
EMPLOYMENT_STATUS,
|
|
||||||
Gender,
|
|
||||||
User,
|
|
||||||
} from "@/interfaces/user";
|
|
||||||
import CountrySelect from "@/components/Low/CountrySelect";
|
import CountrySelect from "@/components/Low/CountrySelect";
|
||||||
import { shouldRedirectHome } from "@/utils/navigation.disabled";
|
import {shouldRedirectHome} from "@/utils/navigation.disabled";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import { BsCamera, BsQuestionCircleFill } from "react-icons/bs";
|
import {BsCamera, BsQuestionCircleFill} from "react-icons/bs";
|
||||||
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 useUsers from "@/hooks/useUsers";
|
import useUsers from "@/hooks/useUsers";
|
||||||
import { convertBase64 } from "@/utils";
|
import {convertBase64} from "@/utils";
|
||||||
import { Divider } from "primereact/divider";
|
import {Divider} from "primereact/divider";
|
||||||
import GenderInput from "@/components/High/GenderInput";
|
import GenderInput from "@/components/High/GenderInput";
|
||||||
import EmploymentStatusInput from "@/components/High/EmploymentStatusInput";
|
import EmploymentStatusInput from "@/components/High/EmploymentStatusInput";
|
||||||
import TimezoneSelect from "@/components/Low/TImezoneSelect";
|
import TimezoneSelect from "@/components/Low/TImezoneSelect";
|
||||||
import Modal from "@/components/Modal";
|
import Modal from "@/components/Modal";
|
||||||
import { Module } from "@/interfaces";
|
import {Module} from "@/interfaces";
|
||||||
import ModuleLevelSelector from "@/components/Medium/ModuleLevelSelector";
|
import ModuleLevelSelector from "@/components/Medium/ModuleLevelSelector";
|
||||||
import Select from "@/components/Low/Select";
|
import Select from "@/components/Low/Select";
|
||||||
import { InstructorGender } from "@/interfaces/exam";
|
import {InstructorGender} from "@/interfaces/exam";
|
||||||
import { capitalize } from "lodash";
|
import {capitalize} from "lodash";
|
||||||
import TopicModal from "@/components/Medium/TopicModal";
|
import TopicModal from "@/components/Medium/TopicModal";
|
||||||
import { v4 } from "uuid";
|
import {v4} from "uuid";
|
||||||
export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
export const getServerSideProps = withIronSessionSsr(({req, res}) => {
|
||||||
const user = req.session.user;
|
const user = req.session.user;
|
||||||
|
|
||||||
if (!user || !user.isVerified) {
|
if (!user || !user.isVerified) {
|
||||||
@@ -69,7 +55,7 @@ export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: { user: req.session.user },
|
props: {user: req.session.user},
|
||||||
};
|
};
|
||||||
}, sessionOptions);
|
}, sessionOptions);
|
||||||
|
|
||||||
@@ -78,11 +64,9 @@ interface Props {
|
|||||||
mutateUser: Function;
|
mutateUser: Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DoubleColumnRow = ({ children }: { children: ReactNode }) => (
|
const DoubleColumnRow = ({children}: {children: ReactNode}) => <div className="flex flex-col lg:flex-row gap-8 w-full">{children}</div>;
|
||||||
<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 [bio, setBio] = useState(user.bio || "");
|
||||||
const [name, setName] = useState(user.name || "");
|
const [name, setName] = useState(user.name || "");
|
||||||
const [email, setEmail] = useState(user.email || "");
|
const [email, setEmail] = useState(user.email || "");
|
||||||
@@ -91,89 +75,49 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [profilePicture, setProfilePicture] = useState(user.profilePicture);
|
const [profilePicture, setProfilePicture] = useState(user.profilePicture);
|
||||||
|
|
||||||
const [desiredLevels, setDesiredLevels] = useState<
|
const [desiredLevels, setDesiredLevels] = useState<{[key in Module]: number} | undefined>(
|
||||||
{ [key in Module]: number } | undefined
|
["developer", "student"].includes(user.type) ? user.desiredLevels : undefined,
|
||||||
>(
|
|
||||||
["developer", "student"].includes(user.type)
|
|
||||||
? user.desiredLevels
|
|
||||||
: undefined,
|
|
||||||
);
|
);
|
||||||
|
const [focus, setFocus] = useState<"academic" | "general">(user.focus);
|
||||||
|
|
||||||
const [country, setCountry] = useState<string>(
|
const [country, setCountry] = useState<string>(user.demographicInformation?.country || "");
|
||||||
user.demographicInformation?.country || "",
|
const [phone, setPhone] = useState<string>(user.demographicInformation?.phone || "");
|
||||||
);
|
const [gender, setGender] = useState<Gender | undefined>(user.demographicInformation?.gender || undefined);
|
||||||
const [phone, setPhone] = useState<string>(
|
|
||||||
user.demographicInformation?.phone || "",
|
|
||||||
);
|
|
||||||
const [gender, setGender] = useState<Gender | undefined>(
|
|
||||||
user.demographicInformation?.gender || undefined,
|
|
||||||
);
|
|
||||||
const [employment, setEmployment] = useState<EmploymentStatus | undefined>(
|
const [employment, setEmployment] = useState<EmploymentStatus | undefined>(
|
||||||
user.type === "corporate"
|
user.type === "corporate" ? undefined : user.demographicInformation?.employment,
|
||||||
? undefined
|
|
||||||
: user.demographicInformation?.employment,
|
|
||||||
);
|
|
||||||
const [passport_id, setPassportID] = useState<string | undefined>(
|
|
||||||
user.type === "student"
|
|
||||||
? user.demographicInformation?.passport_id
|
|
||||||
: undefined,
|
|
||||||
);
|
);
|
||||||
|
const [passport_id, setPassportID] = useState<string | undefined>(user.type === "student" ? user.demographicInformation?.passport_id : undefined);
|
||||||
|
|
||||||
const [preferredGender, setPreferredGender] = useState<
|
const [preferredGender, setPreferredGender] = useState<InstructorGender | undefined>(
|
||||||
InstructorGender | undefined
|
user.type === "student" || user.type === "developer" ? user.preferredGender || "varied" : undefined,
|
||||||
>(
|
|
||||||
user.type === "student" || user.type === "developer"
|
|
||||||
? user.preferredGender || "varied"
|
|
||||||
: undefined,
|
|
||||||
);
|
);
|
||||||
const [preferredTopics, setPreferredTopics] = useState<string[] | undefined>(
|
const [preferredTopics, setPreferredTopics] = useState<string[] | undefined>(
|
||||||
user.type === "student" || user.type === "developer"
|
user.type === "student" || user.type === "developer" ? user.preferredTopics : undefined,
|
||||||
? user.preferredTopics
|
|
||||||
: undefined,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const [position, setPosition] = useState<string | undefined>(
|
const [position, setPosition] = useState<string | undefined>(user.type === "corporate" ? user.demographicInformation?.position : undefined);
|
||||||
user.type === "corporate"
|
const [corporateInformation, setCorporateInformation] = useState(user.type === "corporate" ? user.corporateInformation : undefined);
|
||||||
? user.demographicInformation?.position
|
const [companyName, setCompanyName] = useState<string | undefined>(user.type === "agent" ? user.agentInformation?.companyName : undefined);
|
||||||
: undefined,
|
const [commercialRegistration, setCommercialRegistration] = useState<string | undefined>(
|
||||||
);
|
user.type === "agent" ? user.agentInformation?.commercialRegistration : 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>(
|
const [timezone, setTimezone] = useState<string>(user.demographicInformation?.timezone || moment.tz.guess());
|
||||||
user.demographicInformation?.timezone || moment.tz.guess(),
|
|
||||||
);
|
|
||||||
|
|
||||||
const [isPreferredTopicsOpen, setIsPreferredTopicsOpen] = useState(false);
|
const [isPreferredTopicsOpen, setIsPreferredTopicsOpen] = useState(false);
|
||||||
|
|
||||||
const { groups } = useGroups();
|
const {groups} = useGroups();
|
||||||
const { users } = useUsers();
|
const {users} = useUsers();
|
||||||
|
|
||||||
const profilePictureInput = useRef(null);
|
const profilePictureInput = useRef(null);
|
||||||
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 uploadProfilePicture = async (event: ChangeEvent<HTMLInputElement>) => {
|
const uploadProfilePicture = async (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
@@ -193,20 +137,15 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newPassword && !password) {
|
if (newPassword && !password) {
|
||||||
toast.error(
|
toast.error("To update your password you need to input your current one!");
|
||||||
"To update your password you need to input your current one!",
|
|
||||||
);
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (email !== user?.email) {
|
if (email !== user?.email) {
|
||||||
const userAdmins = groups
|
const userAdmins = groups.filter((x) => x.participants.includes(user.id)).map((x) => x.admin);
|
||||||
.filter((x) => x.participants.includes(user.id))
|
|
||||||
.map((x) => x.admin);
|
|
||||||
const message =
|
const message =
|
||||||
users.filter((x) => userAdmins.includes(x.id) && x.type === "corporate")
|
users.filter((x) => userAdmins.includes(x.id) && x.type === "corporate").length > 0
|
||||||
.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?"
|
? "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?";
|
: "Are you sure you want to update your e-mail address?";
|
||||||
|
|
||||||
@@ -227,6 +166,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
desiredLevels,
|
desiredLevels,
|
||||||
preferredGender,
|
preferredGender,
|
||||||
preferredTopics,
|
preferredTopics,
|
||||||
|
focus,
|
||||||
demographicInformation: {
|
demographicInformation: {
|
||||||
phone,
|
phone,
|
||||||
country,
|
country,
|
||||||
@@ -236,7 +176,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
passport_id,
|
passport_id,
|
||||||
timezone,
|
timezone,
|
||||||
},
|
},
|
||||||
...(user.type === "corporate" ? { corporateInformation } : {}),
|
...(user.type === "corporate" ? {corporateInformation} : {}),
|
||||||
...(user.type === "agent"
|
...(user.type === "agent"
|
||||||
? {
|
? {
|
||||||
agentInformation: {
|
agentInformation: {
|
||||||
@@ -250,7 +190,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
toast.success("Your profile has been updated!");
|
toast.success("Your profile has been updated!");
|
||||||
mutateUser((response.data as { user: User }).user);
|
mutateUser((response.data as {user: User}).user);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -266,9 +206,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
|
|
||||||
const ExpirationDate = () => (
|
const ExpirationDate = () => (
|
||||||
<div className="flex flex-col gap-3 w-full">
|
<div className="flex flex-col gap-3 w-full">
|
||||||
<label className="font-normal text-base text-mti-gray-dim">
|
<label className="font-normal text-base text-mti-gray-dim">Expiry Date (click to purchase)</label>
|
||||||
Expiry Date (click to purchase)
|
|
||||||
</label>
|
|
||||||
<Link
|
<Link
|
||||||
href="/payment"
|
href="/payment"
|
||||||
className={clsx(
|
className={clsx(
|
||||||
@@ -278,29 +216,21 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
? "!bg-mti-green-ultralight !border-mti-green-light"
|
? "!bg-mti-green-ultralight !border-mti-green-light"
|
||||||
: expirationDateColor(user.subscriptionExpirationDate),
|
: expirationDateColor(user.subscriptionExpirationDate),
|
||||||
"bg-white border-mti-gray-platinum",
|
"bg-white border-mti-gray-platinum",
|
||||||
)}
|
)}>
|
||||||
>
|
|
||||||
{!user.subscriptionExpirationDate && "Unlimited"}
|
{!user.subscriptionExpirationDate && "Unlimited"}
|
||||||
{user.subscriptionExpirationDate &&
|
{user.subscriptionExpirationDate && moment(user.subscriptionExpirationDate).format("DD/MM/YYYY")}
|
||||||
moment(user.subscriptionExpirationDate).format("DD/MM/YYYY")}
|
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const TimezoneInput = () => (
|
const TimezoneInput = () => (
|
||||||
<div className="flex flex-col gap-3 w-full">
|
<div className="flex flex-col gap-3 w-full">
|
||||||
<label className="font-normal text-base text-mti-gray-dim">
|
<label className="font-normal text-base text-mti-gray-dim">Timezone</label>
|
||||||
Timezone
|
|
||||||
</label>
|
|
||||||
<TimezoneSelect value={timezone} onChange={setTimezone} />
|
<TimezoneSelect value={timezone} onChange={setTimezone} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
const manualDownloadLink = ["student", "teacher", "corporate"].includes(
|
const manualDownloadLink = ["student", "teacher", "corporate"].includes(user.type) ? `/manuals/${user.type}.pdf` : "";
|
||||||
user.type,
|
|
||||||
)
|
|
||||||
? `/manuals/${user.type}.pdf`
|
|
||||||
: "";
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout user={user}>
|
<Layout user={user}>
|
||||||
@@ -309,10 +239,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
<div className="flex -md:flex-col-reverse -md:items-center w-full justify-between">
|
<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">
|
<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>
|
<h1 className="text-4xl font-bold mb-6 -md:hidden">Edit Profile</h1>
|
||||||
<form
|
<form className="flex flex-col items-center gap-6 w-full" onSubmit={(e) => e.preventDefault()}>
|
||||||
className="flex flex-col items-center gap-6 w-full"
|
|
||||||
onSubmit={(e) => e.preventDefault()}
|
|
||||||
>
|
|
||||||
<DoubleColumnRow>
|
<DoubleColumnRow>
|
||||||
{user.type !== "corporate" ? (
|
{user.type !== "corporate" ? (
|
||||||
<Input
|
<Input
|
||||||
@@ -408,9 +335,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
|
|
||||||
<DoubleColumnRow>
|
<DoubleColumnRow>
|
||||||
<div className="flex flex-col gap-3 w-full">
|
<div className="flex flex-col gap-3 w-full">
|
||||||
<label className="font-normal text-base text-mti-gray-dim">
|
<label className="font-normal text-base text-mti-gray-dim">Country *</label>
|
||||||
Country *
|
|
||||||
</label>
|
|
||||||
<CountrySelect value={country} onChange={setCountry} />
|
<CountrySelect value={country} onChange={setCountry} />
|
||||||
</div>
|
</div>
|
||||||
<Input
|
<Input
|
||||||
@@ -443,48 +368,59 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
{desiredLevels &&
|
{desiredLevels && ["developer", "student"].includes(user.type) && (
|
||||||
["developer", "student"].includes(user.type) && (
|
<>
|
||||||
<div className="flex flex-col gap-3 w-full">
|
<div className="flex flex-col gap-3 w-full">
|
||||||
<label className="font-normal text-base text-mti-gray-dim">
|
<label className="font-normal text-base text-mti-gray-dim">Desired Levels</label>
|
||||||
Desired Levels
|
|
||||||
</label>
|
|
||||||
<ModuleLevelSelector
|
<ModuleLevelSelector
|
||||||
levels={desiredLevels}
|
levels={desiredLevels}
|
||||||
setLevels={
|
setLevels={setDesiredLevels as Dispatch<SetStateAction<{[key in Module]: number}>>}
|
||||||
setDesiredLevels as Dispatch<
|
|
||||||
SetStateAction<{ [key in Module]: number }>
|
|
||||||
>
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="flex flex-col gap-3 w-full">
|
||||||
|
<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",
|
||||||
|
)}>
|
||||||
|
Academic
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => setFocus("general")}
|
||||||
|
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",
|
||||||
|
)}>
|
||||||
|
General
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{preferredGender &&
|
{preferredGender && ["developer", "student"].includes(user.type) && (
|
||||||
["developer", "student"].includes(user.type) && (
|
|
||||||
<>
|
<>
|
||||||
<Divider />
|
<Divider />
|
||||||
<DoubleColumnRow>
|
<DoubleColumnRow>
|
||||||
<div className="flex flex-col gap-3 w-full">
|
<div className="flex flex-col gap-3 w-full">
|
||||||
<label className="font-normal text-base text-mti-gray-dim">
|
<label className="font-normal text-base text-mti-gray-dim">Speaking Instructor's Gender</label>
|
||||||
Speaking Instructor's Gender
|
|
||||||
</label>
|
|
||||||
<Select
|
<Select
|
||||||
value={{
|
value={{
|
||||||
value: preferredGender,
|
value: preferredGender,
|
||||||
label: capitalize(preferredGender),
|
label: capitalize(preferredGender),
|
||||||
}}
|
}}
|
||||||
onChange={(value) =>
|
onChange={(value) => (value ? setPreferredGender(value.value as InstructorGender) : null)}
|
||||||
value
|
|
||||||
? setPreferredGender(
|
|
||||||
value.value as InstructorGender,
|
|
||||||
)
|
|
||||||
: null
|
|
||||||
}
|
|
||||||
options={[
|
options={[
|
||||||
{ value: "male", label: "Male" },
|
{value: "male", label: "Male"},
|
||||||
{ value: "female", label: "Female" },
|
{value: "female", label: "Female"},
|
||||||
{ value: "varied", label: "Varied" },
|
{value: "varied", label: "Varied"},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -493,18 +429,12 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
Preferred Topics{" "}
|
Preferred Topics{" "}
|
||||||
<span
|
<span
|
||||||
className="tooltip"
|
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 />
|
<BsQuestionCircleFill />
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
<Button
|
<Button className="w-full" variant="outline" onClick={() => setIsPreferredTopicsOpen(true)}>
|
||||||
className="w-full"
|
Select Topics ({preferredTopics?.length || "All"} selected)
|
||||||
variant="outline"
|
|
||||||
onClick={() => setIsPreferredTopicsOpen(true)}
|
|
||||||
>
|
|
||||||
Select Topics ({preferredTopics?.length || "All"}{" "}
|
|
||||||
selected)
|
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</DoubleColumnRow>
|
</DoubleColumnRow>
|
||||||
@@ -529,9 +459,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
name="companyUsers"
|
name="companyUsers"
|
||||||
onChange={() => null}
|
onChange={() => null}
|
||||||
label="Number of users"
|
label="Number of users"
|
||||||
defaultValue={
|
defaultValue={user.corporateInformation.companyInformation.userAmount}
|
||||||
user.corporateInformation.companyInformation.userAmount
|
|
||||||
}
|
|
||||||
disabled
|
disabled
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
@@ -575,20 +503,14 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{user.type === "corporate" &&
|
{user.type === "corporate" && user.corporateInformation.referralAgent && (
|
||||||
user.corporateInformation.referralAgent && (
|
|
||||||
<>
|
<>
|
||||||
<Divider />
|
<Divider />
|
||||||
<DoubleColumnRow>
|
<DoubleColumnRow>
|
||||||
<Input
|
<Input
|
||||||
name="agentName"
|
name="agentName"
|
||||||
onChange={() => null}
|
onChange={() => null}
|
||||||
defaultValue={
|
defaultValue={users.find((x) => x.id === user.corporateInformation.referralAgent)?.name}
|
||||||
users.find(
|
|
||||||
(x) =>
|
|
||||||
x.id === user.corporateInformation.referralAgent,
|
|
||||||
)?.name
|
|
||||||
}
|
|
||||||
type="text"
|
type="text"
|
||||||
label="Country Manager's Name"
|
label="Country Manager's Name"
|
||||||
placeholder="Not available"
|
placeholder="Not available"
|
||||||
@@ -598,12 +520,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
<Input
|
<Input
|
||||||
name="agentEmail"
|
name="agentEmail"
|
||||||
onChange={() => null}
|
onChange={() => null}
|
||||||
defaultValue={
|
defaultValue={users.find((x) => x.id === user.corporateInformation.referralAgent)?.email}
|
||||||
users.find(
|
|
||||||
(x) =>
|
|
||||||
x.id === user.corporateInformation.referralAgent,
|
|
||||||
)?.email
|
|
||||||
}
|
|
||||||
type="text"
|
type="text"
|
||||||
label="Country Manager's E-mail"
|
label="Country Manager's E-mail"
|
||||||
placeholder="Not available"
|
placeholder="Not available"
|
||||||
@@ -613,16 +530,11 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
</DoubleColumnRow>
|
</DoubleColumnRow>
|
||||||
<DoubleColumnRow>
|
<DoubleColumnRow>
|
||||||
<div className="flex flex-col gap-2 w-full">
|
<div className="flex flex-col gap-2 w-full">
|
||||||
<label className="font-normal text-base text-mti-gray-dim">
|
<label className="font-normal text-base text-mti-gray-dim">Country Manager's Country *</label>
|
||||||
Country Manager's Country *
|
|
||||||
</label>
|
|
||||||
<CountrySelect
|
<CountrySelect
|
||||||
value={
|
value={
|
||||||
users.find(
|
users.find((x) => x.id === user.corporateInformation.referralAgent)?.demographicInformation
|
||||||
(x) =>
|
?.country
|
||||||
x.id ===
|
|
||||||
user.corporateInformation.referralAgent,
|
|
||||||
)?.demographicInformation?.country
|
|
||||||
}
|
}
|
||||||
onChange={() => null}
|
onChange={() => null}
|
||||||
disabled
|
disabled
|
||||||
@@ -636,10 +548,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
onChange={() => null}
|
onChange={() => null}
|
||||||
placeholder="Not available"
|
placeholder="Not available"
|
||||||
defaultValue={
|
defaultValue={
|
||||||
users.find(
|
users.find((x) => x.id === user.corporateInformation.referralAgent)?.demographicInformation?.phone
|
||||||
(x) =>
|
|
||||||
x.id === user.corporateInformation.referralAgent,
|
|
||||||
)?.demographicInformation?.phone
|
|
||||||
}
|
}
|
||||||
disabled
|
disabled
|
||||||
required
|
required
|
||||||
@@ -650,10 +559,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
|
|
||||||
{user.type !== "corporate" && (
|
{user.type !== "corporate" && (
|
||||||
<DoubleColumnRow>
|
<DoubleColumnRow>
|
||||||
<EmploymentStatusInput
|
<EmploymentStatusInput value={employment} onChange={setEmployment} />
|
||||||
value={employment}
|
|
||||||
onChange={setEmployment}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div className="flex flex-col gap-8 w-full">
|
<div className="flex flex-col gap-8 w-full">
|
||||||
<GenderInput value={gender} onChange={setGender} />
|
<GenderInput value={gender} onChange={setGender} />
|
||||||
@@ -666,62 +572,37 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
<div className="flex flex-col gap-6 w-48">
|
<div className="flex flex-col gap-6 w-48">
|
||||||
<div
|
<div
|
||||||
className="flex flex-col gap-3 items-center h-fit cursor-pointer group"
|
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="relative overflow-hidden h-48 w-48 rounded-full">
|
||||||
<div
|
<div
|
||||||
className={clsx(
|
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",
|
"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" />
|
<BsCamera className="text-6xl text-mti-purple-ultralight/80" />
|
||||||
</div>
|
</div>
|
||||||
<img
|
<img src={profilePicture} alt={user.name} className="aspect-square drop-shadow-xl self-end object-cover" />
|
||||||
src={profilePicture}
|
|
||||||
alt={user.name}
|
|
||||||
className="aspect-square drop-shadow-xl self-end object-cover"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input type="file" className="hidden" onChange={uploadProfilePicture} accept="image/*" ref={profilePictureInput} />
|
||||||
type="file"
|
|
||||||
className="hidden"
|
|
||||||
onChange={uploadProfilePicture}
|
|
||||||
accept="image/*"
|
|
||||||
ref={profilePictureInput}
|
|
||||||
/>
|
|
||||||
<span
|
<span
|
||||||
onClick={() => (profilePictureInput.current as any)?.click()}
|
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
|
Change picture
|
||||||
</span>
|
</span>
|
||||||
<h6 className="font-normal text-base text-mti-gray-taupe">
|
<h6 className="font-normal text-base text-mti-gray-taupe">{USER_TYPE_LABELS[user.type]}</h6>
|
||||||
{USER_TYPE_LABELS[user.type]}
|
|
||||||
</h6>
|
|
||||||
</div>
|
</div>
|
||||||
{user.type === "agent" && (
|
{user.type === "agent" && (
|
||||||
<div className="flag items-center h-fit">
|
<div className="flag items-center h-fit">
|
||||||
<img
|
<img
|
||||||
alt={
|
alt={user.demographicInformation?.country.toLowerCase() + "_flag"}
|
||||||
user.demographicInformation?.country.toLowerCase() + "_flag"
|
|
||||||
}
|
|
||||||
src={`https://flagcdn.com/w320/${user.demographicInformation?.country.toLowerCase()}.png`}
|
src={`https://flagcdn.com/w320/${user.demographicInformation?.country.toLowerCase()}.png`}
|
||||||
width="320"
|
width="320"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{manualDownloadLink && (
|
{manualDownloadLink && (
|
||||||
<a
|
<a href={manualDownloadLink} className="max-w-[200px] self-end w-full" download>
|
||||||
href={manualDownloadLink}
|
<Button color="purple" variant="outline" className="max-w-[200px] self-end w-full">
|
||||||
className="max-w-[200px] self-end w-full"
|
|
||||||
download
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
color="purple"
|
|
||||||
variant="outline"
|
|
||||||
className="max-w-[200px] self-end w-full"
|
|
||||||
>
|
|
||||||
Download Manual
|
Download Manual
|
||||||
</Button>
|
</Button>
|
||||||
</a>
|
</a>
|
||||||
@@ -740,20 +621,11 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
|
|
||||||
<div className="self-end flex justify-between w-full gap-8 absolute bottom-8 left-0 px-8">
|
<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">
|
<Link href="/" className="max-w-[200px] self-end w-full">
|
||||||
<Button
|
<Button color="purple" variant="outline" className="max-w-[200px] self-end w-full">
|
||||||
color="purple"
|
|
||||||
variant="outline"
|
|
||||||
className="max-w-[200px] self-end w-full"
|
|
||||||
>
|
|
||||||
Back
|
Back
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
<Button
|
<Button color="purple" className="max-w-[200px] self-end w-full" onClick={updateUser} disabled={isLoading}>
|
||||||
color="purple"
|
|
||||||
className="max-w-[200px] self-end w-full"
|
|
||||||
onClick={updateUser}
|
|
||||||
disabled={isLoading}
|
|
||||||
>
|
|
||||||
Save Changes
|
Save Changes
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -763,7 +635,7 @@ function UserProfile({ user, mutateUser }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const { user, mutateUser } = useUser({ redirectTo: "/login" });
|
const {user, mutateUser} = useUser({redirectTo: "/login"});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
Reference in New Issue
Block a user