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

     1  import React, { useEffect } from "react"
     2  import { useActions, useAppState } from "../overmind"
     3  import FormInput from "./forms/FormInput"
     4  import DynamicButton from "./DynamicButton"
     5  import { Color } from "../Helpers"
     6  import { ButtonType } from "./admin/Button"
     7  
     8  const Release = (): JSX.Element | null => {
     9      const state = useAppState()
    10      const actions = useActions()
    11      const canRelease = state.review.assignmentID > -1
    12  
    13      useEffect(() => {
    14          return () => actions.review.setMinimumScore(0)
    15      }, [state.review.assignmentID])
    16  
    17      const handleMinimumScore = (event: React.FormEvent<HTMLInputElement>) => {
    18          event.preventDefault()
    19          actions.review.setMinimumScore(parseInt(event.currentTarget.value))
    20      }
    21  
    22      if (!canRelease) {
    23          return null
    24      }
    25  
    26      return (
    27          <div className="input-group">
    28              <FormInput type="number" prepend="Set minimum score" name="score" onChange={handleMinimumScore}>
    29                  <div className="input-group-append">
    30                      <DynamicButton
    31                          text="Approve all"
    32                          color={Color.GRAY}
    33                          type={ButtonType.OUTLINE}
    34                          onClick={() => actions.review.releaseAll({ approve: true, release: false })}
    35                      />
    36                  </div>
    37                  <div className="input-group-append">
    38                      <DynamicButton
    39                          text="Release all"
    40                          color={Color.GRAY}
    41                          type={ButtonType.OUTLINE}
    42                          onClick={() => actions.review.releaseAll({ approve: false, release: true })}
    43                      />
    44                  </div>
    45              </FormInput>
    46          </div>
    47      )
    48  }
    49  
    50  export default Release