Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/pages/api/mentors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,24 @@ export default async function handler(
return res.status(405).json({ error: `Method ${req.method} Not Allowed` });
}
try {
const { keyword, yearsExperience, areas, language, focus } = req.query;
const {
keyword,
mentorshipTypes,
yearsExperience,
areas,
language,
focus,
} = req.query;

const params = new URLSearchParams();
if (keyword)
params.append('keyword', Array.isArray(keyword) ? keyword[0] : keyword);
if (mentorshipTypes) {
params.append(
'mentorshipTypes',
Array.isArray(mentorshipTypes) ? mentorshipTypes[0] : mentorshipTypes,
);
}
if (yearsExperience)
params.append(
'yearsExperience',
Expand Down
49 changes: 48 additions & 1 deletion src/pages/mentorship/mentors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import { useRouter } from 'next/router';
import { useEffect, useState } from 'react';

import { BreadCrumbsDynamic, MentorProfileCard, Title } from '@components';
import { FILTER_EXPERIENCE_OPTIONS } from '@utils/mentorshipConstants';
import {
ALL_MENTORSHIP_TYPES,
FILTER_EXPERIENCE_OPTIONS,
FILTER_MENTORSHIP_TYPES_OPTIONS,
} from '@utils/mentorshipConstants';
import { useIsMobile } from '@utils/theme-utils';
// eslint-disable-next-line import/order
import { Mentor } from '@utils/types';
Expand All @@ -28,6 +32,7 @@ type FilterSection = {
types: string[];
skills: {
yearsExperience?: number;
mentorshipTypes: string[];
areas: string[];
languages: string[];
mentorshipFocus: string[];
Expand All @@ -37,6 +42,8 @@ type FilterSection = {
import theme from 'theme';

const filterYearExperienceOptions = FILTER_EXPERIENCE_OPTIONS;
const filterMentorshipTypeOptions = FILTER_MENTORSHIP_TYPES_OPTIONS;

const MentorsPage = () => {
const router = useRouter();
const isMobile = useIsMobile();
Expand All @@ -46,6 +53,8 @@ const MentorsPage = () => {
const [loading, setLoading] = useState(false);
const [filtersOpen, setFiltersOpen] = useState(false);
const [keyword, setKeyword] = useState<string>('');
const [selectedMentorshipType, setSelectedMentorshipType] =
useState<string>('');
const [selectedYearsExperience, setSelectedYearsExperience] =
useState<string>('');
const [selectedAreas, setSelectedAreas] = useState<string>('');
Expand All @@ -59,6 +68,9 @@ const MentorsPage = () => {
useEffect(() => {
if (!query) return;
if (typeof query.keyword === 'string') setKeyword(query.keyword);
if (typeof query.mentorshipTypes === 'string') {
setSelectedMentorshipType(query.mentorshipTypes);
}
if (typeof query.yearsExperience === 'string') {
setSelectedYearsExperience(query.yearsExperience);
} else {
Expand All @@ -80,6 +92,7 @@ const MentorsPage = () => {
const params = new URLSearchParams();
const filterKeys = [
'keyword',
'mentorshipTypes',
'yearsExperience',
'areas',
'language',
Expand Down Expand Up @@ -127,6 +140,7 @@ const MentorsPage = () => {

const applyFilters = (opts?: {
keyword?: string;
mentorshipTypes?: string;
yearsExperience?: string;
areas?: string;
language?: string;
Expand All @@ -151,6 +165,7 @@ const MentorsPage = () => {

const handleClearFilters = () => {
setKeyword('');
setSelectedMentorshipType('');
setSelectedYearsExperience('');
setSelectedAreas('');
setSelectedLanguage('');
Expand Down Expand Up @@ -260,6 +275,38 @@ const MentorsPage = () => {
{/* First row: filter dropdowns */}
<Grid item xs={12}>
<Box display="flex" flexWrap="wrap" gap={2}>
<FormControl sx={{ minWidth: 120, flex: 1 }}>
<InputLabel id="filter-mentorship-type-label">
Mentorship type
</InputLabel>
<Select
labelId="filter-mentorship-type-label"
value={selectedMentorshipType}
label="Mentorship type"
onChange={(e) => {
const mentorshipType = e.target.value as string;
setSelectedMentorshipType(mentorshipType);
if (
mentorshipType === ALL_MENTORSHIP_TYPES &&
!selectedMentorshipType
) {
return;
}
applyFilters({
mentorshipTypes:
mentorshipType === ALL_MENTORSHIP_TYPES
? ''
: mentorshipType,
});
}}
>
{filterMentorshipTypeOptions.map((option) => (
<MenuItem key={option.label} value={option.value}>
{option.label}
</MenuItem>
))}
</Select>
</FormControl>
<FormControl sx={{ minWidth: 120, flex: 1 }}>
<InputLabel id="filter-experience-label">
Experience
Expand Down
8 changes: 8 additions & 0 deletions src/utils/mentorshipConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ export const MENTORSHIP_TYPES: LabelValue[] = [
{ label: 'Ad-Hoc', value: 'AD_HOC' },
];

export const ALL_MENTORSHIP_TYPES = 'All';

export const FILTER_MENTORSHIP_TYPES_OPTIONS = [
{ label: 'All', value: ALL_MENTORSHIP_TYPES },
{ label: 'Long-term', value: 'Long-Term' },
{ label: 'Ad-hoc', value: 'Ad-Hoc' },
] as const;

export const MENTORSHIP_FOCUS_AREAS: LabelValue[] = [
{ label: 'Switch career to IT', value: 'SWITCH_CAREER_TO_IT' },
{ label: 'Grow from beginner to mid-level', value: 'GROW_BEGINNER_TO_MID' },
Expand Down
Loading