Skip to content

Commit

Permalink
Merge pull request #1647 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
Dev Server
  • Loading branch information
nashnsulthan authored Oct 11, 2024
2 parents 40dfeff + a44636a commit 3e228d7
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 21 deletions.
10 changes: 10 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import Refund from "./modules/Public/Donation/pages/Refund";
import DonationSuccess from "./modules/Public/Donation/pages/DonationSuccess";
import OpenGrad from "./modules/Dashboard/modules/OpenGrad";
import UserInterest from "./modules/Common/Authentication/pages/Onboarding/UserInterest/UserInterest";
import OrganizationSetting from "./modules/Dashboard/modules/Settings/pages/Organization/Organization";
import SettingsHome from "./modules/Dashboard/modules/Settings/pages/Settings/SettingsHome";

const Profile = lazy(
() => import("./modules/Dashboard/modules/Profile/pages/Profile")
Expand Down Expand Up @@ -731,6 +733,14 @@ function App() {
path: "settings",
element: <Settings />,
children: [
{
path: "",
element: <SettingsHome />
},
{
path: "organization",
element: <OrganizationSetting />
},
{
path: "account",
element: <Account />
Expand Down
42 changes: 21 additions & 21 deletions src/modules/Dashboard/components/SideNavBarBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ const SideNavBarBody = ({
.filter(
button =>
button.hasView &&
((!button.roles ||
(!button.roles ||
button.roles?.some(role =>
userInfo?.roles?.includes(role)
) ||
button.dynamicType?.some(type =>
userInfo?.dynamic_type?.includes(
type as ManagementTypes
)
))
||
(
button.dynamicType?.some(type =>
userInfo?.dynamic_type?.includes(type as ManagementTypes)
))
)
)
.map((button, i) =>
button.children ? (
Expand All @@ -87,12 +86,12 @@ const SideNavBarBody = ({
userInfo?.roles?.includes(
role
)
)
||
(
button.dynamicType?.some(type =>
userInfo?.dynamic_type?.includes(type as ManagementTypes)
)))
) ||
button.dynamicType?.some(type =>
userInfo?.dynamic_type?.includes(
type as ManagementTypes
)
))
)
.map((button, i) =>
button.children ? (
Expand All @@ -110,7 +109,7 @@ const SideNavBarBody = ({
}
display={
level2dropDownDisplay ===
button.title
button.title
? "max-content"
: "0"
}
Expand All @@ -124,12 +123,13 @@ const SideNavBarBody = ({
userInfo?.roles?.includes(
role
)
)
||
(
button.dynamicType?.some(type =>
userInfo?.dynamic_type?.includes(type as ManagementTypes)
)))
) ||
button.dynamicType?.some(
type =>
userInfo?.dynamic_type?.includes(
type as ManagementTypes
)
))
)
.map((button, i) => (
<MuButton
Expand Down Expand Up @@ -191,7 +191,7 @@ const SideNavBarBody = ({
<MuButton
text="Account Setting"
icon={<MuSettings />}
onClick={() => navigate("/dashboard/settings/account")}
onClick={() => navigate("/dashboard/settings")}
style={{
color: "#9297AA",
backgroundColor: "#fff"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@200;300;400;500;600;700;800&display=swap");

.wrapper {
padding: 1rem;
display: flex;
justify-content: center;
align-items: center;
}

.tableWrapper {
background-color: white;
border-radius: 10px;
padding: 2rem;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.wrapper form {
width: 20rem;
}

.inputBox {
width: 100%;
height: 2.5rem;
margin-top: 1.5rem;
}

.inputBox span {
color: red;
font-size: small;
margin-left: 15px;
}

.inputBox input {
width: 100%;
height: 100%;
background: #f3f3f4;
border-radius: 8px;
border: none;
padding: 1rem;
}

.submit {
margin-top: 20px;
display: flex;
justify-content: center;
align-items: center;
}

.submit button {
width: 100%;
color: white;
}

.text {
font-weight: 700;
}

.errorsSpan {
color: red;
font-size: small;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
import { PowerfulButton } from "@/MuLearnComponents/MuButtons/MuButton";
import styles from "./Organization.module.css";
import { Form, Formik } from "formik";
import * as z from "yup";
import { FormikTextInputWithoutLabel as SimpleInput } from "@/MuLearnComponents/FormikComponents/FormikComponents";
import { useEffect, useState } from "react";
import {
getColleges,
getDepartments,
getRoles,
submitUserData
} from "../../../../../Common/Authentication/services/newOnboardingApis";
import ReactSelect, { SingleValue } from "react-select";
import { useLocation, useNavigate } from "react-router-dom";

// Define the Option type for ReactSelect
type Option = {
value: string;
label: string;
};

const inputObject = {
college: "College Name",
department: "Department",
graduationYear: "Graduation Year"
};

const scheme = z.object({
college: z
.string()
.required(`${inputObject.college} is Required`)
.min(3, `${inputObject.college} must be at least 3 characters`)
.max(100, `${inputObject.college} must be at most 100 characters`),
department: z
.string()
.required(`${inputObject.department} is Required`)
.min(2, `${inputObject.department} must be at least 2 characters`)
.max(100, `${inputObject.department} must be at most 100 characters`),
graduationYear: z
.number()
.integer()
.positive()
.when("role", {
is: "student",
then: s =>
s
.required(`${inputObject.graduationYear} is Required`)
.min(2000, `${inputObject.graduationYear} > 2000`)
.max(2030, `${inputObject.graduationYear} < 2030`)
})
});

export default function CollegePage({}: {}) {
const navigate = useNavigate();
const location = useLocation();
let userData: any = location.state as Object;

const [isloading, setIsLoading] = useState(true);
const [colleges, setColleges] = useState([{ id: "", title: "" }]);
const [departments, setDepartments] = useState([{ id: "", title: "" }]);
const [roles, setRoles] = useState([{ id: "", title: "" }]);

const [selectedCollege, setSelectedCollege] = useState<Option | null>(null);
const [selectedDepartment, setSelectedDepartment] = useState<Option | null>(null);

const getRoleTitle = (id: string) => {
const slice = roles.filter(val => val.id === id);
if (slice[0]) return slice[0].title;
};

const CustomFilter = (
{ label, value }: Option,
searchString: string
): boolean => {
if (value === "Others") return true;
if (!searchString) return true;
return label.toLowerCase().includes(searchString.toLowerCase());
};

useEffect(() => {
getColleges({
setIsLoading: setIsLoading,
setColleges: setColleges
});
getDepartments({
setIsLoading: setIsLoading,
setDepartments: setDepartments
});
getRoles().then((res: any) => {
setRoles(res);
setIsLoading(false);
});
}, []);

const onSubmit = async (values: any) => {
const newUserData: any = {
user: {
full_name: userData.user.full_name,
email: userData.user.email,
password: userData.user.password,
district: userData.district
},
organization: {
...(values.department !== "Others" && {
department: values.department
}),
year_of_graduation: values.graduationYear,
organizations: [
...(values.college !== "Others" ? [values.college] : []),
...userData.communities
],
verified: true
}
};

if (userData.referral)
newUserData["referral"] = { muid: userData.referral.muid };

if (userData.role === "Enabler")
delete newUserData.organization.year_of_graduation;

console.log(newUserData);

submitUserData({
setIsLoading: setIsLoading,
userData: newUserData,
navigate: navigate
});
};

return (
<Formik
initialValues={Object.fromEntries(
Object.keys(inputObject).map(key => [key, ""])
)}
validationSchema={scheme}
onSubmit={(value, action) => onSubmit(value)}
>
{formik => (
<div className={`${styles.wrapper} ${styles.tableWrapper}`}>
<Form onSubmit={formik.handleSubmit}>
<h5 className={styles.text}>
Please enter your college details
</h5>
<div className={styles.inputBox}>
<ReactSelect
options={[
{ value: "Others", label: "Others" },
...colleges.map(college => ({
value: String(college.id), // Ensure ID is string
label: college.title
}))
]}
name="college"
placeholder="College"
value={selectedCollege}
filterOption={CustomFilter}
isDisabled={isloading}
onChange={(newValue: SingleValue<Option>) => {
if (newValue) {
setSelectedCollege(newValue);
formik.setFieldValue("college", newValue.value);
} else {
setSelectedCollege(null);
formik.setFieldValue("college", "");
}
}}
/>
</div>
{formik.touched.college && formik.errors.college && (
<span className={styles.errorsSpan}>
{formik.errors.college}
</span>
)}
<div className={styles.inputBox}>
<ReactSelect
options={[
{ value: "Others", label: "Others" },
...departments.map(department => ({
value: String(department.id), // Ensure ID is string
label: department.title
}))
]}
name="department"
placeholder="Department"
value={selectedDepartment}
isDisabled={isloading}
filterOption={CustomFilter}
onChange={(newValue: SingleValue<Option>) => {
if (newValue) {
setSelectedDepartment(newValue);
formik.setFieldValue("department", newValue.value);
} else {
setSelectedDepartment(null);
formik.setFieldValue("department", "");
}
}}
/>
</div>
{formik.touched.department &&
formik.errors.department && (
<span className={styles.errorsSpan}>
{formik.errors.department}
</span>
)}
<div className={styles.inputBox}>
<SimpleInput
value={formik.values.graduationYear}
name="graduationYear"
type="number"
placeholder="Graduation Year"
disabled={isloading}
/>
{formik.touched.graduationYear &&
formik.errors.graduationYear && (
<span className={styles.errorsSpan}>
{formik.errors.graduationYear}
</span>
)}
</div>

<div className={styles.submit}>
<PowerfulButton type="submit" isLoading={isloading}>
{isloading ? "Please wait..." : "Submit"}
</PowerfulButton>
</div>
</Form>
</div>
)}
</Formik>
);
}
Loading

0 comments on commit 3e228d7

Please sign in to comment.