mirror of
https://github.com/Steffo99/sophon.git
synced 2024-12-23 07:14:21 +00:00
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import {faLockOpen} from "@fortawesome/free-solid-svg-icons"
|
|
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
|
|
import {Button} from "@steffo/bluelib-react"
|
|
import * as React from "react"
|
|
import {useAuthorizationContext} from "../../contexts/authorization"
|
|
import {ManagedResource} from "../../hooks/useManagedViewSet"
|
|
import {SophonNotebook} from "../../types/SophonTypes"
|
|
import {SafetyButton} from "../elements/SafetyButton"
|
|
import {useGroupMembership} from "../group/useGroupMembership"
|
|
|
|
|
|
export interface NotebookUnlockButtonProps {
|
|
resource: ManagedResource<SophonNotebook>,
|
|
}
|
|
|
|
|
|
export function NotebookUnlockButton({resource}: NotebookUnlockButtonProps): JSX.Element | null {
|
|
const authorization = useAuthorizationContext()
|
|
|
|
if(!useGroupMembership()) {
|
|
return null
|
|
}
|
|
if(!resource.value.locked_by) {
|
|
return null
|
|
}
|
|
|
|
if(resource.value.locked_by === authorization!.state.user!.id) {
|
|
return (
|
|
<Button onClick={() => resource.action("PATCH", "unlock", {})} disabled={resource.busy}>
|
|
<FontAwesomeIcon icon={faLockOpen} spin={resource.busy}/> Unlock
|
|
</Button>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<SafetyButton timeout={3} onClick={() => resource.action("PATCH", "unlock", {})} disabled={resource.busy}>
|
|
<FontAwesomeIcon icon={faLockOpen} spin={resource.busy}/> Unlock
|
|
</SafetyButton>
|
|
)
|
|
}
|