-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨(frontend) build page TeacherCourse
- Loading branch information
1 parent
6ab4b4a
commit 4a56a6d
Showing
43 changed files
with
1,157 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { rest } from 'msw'; | ||
import type { CourseRun } from 'types/Joanie'; | ||
import { getAPIEndpoint } from 'api/joanie'; | ||
import { CourseFactory } from 'utils/test/factories/joanie'; | ||
import { Nullable } from 'types/utils'; | ||
import { CourseState } from 'types'; | ||
import { Resource } from 'types/Resource'; | ||
import { OrganizationMock } from './organizations'; | ||
|
||
export interface CourseListItemMock extends Resource { | ||
id: string; | ||
title: string; | ||
code: string; | ||
organization: OrganizationMock; | ||
course_runs: CourseRun['id'][]; | ||
cover_image: Nullable<{ | ||
filename: string; | ||
url: string; | ||
height: number; | ||
width: number; | ||
}>; | ||
state: CourseState; | ||
} | ||
|
||
export const listCourses = rest.get<CourseListItemMock[]>( | ||
`${getAPIEndpoint()}/courses/`, | ||
(req, res, ctx) => { | ||
const queryPerPage = req.url.searchParams.get('per_page'); | ||
const perPage = queryPerPage === null ? 6 : parseInt(queryPerPage, 10); | ||
|
||
const organizationCover001 = require('./assets/organization_cover_001.jpg'); | ||
const courseCover001 = require('./assets/course_cover_001.jpg'); | ||
const courses: CourseListItemMock[] = CourseFactory.generate(perPage).map( | ||
(course: CourseListItemMock) => ({ | ||
...course, | ||
organization: { | ||
title: 'Awesome university', | ||
logo: { | ||
url: organizationCover001.default, | ||
}, | ||
}, | ||
cover_image: { url: courseCover001.default }, | ||
}), | ||
); | ||
|
||
return res(ctx.status(200), ctx.json(courses)); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Course as RichieCourse, isRichieCourse } from 'types/Course'; | ||
import { CourseListItemMock as JoanieCourse } from 'api/mocks/joanie/courses'; | ||
import { CourseGlimpseCourse } from '.'; | ||
|
||
const getCourseGlimpsePropsFromRichieCourse = (course: RichieCourse): CourseGlimpseCourse => ({ | ||
id: course.id, | ||
code: course.code, | ||
course_url: course.absolute_url, | ||
cover_image: course.cover_image, | ||
title: course.title, | ||
organization: { | ||
title: course.organization_highlighted, | ||
image: course.organization_highlighted_cover_image, | ||
}, | ||
icon: course.icon, | ||
state: course.state, | ||
}); | ||
|
||
const getCourseGlimpsePropsFromJoanieCourse = (course: JoanieCourse): CourseGlimpseCourse => ({ | ||
id: course.id, | ||
code: course.code, | ||
cover_image: course.cover_image | ||
? { | ||
src: course.cover_image.url, | ||
} | ||
: null, | ||
title: course.title, | ||
organization: { | ||
title: course.organization.title, | ||
image: course.organization.logo | ||
? { | ||
src: course.organization.logo.url, | ||
} | ||
: null, | ||
}, | ||
state: course.state, | ||
}); | ||
|
||
export const getCourseGlimpsProps = (course: JoanieCourse | RichieCourse): CourseGlimpseCourse => { | ||
return isRichieCourse(course) | ||
? getCourseGlimpsePropsFromRichieCourse(course) | ||
: getCourseGlimpsePropsFromJoanieCourse(course); | ||
}; |
Oops, something went wrong.