accounts-frontend/packages/app/components/auth/RejectionLink.tsx

38 lines
863 B
TypeScript
Raw Normal View History

import React, { useContext } from 'react';
2019-12-07 16:58:52 +05:30
import { FormattedMessage as Message, MessageDescriptor } from 'react-intl';
import Context, { AuthContext } from './Context';
2019-12-07 16:58:52 +05:30
interface Props {
isAvailable?: (context: AuthContext) => boolean;
2019-12-07 16:58:52 +05:30
payload?: { [key: string]: any };
label: MessageDescriptor;
}
2019-12-07 16:58:52 +05:30
export type RejectionLinkProps = Props;
function RejectionLink(props: Props) {
const context = useContext(Context);
2019-12-07 16:58:52 +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;
}
return (
<a
href="#"
onClick={event => {
event.preventDefault();
context.reject(props.payload);
}}
>
<Message {...props.label} />
</a>
);
}
2019-12-07 16:58:52 +05:30
export default RejectionLink;