import {EmploymentStatus, EMPLOYMENT_STATUS, Gender, User} from "@/interfaces/user"; import {FormEvent, useEffect, useState} from "react"; import countryCodes from "country-codes-list"; import {RadioGroup} from "@headlessui/react"; import Input from "./Low/Input"; import clsx from "clsx"; import Button from "./Low/Button"; import {BsArrowRepeat} from "react-icons/bs"; import axios from "axios"; import {toast} from "react-toastify"; import {KeyedMutator} from "swr"; import CountrySelect from "./Low/CountrySelect"; import GenderInput from "@/components/High/GenderInput"; import EmploymentStatusInput from "@/components/High/EmploymentStatusInput"; import TimezoneSelect from "./Low/TImezoneSelect"; import moment from "moment"; interface Props { user: User; mutateUser: (user: User) => void; } export default function DemographicInformationInput({user, mutateUser}: Props) { const [country, setCountry] = useState(user.demographicInformation?.country); const [phone, setPhone] = useState(user.demographicInformation?.phone); const [passport_id, setPassportID] = useState(user.type === "student" ? user.demographicInformation?.passport_id : undefined); const [gender, setGender] = useState(); const [employment, setEmployment] = useState(); const [timezone, setTimezone] = useState(moment.tz.guess()); const [isLoading, setIsLoading] = useState(false); const [position, setPosition] = useState( user.type === "corporate" || user.type === "mastercorporate" ? user.demographicInformation?.position : user.demographicInformation?.employment, ); const [companyName, setCompanyName] = useState(); const [commercialRegistration, setCommercialRegistration] = useState(); const save = (e?: FormEvent) => { if (e) e.preventDefault(); setIsLoading(true); axios .patch<{user: User}>("/api/users/update", { demographicInformation: { country, phone: `+${countryCodes.findOne("countryCode" as any, country!).countryCallingCode}${phone}`, gender, employment: user.type === "corporate" ? undefined : employment, position: user.type === "corporate" ? position : undefined, passport_id, timezone, }, agentInformation: user.type === "agent" ? {companyName, commercialRegistration} : undefined, }) .then((response) => mutateUser(response.data.user)) .catch(() => { toast.error("Something went wrong, please try again later!", {toastId: "user-update-error"}); }) .finally(() => setIsLoading(false)); }; return (

Welcome to EnCoach, the ultimate platform dedicated to helping you master the IELTS ! We are thrilled that you have chosen us as your learning companion on this journey towards achieving your desired IELTS score.

To make the most of your learning experience, we kindly request you to complete your profile. By providing some essential information about yourself.

{user.type === "agent" && (
)}
setPhone(e)} value={phone} placeholder="Enter phone number" required />
{user.type === "student" && ( setPassportID(e)} value={passport_id} placeholder="Enter National ID or Passport number" required /> )}
{user.type === "corporate" && ( )} {user.type !== "corporate" && }
); }