2019-12-13 09:26:29 +02:00
|
|
|
import React, { useContext } from 'react';
|
2019-12-07 13:28:52 +02:00
|
|
|
import { FormattedMessage as Message, MessageDescriptor } from 'react-intl';
|
2019-12-13 09:26:29 +02:00
|
|
|
|
|
|
|
import Context, { AuthContext } from './Context';
|
2016-05-14 15:38:00 +03:00
|
|
|
|
2019-12-07 13:28:52 +02:00
|
|
|
interface Props {
|
2019-12-13 09:26:29 +02:00
|
|
|
isAvailable?: (context: AuthContext) => boolean;
|
2019-12-07 13:28:52 +02:00
|
|
|
payload?: { [key: string]: any };
|
|
|
|
label: MessageDescriptor;
|
|
|
|
}
|
2016-05-14 15:38:00 +03:00
|
|
|
|
2019-12-07 13:28:52 +02:00
|
|
|
export type RejectionLinkProps = Props;
|
2017-03-03 07:48:25 +02:00
|
|
|
|
2019-12-13 09:26:29 +02:00
|
|
|
function RejectionLink(props: Props) {
|
|
|
|
const context = useContext(Context);
|
2019-12-07 13:28:52 +02:00
|
|
|
|
2019-11-27 11:03:32 +02:00
|
|
|
if (props.isAvailable && !props.isAvailable(context)) {
|
|
|
|
// TODO: if want to properly support multiple links, we should control
|
|
|
|
// the dividers ' | ' rendered from factory too
|
|
|
|
return null;
|
|
|
|
}
|
2017-03-03 07:48:25 +02:00
|
|
|
|
2019-11-27 11:03:32 +02:00
|
|
|
return (
|
|
|
|
<a
|
|
|
|
href="#"
|
|
|
|
onClick={event => {
|
|
|
|
event.preventDefault();
|
2016-05-14 15:38:00 +03:00
|
|
|
|
2019-11-27 11:03:32 +02:00
|
|
|
context.reject(props.payload);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Message {...props.label} />
|
|
|
|
</a>
|
|
|
|
);
|
2016-05-14 15:38:00 +03:00
|
|
|
}
|
|
|
|
|
2019-12-07 13:28:52 +02:00
|
|
|
export default RejectionLink;
|