github.com/quickfeed/quickfeed@v0.0.0-20240507093252-ed8ca812a09c/public/src/components/teacher/RoleSwitch.tsx (about)

     1  import React from "react"
     2  import { Enrollment } from "../../../proto/qf/types_pb"
     3  import { hasTeacher, isTeacher } from "../../Helpers"
     4  import { useActions, useAppState } from "../../overmind"
     5  
     6  
     7  // RoleSwitch is a component that displays a button to switch between teacher and student roles.
     8  const RoleSwitch = ({ enrollment }: { enrollment: Enrollment }) => {
     9      const state = useAppState()
    10      const actions = useActions()
    11  
    12      if (hasTeacher(state.status[enrollment.courseID.toString()])) {
    13          return (
    14              <span className="clickable" onClick={() => actions.changeView(enrollment.courseID)}>
    15                  {isTeacher(enrollment) ? "Switch to Student View" : "Switch to Teacher View"}
    16              </span>
    17          )
    18      }
    19      return null
    20  }
    21  
    22  export default RoleSwitch