2017-08-23 00:19:50 +05:30
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2019-12-07 16:58:52 +05:30
|
|
|
import { FormattedMessage as Message, MessageDescriptor } from 'react-intl';
|
2019-12-08 00:32:00 +05:30
|
|
|
import { User } from 'app/components/user';
|
|
|
|
import { userShape } from 'app/components/user/User';
|
2016-05-14 18:08:00 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
interface Props {
|
|
|
|
isAvailable?: (context: Context) => boolean;
|
|
|
|
payload?: { [key: string]: any };
|
|
|
|
label: MessageDescriptor;
|
|
|
|
}
|
2016-05-14 18:08:00 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export type RejectionLinkProps = Props;
|
2017-03-03 11:18:25 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
interface Context {
|
|
|
|
reject: (payload: { [key: string]: any } | undefined) => void;
|
|
|
|
user: User;
|
|
|
|
}
|
|
|
|
|
|
|
|
function RejectionLink(props: Props, context: Context) {
|
2019-11-27 14:33:32 +05:30
|
|
|
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 11:18:25 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return (
|
|
|
|
<a
|
|
|
|
href="#"
|
|
|
|
onClick={event => {
|
|
|
|
event.preventDefault();
|
2016-05-14 18:08:00 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
context.reject(props.payload);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Message {...props.label} />
|
|
|
|
</a>
|
|
|
|
);
|
2016-05-14 18:08:00 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
RejectionLink.contextTypes = {
|
2019-11-27 14:33:32 +05:30
|
|
|
reject: PropTypes.func.isRequired,
|
|
|
|
user: userShape,
|
2016-05-14 18:08:00 +05:30
|
|
|
};
|
2019-12-07 16:58:52 +05:30
|
|
|
|
|
|
|
export default RejectionLink;
|