Skip to content

Commit

Permalink
feat: pupil expiring banners
Browse files Browse the repository at this point in the history
  • Loading branch information
kimon-satan committed Dec 2, 2024
1 parent 33feeb6 commit 5c51362
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
OakPupilJourneyListCounter,
OakBox,
OakInlineBanner,
OakSecondaryLink,
isValidIconName,
OakSecondaryButton,
} from "@oaknational/oak-components";
import { useState } from "react";

Expand All @@ -33,6 +33,7 @@ export const PupilViewsLessonListing = (props: PupilLessonListingViewProps) => {
const { unitData, programmeFields, orderedCurriculumData, backLink } = props;
const {
yearDescription,
yearSlug,
subject,
subjectSlug,
tierDescription,
Expand All @@ -47,6 +48,9 @@ export const PupilViewsLessonListing = (props: PupilLessonListingViewProps) => {
orderedCurriculumData.some((c) => c.actions?.displayExpiringBanner),
);

const baseSlug = `${subjectSlug}-${phaseSlug}-${yearSlug}`;
const unitListingHref = `/pupils/programmes/${baseSlug}/options`; // NB. options will forward to units if no options available

const noneExpiredLessons = orderedCurriculumData.filter(
(lesson) => !lesson.lessonData?.deprecatedFields?.expired,
);
Expand Down Expand Up @@ -107,16 +111,17 @@ export const PupilViewsLessonListing = (props: PupilLessonListingViewProps) => {
<OakInlineBanner
canDismiss
cta={
<OakSecondaryLink
href="https://support.thenational.academy/lesson-unavailable"
iconName="chevron-right"
<OakSecondaryButton
element="a"
iconName="arrow-right"
isTrailingIcon
href={unitListingHref}
>
Read the help article
</OakSecondaryLink>
View new lessons
</OakSecondaryButton>
}
isOpen={showExpiredLessonsBanner}
message="We've made brand new and improved lessons for you."
message="We've made brand-new and improved lessons for you."
onDismiss={() => {
setShowExpiredLessonsBanner(false);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
OakP,
OakPrimaryButton,
OakPupilContentGuidance,
OakSecondaryLink,
OakSecondaryButton,
OakSpan,
OakSubjectIcon,
isValidIconName,
Expand Down Expand Up @@ -84,6 +84,9 @@ export const PupilViewsLessonOverview = ({
browseData.actions?.displayExpiringBanner === true,
);

const baseSlug = `${browseData.programmeFields.subjectSlug}-${browseData.programmeFields.phaseSlug}-${browseData.programmeFields.yearSlug}`;
const unitListingHref = `/pupils/programmes/${baseSlug}/options`; // NB. options will forward to units if no options available

function pickProgressForSection(section: LessonReviewSection) {
if (sectionResults[section]?.isComplete) {
return "complete";
Expand Down Expand Up @@ -158,20 +161,21 @@ export const PupilViewsLessonOverview = ({
<OakInlineBanner
canDismiss
cta={
<OakSecondaryLink
href="https://support.thenational.academy/lesson-unavailable"
iconName="chevron-right"
<OakSecondaryButton
element="a"
iconName="arrow-right"
isTrailingIcon
href={unitListingHref}
>
Read the help article
</OakSecondaryLink>
View new lessons
</OakSecondaryButton>
}
isOpen={showExpiredLessonsBanner}
message="We've made brand new and improved lessons for you."
message="We've made brand-new and improved lessons for you."
onDismiss={() => {
setShowExpiredLessonsBanner(false);
}}
title="This lesson will soon be taken down."
title="These lessons will be removed by Spring 2025."
type="alert"
$mt={"space-between-m"}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
pupilProgrammeListingSchema,
} from "./pupilProgrammeListing.schema";

import OakError from "@/errors/OakError";
import { Sdk } from "@/node-lib/curriculum-api-2023/sdk";
import { applyGenericOverridesAndExceptions } from "@/node-lib/curriculum-api-2023/helpers/overridesAndExceptions";
import { PupilProgrammeListingQuery } from "@/node-lib/curriculum-api-2023/generated/sdk";
Expand Down Expand Up @@ -35,8 +34,9 @@ export const pupilProgrammeListingQuery =
browseData: res.data,
});

// perhaps we redirect to unitListing page ?
if (modified.length === 0) {
throw new OakError({ code: "curriculum-api/not-found" });
return [];
}

pupilProgrammeListingSchema.array().parse(modified);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("pupilUnitListing()", () => {
expect(res[0]?.programmeFields?.phase).toEqual("primary");
});

it("throws if data is not returned", async () => {
it("returns empty array if data is not returned", async () => {
await expect(
pupilProgrammeListingQuery({
...sdk,
Expand All @@ -42,7 +42,7 @@ describe("pupilUnitListing()", () => {
})({
baseSlug: "unknown-slug",
}),
).rejects.toThrow("Resource not found");
).resolves.toEqual([]);
});

it("defaults to legacy programmes", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { PupilProgrammeListingData } from "@/node-lib/curriculum-api-2023/querie
import OakError from "@/errors/OakError";
import { subjectBrowseDataFixture } from "@/node-lib/curriculum-api-2023/fixtures/subjectBrowseData.fixture";
import { PupilViewsProgrammeListingProps } from "@/components/PupilViews/PupilProgrammeListing/PupilProgrammeListing.view";
import keysToCamelCase from "@/utils/snakeCaseConverter";

describe("options-pages-helpers", () => {
describe("getYearSlug", () => {
Expand Down Expand Up @@ -85,7 +86,9 @@ describe("options-pages-helpers", () => {
it("should return redirect if only one programme exists", async () => {
(
curriculumApi2023.default.pupilProgrammeListingQuery as jest.Mock
).mockResolvedValueOnce([syntheticProgrammesByYearFixture()]);
).mockResolvedValueOnce([
keysToCamelCase(syntheticProgrammesByYearFixture()),
]);

const result = await getPupilOptionData({
params: { programmeSlug: "maths-primary-year-1" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export const getPupilOptionData = async (
};
}

if (programmes.length === 1) {
if (
programmes.filter((p) => p?.programmeFields.legacy !== "true").length === 1
) {
return {
redirect: {
destination: resolveOakHref({
Expand Down

0 comments on commit 5c51362

Please sign in to comment.