diff --git a/src/__tests__/pages/MenteeRegistrationPage.test.tsx b/src/__tests__/pages/MenteeRegistrationPage.test.tsx index 77f2a03..c46e2af 100644 --- a/src/__tests__/pages/MenteeRegistrationPage.test.tsx +++ b/src/__tests__/pages/MenteeRegistrationPage.test.tsx @@ -22,6 +22,17 @@ jest.mock('next/router', () => ({ useRouter: () => ({ push: jest.fn(), pathname: '/' }), })); +// Mutable flag so individual tests can override the registration state +let mockIsRegistrationOpen = true; + +// Mock the registration toggle +jest.mock('../../utils/mentorshipConstants', () => ({ + ...jest.requireActual('../../utils/mentorshipConstants'), + get IS_REGISTRATION_OPEN() { + return mockIsRegistrationOpen; + }, +})); + const renderPage = () => render( @@ -150,3 +161,27 @@ describe('MenteeRegistrationPage', () => { }); }); }); + +describe('MenteeRegistrationPage - registration closed', () => { + beforeEach(() => { + mockIsRegistrationOpen = false; + }); + + afterEach(() => { + mockIsRegistrationOpen = true; + jest.resetAllMocks(); + }); + + it('shows closed message when registration is not open', () => { + render( + + + , + ); + expect(screen.getByText('Application is now closed')).toBeInTheDocument(); + expect( + screen.getByText(/Long-Term Mentorship programme/i), + ).toBeInTheDocument(); + expect(screen.queryByText('Step 1 of 3')).not.toBeInTheDocument(); + }); +}); diff --git a/src/components/mentorship/RegistrationClosed.tsx b/src/components/mentorship/RegistrationClosed.tsx new file mode 100644 index 0000000..f957b24 --- /dev/null +++ b/src/components/mentorship/RegistrationClosed.tsx @@ -0,0 +1,22 @@ +import { Box, Button, Typography } from '@mui/material'; +import NextLink from 'next/link'; +import React from 'react'; + +/** + * Displayed when the mentee registration window is closed. + */ +const RegistrationClosed = () => ( + + + Application is now closed + + + Applications for the Long-Term Mentorship programme are currently closed. + + + +); + +export default RegistrationClosed; diff --git a/src/pages/mentorship/mentee-registration.tsx b/src/pages/mentorship/mentee-registration.tsx index 856b19d..ac85c4b 100644 --- a/src/pages/mentorship/mentee-registration.tsx +++ b/src/pages/mentorship/mentee-registration.tsx @@ -25,6 +25,8 @@ import MenteeStep1BasicInfo from 'components/mentorship/MenteeStep1BasicInfo'; import MenteeStep2Skills from 'components/mentorship/MenteeStep2Skills'; import MenteeStep3Applications from 'components/mentorship/MenteeStep3Applications'; import { MentorOption } from 'components/mentorship/MentorApplicationCard'; +import RegistrationClosed from 'components/mentorship/RegistrationClosed'; +import { IS_REGISTRATION_OPEN } from 'utils/mentorshipConstants'; const TOTAL_STEPS = 3; @@ -55,6 +57,7 @@ const validateStep2 = async (formMethods: UseFormReturn) => const MenteeRegistrationPage = () => { const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down('md')); + const registrationOpen = IS_REGISTRATION_OPEN; const formMethods = useForm({ resolver: zodResolver(menteeFormSchema), @@ -68,6 +71,7 @@ const MenteeRegistrationPage = () => { const [submitted, setSubmitted] = useState(false); useEffect(() => { + if (!registrationOpen) return; fetch('/api/mentors') .then((res) => res.json()) .then((data) => { @@ -83,7 +87,7 @@ const MenteeRegistrationPage = () => { .catch(() => { // silently fall back to empty list — user can still submit if API is down }); - }, []); + }, [registrationOpen]); const handleNext = async () => { let isValid; @@ -204,10 +208,16 @@ const MenteeRegistrationPage = () => { sx={{ position: 'relative', zIndex: 1, - pt: { xs: 4, sm: 6, md: 8 }, + pt: registrationOpen ? { xs: 4, sm: 6, md: 8 } : 0, px: { xs: 2, sm: 3 }, maxWidth: isMobile ? '100%' : theme.custom?.innerBox?.maxWidth, margin: '0 auto', + ...(!registrationOpen && { + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + minHeight: '70vh', + }), }} > { bgcolor: 'white', }} > - {submitted ? ( + {!registrationOpen ? ( + + ) : submitted ? ( Application submitted! diff --git a/src/utils/mentorshipConstants.ts b/src/utils/mentorshipConstants.ts index 9dd7546..d4db893 100644 --- a/src/utils/mentorshipConstants.ts +++ b/src/utils/mentorshipConstants.ts @@ -195,3 +195,9 @@ export const SKILL_LEVELS = [ 'Not Applicable', ]; export const PREFERENCE_LEVELS = ['Low', 'Medium', 'High', 'Not Applicable']; + +/** + * Mentee registration toggle. + * Set to `true` to open the registration form, `false` to show the closed page. + */ +export const IS_REGISTRATION_OPEN = false;