2021-10-14 03:05:01 +00:00
|
|
|
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"
|
2021-10-20 20:39:19 +00:00
|
|
|
import {useGroupMembership} from "../group/useGroupMembership"
|
2021-10-14 03:05:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
export interface NotebookUnlockButtonProps {
|
|
|
|
resource: ManagedResource<SophonNotebook>,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function NotebookUnlockButton({resource}: NotebookUnlockButtonProps): JSX.Element | null {
|
|
|
|
const authorization = useAuthorizationContext()
|
|
|
|
|
2021-10-20 20:39:19 +00:00
|
|
|
if(!useGroupMembership()) {
|
2021-10-14 03:05:01 +00:00
|
|
|
return null
|
|
|
|
}
|
|
|
|
if(!resource.value.locked_by) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2021-10-20 20:39:19 +00:00
|
|
|
if(resource.value.locked_by === authorization!.state.user!.id) {
|
2021-10-14 03:05:01 +00:00
|
|
|
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>
|
|
|
|
)
|
|
|
|
}
|