40 lines
864 B
TypeScript
Raw Normal View History

import React, { ComponentType, useContext } from 'react';
2019-12-07 13:28:52 +02:00
import { FormattedMessage as Message, MessageDescriptor } from 'react-intl';
import Context, { AuthContext } from './Context';
2019-12-07 13:28:52 +02:00
interface Props {
isAvailable?: (context: AuthContext) => boolean;
payload?: Record<string, any>;
2019-12-07 13:28:52 +02:00
label: MessageDescriptor;
}
const RejectionLink: ComponentType<Props> = ({
isAvailable,
payload,
label,
}) => {
const context = useContext(Context);
2019-12-07 13:28:52 +02:00
if (isAvailable && !isAvailable(context)) {
// TODO: if want to properly support multiple links, we should control
// the dividers ' | ' rendered from factory too
return null;
}
return (
<a
href="#"
onClick={(event) => {
event.preventDefault();
context.reject(payload);
}}
>
<Message {...label} />
</a>
);
};
2019-12-07 13:28:52 +02:00
export default RejectionLink;