Skip to content
Snippets Groups Projects
MultiAction.js 2.24 KiB
Newer Older
import React, { Fragment } from 'react'
import styled from 'styled-components'
import { th } from '@pubsweet/ui-toolkit'
import { H2, Button, Spinner } from '@pubsweet/ui'
import { compose, setDisplayName, withHandlers } from 'recompose'

import { IconButton, Text, Row } from '../'

const MultiAction = ({
  title,
  onClose,
  subtitle,
  onConfirm,
  modalError,
  isFetching,
  confirmText = 'OK',
  cancelText = 'Cancel',
}) => (
  <Root>
    <IconButton icon="x" onClick={onClose} right={5} secondary top={5} />
    <H2>{title}</H2>
    {subtitle && <Text secondary>{subtitle}</Text>}
    {modalError && (
      <Text error mt={1}>
        {modalError}
      </Text>
    )}
      {isFetching ? (
        <Spinner size={3} />
      ) : (
        <Fragment>
          <Button onClick={onClose}>{cancelText}</Button>
          <Button onClick={onConfirm} primary>
            {confirmText}
          </Button>
        </Fragment>
      )}
  </Root>
)

export default compose(
  withHandlers({
    onConfirm: ({ onConfirm, ...props }) => () => {
      if (onConfirm && typeof onConfirm === 'function') {
    onClose: ({ onCancel, ...props }) => () => {
      if (onCancel && typeof onCancel === 'function') {
    renderContent: ({ content, ...props }) => () => {
      if (!content) return null
      if (typeof content === 'object') {
        return content
      } else if (typeof content === 'function') {
      }
      return <Text dangerouslySetInnerHTML={{ __html: content }} mb={1} />
    },
  }),
  setDisplayName('MultiActionModal'),
)(MultiAction)

// #region styles
const Root = styled.div`
  align-items: center;
  background: ${th('colorBackground')};
  border: ${th('borderWidth')} ${th('borderStyle')} transparent;
  border-radius: ${th('borderRadius')};
  box-shadow: ${th('boxShadow')};
  display: flex;
  flex-direction: column;
  position: relative;
  padding: calc(${th('gridUnit')} * 5);

  ${H2} {
    margin: 0 0 ${th('gridUnit')} 0;
    text-align: center;
  }

  ${Text} {
    margin-bottom: ${th('gridUnit')};
  }
`
// #endregion