All files / web/modules/admin/article/create CreateArticle.tsx

0% Statements 0/21
100% Branches 0/0
0% Functions 0/3
0% Lines 0/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64                                                                                                                               
import * as React from 'react';
import { Mutation } from 'react-apollo';
import { connect } from 'react-redux';
import { createArticlePermissions } from '../../../../../shared/permissions';
import { IState } from '../../../../types';
import {
  selectHasPermission,
  selectIsLoading,
  selectUsername,
  selectUserSub,
} from '../../../auth/reducer';
import Spin from '../../../components/Spin';
import { SETTINGS_ARTICLES } from '../../queries';
import { CREATE_ARTICLE } from '../mutations';
import CreateArticleForm from './CreateArticleForm';
 
interface IProps {
  username: string;
  userSub: string;
  hasPermission: (groups: string[]) => boolean;
  isLoading: boolean;
}
 
const CreateArticle = ({
  username,
  userSub,
  hasPermission,
  isLoading,
}: IProps) => {
  if (!hasPermission(createArticlePermissions)) {
    return null;
  }
 
  if (isLoading) {
    return <Spin size={14} />;
  }
 
  return (
    <Mutation
      mutation={CREATE_ARTICLE}
      refetchQueries={[{ query: SETTINGS_ARTICLES, variables: { userSub } }]}
    >
      {(createArticle, { loading }) => (
        <CreateArticleForm
          createArticle={createArticle}
          loading={loading}
          username={username}
          userSub={userSub}
        />
      )}
    </Mutation>
  );
};
 
export default connect(
  (state: IState) => ({
    username: selectUsername(state),
    userSub: selectUserSub(state),
    hasPermission: selectHasPermission(state),
    isLoading: selectIsLoading(state),
  }),
  {},
)(CreateArticle);