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

36 lines
937 B
TypeScript
Raw Permalink Normal View History

import React, { ComponentType, 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 {
2020-05-24 04:38:24 +05:30
isAvailable?: (context: AuthContext) => boolean;
payload?: Record<string, any>;
label: MessageDescriptor;
2019-12-07 16:58:52 +05:30
}
2020-05-24 04:38:24 +05:30
const RejectionLink: ComponentType<Props> = ({ isAvailable, payload, label }) => {
const context = useContext(Context);
2019-12-07 16:58:52 +05:30
2020-05-24 04:38:24 +05:30
if (isAvailable && !isAvailable(context)) {
// TODO: if want to properly support multiple links, we should control
// the dividers ' | ' rendered from factory too
return null;
}
2020-05-24 04:38:24 +05:30
return (
<a
href="#"
onClick={(event) => {
event.preventDefault();
2020-05-24 04:38:24 +05:30
context.reject(payload);
}}
>
<Message {...label} />
</a>
);
};
2019-12-07 16:58:52 +05:30
export default RejectionLink;