2021-10-11 17:13:32 +00:00
|
|
|
import {faTrash} from "@fortawesome/free-solid-svg-icons"
|
|
|
|
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
|
|
|
|
import * as React from "react"
|
|
|
|
import {useAuthorizationContext} from "../../contexts/authorization"
|
|
|
|
import {ManagedResource} from "../../hooks/useManagedViewSet"
|
|
|
|
import {SophonResearchGroup} from "../../types/SophonTypes"
|
|
|
|
import {SafetyButton} from "../elements/SafetyButton"
|
|
|
|
|
|
|
|
|
|
|
|
export interface GroupDeleteButtonProps {
|
|
|
|
resource: ManagedResource<SophonResearchGroup>,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function GroupDeleteButton({resource}: GroupDeleteButtonProps): JSX.Element | null {
|
|
|
|
const authorization = useAuthorizationContext()
|
|
|
|
|
|
|
|
const doDelete =
|
|
|
|
React.useCallback(
|
|
|
|
async () => {
|
|
|
|
await resource.destroy()
|
|
|
|
},
|
|
|
|
[resource],
|
|
|
|
)
|
|
|
|
|
|
|
|
if(!authorization) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
if(!authorization.state.user) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
if(resource.value.owner !== authorization.state.user.id) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-10-12 00:26:27 +00:00
|
|
|
<SafetyButton timeout={3} onClick={doDelete}>
|
2021-10-11 17:13:32 +00:00
|
|
|
<FontAwesomeIcon icon={faTrash} pulse={resource.busy}/> Delete
|
|
|
|
</SafetyButton>
|
|
|
|
)
|
|
|
|
}
|