2020-01-18 02:07:52 +05:30
|
|
|
import React, { ComponentType, useContext } from 'react';
|
2019-12-07 16:58:52 +05:30
|
|
|
import { FormattedMessage as Message, MessageDescriptor } from 'react-intl';
|
2019-12-13 12:56:29 +05:30
|
|
|
|
|
|
|
import Context, { AuthContext } from './Context';
|
2016-05-14 18:08:00 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
interface Props {
|
2019-12-13 12:56:29 +05:30
|
|
|
isAvailable?: (context: AuthContext) => boolean;
|
2020-01-18 02:07:52 +05:30
|
|
|
payload?: Record<string, any>;
|
2019-12-07 16:58:52 +05:30
|
|
|
label: MessageDescriptor;
|
|
|
|
}
|
2016-05-14 18:08:00 +05:30
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
const RejectionLink: ComponentType<Props> = ({
|
|
|
|
isAvailable,
|
|
|
|
payload,
|
|
|
|
label,
|
|
|
|
}) => {
|
2019-12-13 12:56:29 +05:30
|
|
|
const context = useContext(Context);
|
2019-12-07 16:58:52 +05:30
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
if (isAvailable && !isAvailable(context)) {
|
2019-11-27 14:33:32 +05:30
|
|
|
// TODO: if want to properly support multiple links, we should control
|
|
|
|
// the dividers ' | ' rendered from factory too
|
|
|
|
return null;
|
|
|
|
}
|
2017-03-03 11:18:25 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return (
|
|
|
|
<a
|
|
|
|
href="#"
|
2020-05-20 22:05:52 +05:30
|
|
|
onClick={(event) => {
|
2019-11-27 14:33:32 +05:30
|
|
|
event.preventDefault();
|
2016-05-14 18:08:00 +05:30
|
|
|
|
2020-01-18 02:07:52 +05:30
|
|
|
context.reject(payload);
|
2019-11-27 14:33:32 +05:30
|
|
|
}}
|
|
|
|
>
|
2020-01-18 02:07:52 +05:30
|
|
|
<Message {...label} />
|
2019-11-27 14:33:32 +05:30
|
|
|
</a>
|
|
|
|
);
|
2020-01-18 02:07:52 +05:30
|
|
|
};
|
2016-05-14 18:08:00 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export default RejectionLink;
|