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
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ const CompetitionButton = ({ buttons }: CompetitionButtonProps) => {
};

const handleClick = (to: string) => {
persistence.save(KEY.AFTER_AUTH_PATH, location.pathname);
if (to.startsWith("#")) {
document.getElementById(to.slice(1))?.scrollIntoView({ behavior: "smooth" });
return;
}

if (isExternalLink(to)) {
// For external links, open in the new tab
window.open(to, "_blank", "noopener, noreferrer");
} else {
// For internal links, use React Router
history.push(to);
return;
}

persistence.save(KEY.AFTER_AUTH_PATH, location.pathname);
history.push(to);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const CompetitionEntryForm = ({ handleTermsClick }: CompetitionEntryFormP
selectedGroup && selectedGroup.members !== undefined && !isLoadingMembers && selectedGroup.members.length === 0;

return (
<div className="pt-5">
<div className="pt-5" id="competition-entry-form">
<div className="entry-form-background-img entry-form-section">
<Container className="pb-2">
<Form onSubmit={handleSubmit}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import React from "react";
import { Container, Col } from "reactstrap";
import CompetitionEntryForm from "./CompetitionEntryForm";
import CompetitionButton from "../Buttons/CompetitionButton";
import { selectors, useAppSelector } from "../../../../state";
import { isStudent, isAdmin, isTeacher } from "../../../../services";
import { isStudent, isAdmin, isTeacher, isLoggedIn } from "../../../../services";
import CompetitionWrapper from "../CompetitionWrapper";
import { CLOSED_MESSAGE, STUDENT_MESSAGE, TEACHER_MESSAGE } from "../constants";
import { CLOSED_MESSAGE, STUDENT_MESSAGE } from "../constants";
import { isBeforeCompetitionOpenDate } from "../dateUtils";
import { PotentialUser } from "../../../../../IsaacAppTypes";
import { Immutable } from "immer";

// EOI button configuration - same as HomepageHighlight
export const eoiButton = {
to: "https://forms.cloud.microsoft/e/K4GmaA3QEF",
label: isBeforeCompetitionOpenDate(new Date()) ? "Express your interest" : "Submit your project",
const EOI_FORM_URL = "https://forms.cloud.microsoft/e/K4GmaA3QEF";
const ENTRY_FORM_ANCHOR = "#competition-entry-form";

export const getHeadlineCtaButton = (user?: Immutable<PotentialUser> | null) => {
const beforeOpen = isBeforeCompetitionOpenDate(new Date());
if (beforeOpen) {
return { to: EOI_FORM_URL, label: "Express your interest" };
}

if (isLoggedIn(user) && (isTeacher(user) || isAdmin(user))) {
return { to: ENTRY_FORM_ANCHOR, label: "Submit your project" };
}

return { to: "/login", label: "Submit your project" };
};

const StudentMessage = () => (
Expand All @@ -22,25 +33,11 @@ const StudentMessage = () => (
</Container>
);

interface DefaultMessageProps {
buttons: { to: string; label: string }[];
}

const DefaultMessage: React.FC<DefaultMessageProps> = ({ buttons }) => (
<Container>
<Col className="d-flex flex-column align-items-start pb-4 pl-0" xs="auto">
<p className="pb-3 body-text">{TEACHER_MESSAGE}</p>
<CompetitionButton buttons={buttons} />
</Col>
</Container>
);

interface EntryFormHandlerProps {
buttons: { to: string; label: string }[];
handleTermsClick: (event: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => void;
}

const EntryFormHandler = ({ buttons, handleTermsClick }: EntryFormHandlerProps) => {
const EntryFormHandler = ({ handleTermsClick }: EntryFormHandlerProps) => {
const user = useAppSelector(selectors.user.orNull);

const renderEntryForm = () => {
Expand All @@ -53,9 +50,10 @@ const EntryFormHandler = ({ buttons, handleTermsClick }: EntryFormHandlerProps)
);
} else if (isStudent(user)) {
return <StudentMessage />;
} else {
return <DefaultMessage buttons={buttons} />;
}

// Logged-out CTA lives in the headline (teacher copy + Submit your project)
return null;
};

return (
Expand Down
19 changes: 9 additions & 10 deletions src/app/components/pages/IsaacCompetition/IsaacCompetition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import "../../../../scss/cs/competition.scss";
import Accordion from "./Accordion/Accordion";
import InformationCard from "./CompetitionInformation/InformationCard";
import CompetitionTimeline from "./CompetitionInformation/CompetitionTimeline";
import EntryFormHandler, { eoiButton } from "./EntryForm/EntryFormHandler";
import EntryFormHandler, { getHeadlineCtaButton } from "./EntryForm/EntryFormHandler";
import CompetitionButton from "./Buttons/CompetitionButton";
import CompetitionWrapper from "./CompetitionWrapper";
import { isBeforeCompetitionOpenDate, liveQandASessionDate } from "./dateUtils";
import { selectors, useAppSelector } from "../../../state";

const { section1, section3, accordion } = content;

Expand All @@ -19,12 +20,8 @@ export const IsaacCompetition = () => {
document.title = "Isaac " + SITE_SUBJECT_TITLE;
}, []);

const buttons = [
{
to: "/login",
label: "Submit a project",
},
];
const user = useAppSelector(selectors.user.orNull);
const headlineCtaButton = getHeadlineCtaButton(user);

const [open, setOpen] = useState<string | null>(null);

Expand Down Expand Up @@ -103,8 +100,10 @@ export const IsaacCompetition = () => {
</p>
<Row className="justify-content-left mt-5">
<Col xs="auto">
<CompetitionWrapper>
<CompetitionButton buttons={[eoiButton]} />
<CompetitionWrapper
beforeCompetitionOpenContent={<CompetitionButton buttons={[headlineCtaButton]} />}
>
<CompetitionButton buttons={[headlineCtaButton]} />
</CompetitionWrapper>
</Col>
</Row>
Expand All @@ -121,7 +120,7 @@ export const IsaacCompetition = () => {
</Col>
</Row>
</Container>
<EntryFormHandler buttons={buttons} handleTermsClick={handleTermsClick} />
<EntryFormHandler handleTermsClick={handleTermsClick} />
</section>
<section id="internetOfEverything" className="event-section">
<div className="event-section-background-img"></div>
Expand Down
Loading