index.tsx 1.39 KB
Newer Older
zhanghaozhe committed
1 2 3 4
import React, { ReactNode, ReactElement } from "react"
import { handleNavigation, Navigation } from "../index"
import { RequireAtLeastOne } from "src/utils/types"
import { History } from "history"
zhanghaozhe committed
5

zhanghaozhe committed
6
import "./index.scss"
zhanghaozhe committed
7 8

export interface CoursePropsBasic {
zhanghaozhe committed
9 10 11 12 13 14 15 16 17
  image: string
  title: string
  courseId: number
  status: ReactNode
  navigate?: (courseId: number) => void
  history?: History
  subtitle?: string
  tag?: ReactElement
  marketing?: string
zhanghaozhe committed
18 19
}

zhanghaozhe committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
export type CourseProps = RequireAtLeastOne<
  CoursePropsBasic,
  "history" | "navigate"
>

const CourseCardH: React.FC<CourseProps> = ({
  image,
  title,
  subtitle,
  status,
  navigate,
  courseId,
  tag,
  history,
  marketing,
}) => {
  return (
    <div
      className={"course-card course-card-h"}
      onClick={(e) => {
        if (navigate) {
          handleNavigation({ e, courseId, navigate })
        } else {
          handleNavigation({ e, courseId, history } as Navigation)
        }
      }}
    >
      <div className="show">
        <img src={image} alt={title} />
        {marketing && <div className="marketing">{marketing}</div>}
        {tag}
      </div>
      <div className="info">
        <div className="title">{title}</div>
        {subtitle && <div className="subtitle">{subtitle}</div>}
        <div className="status">{status}</div>
      </div>
    </div>
  )
zhanghaozhe committed
59 60
}

zhanghaozhe committed
61
CourseCardH.displayName = "CourseCardH"
zhanghaozhe committed
62

zhanghaozhe committed
63
export default CourseCardH