Skip to content

Commit fab0c32

Browse files
UAI Dashboard (#2189)
* better types on expectProps * remove old mockAxios * add org tabs * mock apis * add cards for organizations programs * tmp * add org header * tmp * add more data factories * update mitxonline enrollment factories * add offerUpgrade and courseNoun props to dashboard cards * add tests and enrolled indicator * fix a few ts errors * update spec * tmp * fix tests * fix a mobile title issue * fix two typos
1 parent 9b6a0c8 commit fab0c32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2123
-402
lines changed
+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { EnrollmentsApi } from "./generated/v0/api"
1+
import { EnrollmentsApi, ProgramsApi, CoursesApi } from "./generated/v0/api"
22
import axios from "axios"
33

4-
const instance = axios.create({})
4+
const axiosInstance = axios.create({})
55

66
const BASE_PATH =
77
process.env.NEXT_PUBLIC_MITXONLINE_API_BASE_URL?.replace(/\/+$/, "") ?? ""
88

9-
const enrollmentsApi = new EnrollmentsApi(undefined, BASE_PATH, instance)
9+
const enrollmentsApi = new EnrollmentsApi(undefined, BASE_PATH, axiosInstance)
10+
const programsApi = new ProgramsApi(undefined, BASE_PATH, axiosInstance)
11+
const coursesApi = new CoursesApi(undefined, BASE_PATH, axiosInstance)
1012

11-
export { enrollmentsApi }
13+
export { enrollmentsApi, programsApi, coursesApi, axiosInstance }

frontends/api/src/mitxonline/generated/v0/api.ts

+75-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// FAKE DATA while API / auth work is in development
2+
import { CourseWithCourseRuns } from "../../generated/v0"
3+
import { mockProgramCourseData } from "../programs/data"
4+
5+
const fakeCourse = ({
6+
id,
7+
title,
8+
}: {
9+
id: number
10+
title: string
11+
}): CourseWithCourseRuns => {
12+
const runId = id * 10
13+
return {
14+
id,
15+
title,
16+
readable_id: "course-v1:MITxT+18.03.2x",
17+
next_run_id: runId,
18+
departments: [{ name: "Mathematics" }],
19+
page: {
20+
feature_image_src:
21+
"/media/original_images/18.032x_courseimage_MITxO.png?v=bb0e1eaeb2bc4ff5f079d479ece6954bd8f22ca6",
22+
page_url: "/courses/course-v1:MITxT+18.03.2x/",
23+
description:
24+
"In order to understand most phenomena in the world, we need to understand not just single equations, but systems of differential equations. In this course, we start with 2x2 systems.",
25+
live: true,
26+
length: "9 weeks",
27+
effort: "5-8 hrs/wk",
28+
financial_assistance_form_url: "",
29+
current_price: 75.0,
30+
instructors: [{ name: "Jennifer French", description: "" }],
31+
},
32+
programs: null,
33+
topics: [{ name: "Mathematics" }, { name: "Science & Math" }],
34+
certificate_type: "Certificate of Completion",
35+
required_prerequisites: true,
36+
duration: "9 weeks",
37+
min_weeks: 9,
38+
max_weeks: 9,
39+
time_commitment: "5-8 hrs/wk",
40+
availability: "anytime",
41+
min_weekly_hours: "5",
42+
max_weekly_hours: "8",
43+
courseruns: [
44+
{
45+
title: "Differential Equations: 2x2 Systems",
46+
start_date: "2025-01-08T16:00:00Z",
47+
end_date: "2025-03-19T16:00:00Z",
48+
enrollment_start: "2024-12-13T16:00:00Z",
49+
enrollment_end: null,
50+
expiration_date: null,
51+
courseware_url:
52+
"https://courses.mitxonline.mit.edu/courses/course-v1:MITxT+18.03.2x+1T2025/course",
53+
courseware_id: "course-v1:MITxT+18.03.2x+1T2025",
54+
certificate_available_date: "2025-03-19T16:00:00Z",
55+
upgrade_deadline: "2025-03-09T16:00:00Z",
56+
is_upgradable: false,
57+
is_enrollable: true,
58+
is_archived: false,
59+
is_self_paced: false,
60+
run_tag: "1T2025",
61+
id: runId,
62+
live: true,
63+
course_number: "18.03.2x",
64+
products: [],
65+
approved_flexible_price_exists: false,
66+
},
67+
],
68+
}
69+
}
70+
71+
const universalAiCourses: CourseWithCourseRuns[] = [
72+
fakeCourse(mockProgramCourseData.foundational.one),
73+
fakeCourse(mockProgramCourseData.foundational.two),
74+
fakeCourse(mockProgramCourseData.foundational.three),
75+
fakeCourse(mockProgramCourseData.foundational.four),
76+
fakeCourse(mockProgramCourseData.foundational.five),
77+
fakeCourse(mockProgramCourseData.foundational.six),
78+
fakeCourse(mockProgramCourseData.foundational.seven),
79+
fakeCourse(mockProgramCourseData.foundational.eight),
80+
fakeCourse(mockProgramCourseData.foundational.nine),
81+
fakeCourse(mockProgramCourseData.industry.one),
82+
fakeCourse(mockProgramCourseData.industry.two),
83+
fakeCourse(mockProgramCourseData.industry.three),
84+
fakeCourse(mockProgramCourseData.industry.four),
85+
]
86+
87+
export { universalAiCourses }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { coursesQueries } from "./queries"
2+
3+
export { coursesQueries }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { queryOptions } from "@tanstack/react-query"
2+
import type {
3+
CoursesApiApiV2CoursesListRequest,
4+
PaginatedCourseWithCourseRunsList,
5+
} from "../../generated/v0"
6+
7+
import * as data from "./data"
8+
import { coursesApi } from "../../clients"
9+
10+
const coursesKeys = {
11+
root: ["mitxonline", "courses"],
12+
coursesList: (opts?: CoursesApiApiV2CoursesListRequest) => [
13+
...coursesKeys.root,
14+
"list",
15+
opts,
16+
],
17+
}
18+
19+
const coursesQueries = {
20+
coursesList: (opts?: CoursesApiApiV2CoursesListRequest) =>
21+
queryOptions({
22+
queryKey: coursesKeys.coursesList(opts),
23+
queryFn: async (): Promise<PaginatedCourseWithCourseRunsList> => {
24+
if (process.env.NODE_ENV === "test") {
25+
/**
26+
* For now, only use the API client during tests so we
27+
* can mock it the way we normally do.
28+
*/
29+
return coursesApi.apiV2CoursesList(opts).then((res) => res.data)
30+
}
31+
const ids = opts?.id ?? []
32+
const courses =
33+
ids.length === 0
34+
? data.universalAiCourses
35+
: data.universalAiCourses.filter((c) => ids.includes(c.id))
36+
if (courses.length === 0) {
37+
console.error("No mock courses matching the given ids found.", {
38+
ids,
39+
})
40+
}
41+
return {
42+
count: courses.length,
43+
next: null,
44+
previous: null,
45+
results: courses,
46+
}
47+
},
48+
}),
49+
}
50+
51+
export { coursesQueries, coursesKeys }

frontends/api/src/mitxonline/hooks/enrollment/data.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FAKE DATA while API / auth work is in development
12
import { CourseRunEnrollment } from "../../generated/v0"
23

34
const soon = (days: number) => {

0 commit comments

Comments
 (0)