diff --git a/backend/api/models/MenteeProfile.py b/backend/api/models/MenteeProfile.py index 13d3bf55..29458d29 100644 --- a/backend/api/models/MenteeProfile.py +++ b/backend/api/models/MenteeProfile.py @@ -34,6 +34,7 @@ class MenteeProfile(Document, Mixin): preferred_language = StringField(required=False, default="en-US") roomName = StringField(required=False) timezone = StringField(required=True) + birthday = DateField(required=False) def __repr__(self): return f"""
+ {props.mentor.birthday && ( + <> +
+ {t("common.birthday")} +
+
{formatDate(new Date(props.mentor.birthday.$date))}
+
+ + )} {accountType === ACCOUNT_TYPE.PARTNER ? ( <> {" "} diff --git a/frontend/src/components/pages/MenteeProfileForm.js b/frontend/src/components/pages/MenteeProfileForm.js index a4532ab6..b2be9148 100644 --- a/frontend/src/components/pages/MenteeProfileForm.js +++ b/frontend/src/components/pages/MenteeProfileForm.js @@ -10,6 +10,7 @@ import { Input, Select, Switch, + DatePicker, } from "antd"; import { useSelector } from "react-redux"; import { @@ -61,6 +62,7 @@ function MenteeProfileForm({ const [countryOptions, setCountryOptions] = useState([]); const [flag, setFlag] = useState(false); const [finishFlag, setFinishFlag] = useState(false); + const [refresh, setRefresh] = useState(false); const immigrantOptions = [ { @@ -143,6 +145,9 @@ function MenteeProfileForm({ form.setFieldValue("organization", null); } setImage(profileData.image); + if (profileData.birthday) { + form.setFieldValue("birthday", moment(profileData.birthday.$date)); + } } if (applicationData) { form.setFieldValue( @@ -229,6 +234,39 @@ function MenteeProfileForm({ onSubmit(newData); }; + function getAgeRange(birthday) { + let res = ""; + if (birthday) { + birthday = birthday.format("YYYY"); + let age = new Date().getFullYear() - birthday; + if (age >= 18 && age <= 22) { + res = "18-22"; + } else if (age >= 23 && age <= 25) { + res = "23-25"; + } else if (age >= 26 && age <= 30) { + res = "26-30"; + } else if (age >= 31 && age < 40) { + res = "30s"; + } else if (age >= 41 && age < 50) { + res = "40s"; + } else if (age >= 51 && age < 60) { + res = "50s"; + } else if (age >= 61 && age < 70) { + res = "60s"; + } else if (age > 70) { + res = "70s"; + } + } + return res; + } + + const changeBirthday = () => { + let birthday = form.getFieldValue("birthday"); + let age_range = getAgeRange(birthday); + form.setFieldValue("age", age_range); + setRefresh(!refresh); + }; + return (
) : null} + + + changeBirthday()} + /> + + @@ -381,7 +439,10 @@ function MenteeProfileForm({ ]} className={styles.formGroupItem} > - { }); }; +export const formatDate = (time_object) => { + const month = time_object.getMonth() + 1; // Adding 1 because months are 0-indexed + const day = time_object.getDate(); + const year = time_object.getFullYear(); + + const formattedDate = `${month.toString().padStart(2, "0")}/${day + .toString() + .padStart(2, "0")}/${year}`; + + return formattedDate; +}; + export const formatDateTime = (time_object) => { const month = time_object.getMonth() + 1; // Adding 1 because months are 0-indexed const day = time_object.getDate();