mirror of
				https://github.com/elyby/accounts-frontend.git
				synced 2025-05-31 14:11:58 +05:30 
			
		
		
		
	Migrate auth components to new Context api
This commit is contained in:
		@@ -1,23 +1,19 @@
 | 
			
		||||
import PropTypes from 'prop-types';
 | 
			
		||||
import React from 'react';
 | 
			
		||||
import React, { useContext } from 'react';
 | 
			
		||||
import { FormattedMessage as Message, MessageDescriptor } from 'react-intl';
 | 
			
		||||
import { User } from 'app/components/user';
 | 
			
		||||
import { userShape } from 'app/components/user/User';
 | 
			
		||||
 | 
			
		||||
import Context, { AuthContext } from './Context';
 | 
			
		||||
 | 
			
		||||
interface Props {
 | 
			
		||||
  isAvailable?: (context: Context) => boolean;
 | 
			
		||||
  isAvailable?: (context: AuthContext) => boolean;
 | 
			
		||||
  payload?: { [key: string]: any };
 | 
			
		||||
  label: MessageDescriptor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export type RejectionLinkProps = Props;
 | 
			
		||||
 | 
			
		||||
interface Context {
 | 
			
		||||
  reject: (payload: { [key: string]: any } | undefined) => void;
 | 
			
		||||
  user: User;
 | 
			
		||||
}
 | 
			
		||||
function RejectionLink(props: Props) {
 | 
			
		||||
  const context = useContext(Context);
 | 
			
		||||
 | 
			
		||||
function RejectionLink(props: Props, context: Context) {
 | 
			
		||||
  if (props.isAvailable && !props.isAvailable(context)) {
 | 
			
		||||
    // TODO: if want to properly support multiple links, we should control
 | 
			
		||||
    // the dividers ' | ' rendered from factory too
 | 
			
		||||
@@ -38,9 +34,4 @@ function RejectionLink(props: Props, context: Context) {
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
RejectionLink.contextTypes = {
 | 
			
		||||
  reject: PropTypes.func.isRequired,
 | 
			
		||||
  user: userShape,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default RejectionLink;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user