import {EmploymentStatus, EMPLOYMENT_STATUS, Gender, User} from "@/interfaces/user"; import {FormEvent, 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"; interface Props { user: User; mutateUser: KeyedMutator; } export default function DemographicInformationInput({user, mutateUser}: Props) { const [country, setCountry] = useState(); const [phone, setPhone] = useState(); const [gender, setGender] = useState(); const [employment, setEmployment] = useState(); const [position, setPosition] = useState(); const [isLoading, setIsLoading] = useState(false); const [companyName, setCompanyName] = useState(); const [commercialRegistration, setCommercialRegistration] = useState(); const save = (e?: FormEvent) => { if (e) e.preventDefault(); setIsLoading(true); axios .patch("/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, }, agentInformation: user.type === "agent" ? {companyName, commercialRegistration} : undefined, }) .then((response) => mutateUser((response.data as {user: User}).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)} placeholder="Enter phone number" required />
{({checked}) => ( Male )} {({checked}) => ( Female )} {({checked}) => ( Other )}
{user.type === "corporate" && ( )} {user.type !== "corporate" && (
{EMPLOYMENT_STATUS.map(({status, label}) => ( {({checked}) => ( {label} )} ))}
)}
); }