2017-08-23 00:19:50 +05:30
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
2016-05-14 18:08:00 +05:30
|
|
|
|
|
|
|
import { FormattedMessage as Message } from 'react-intl';
|
|
|
|
|
2017-03-03 11:18:25 +05:30
|
|
|
import { userShape } from 'components/user/User';
|
|
|
|
|
2016-05-14 18:08:00 +05:30
|
|
|
export default function RejectionLink(props, context) {
|
2017-03-03 11:18:25 +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;
|
|
|
|
}
|
|
|
|
|
2016-05-14 18:08:00 +05:30
|
|
|
return (
|
|
|
|
<a href="#" onClick={(event) => {
|
|
|
|
event.preventDefault();
|
|
|
|
|
2016-07-24 14:02:54 +05:30
|
|
|
context.reject(props.payload);
|
2016-05-14 18:08:00 +05:30
|
|
|
}}>
|
|
|
|
<Message {...props.label} />
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
RejectionLink.displayName = 'RejectionLink';
|
|
|
|
RejectionLink.propTypes = {
|
2017-03-03 11:18:25 +05:30
|
|
|
isAvailable: PropTypes.func, // a function from context to allow link visibility control
|
2016-07-24 14:02:54 +05:30
|
|
|
// eslint-disable-next-line react/forbid-prop-types
|
|
|
|
payload: PropTypes.object, // Custom payload for active state
|
2016-05-14 18:08:00 +05:30
|
|
|
label: PropTypes.shape({
|
|
|
|
id: PropTypes.string
|
|
|
|
}).isRequired
|
|
|
|
};
|
|
|
|
RejectionLink.contextTypes = {
|
2017-03-03 11:18:25 +05:30
|
|
|
reject: PropTypes.func.isRequired,
|
|
|
|
user: userShape
|
2016-05-14 18:08:00 +05:30
|
|
|
};
|