From bf0d9efea87a2788fce6cba14fe9debaec8ac00b Mon Sep 17 00:00:00 2001 From: Jure Triglav <juretriglav@gmail.com> Date: Wed, 15 Jul 2020 17:14:27 +0200 Subject: [PATCH] feat: extract StatusBadge --- .../component-manuscripts/src/Manuscript.jsx | 18 +---- .../component-manuscripts/src/style.js | 22 +----- app/components/shared/Badge.js | 73 +++++++++++++++++++ 3 files changed, 79 insertions(+), 34 deletions(-) create mode 100644 app/components/shared/Badge.js diff --git a/app/components/component-manuscripts/src/Manuscript.jsx b/app/components/component-manuscripts/src/Manuscript.jsx index aedc96b0bd..95493e7e2e 100644 --- a/app/components/component-manuscripts/src/Manuscript.jsx +++ b/app/components/component-manuscripts/src/Manuscript.jsx @@ -15,6 +15,7 @@ import { ErrorStatus, NormalStatus, UserAction as Action, + StatusBadge, } from './style' import { convertTimestampToDate } from '../../../shared/time-formatting' @@ -25,14 +26,6 @@ const DELETE_MANUSCRIPT = gql` } ` -const Status = ({ status }) => { - if (status === 'accepted') { - return <SuccessStatus>{status}</SuccessStatus> - } else if (status === 'rejected') { - return <ErrorStatus>{status}</ErrorStatus> - } - return <NormalStatus>{status}</NormalStatus> -} const User = ({ manuscript }) => { const [deleteManuscript] = useMutation(DELETE_MANUSCRIPT) @@ -41,17 +34,10 @@ const User = ({ manuscript }) => { <Row> <Cell> {manuscript.meta && manuscript.meta.title} - {/* <UserCombo> - <UserAvatar manuscript={manuscript} /> - <UserInfo> - <Primary>{manuscript.username}</Primary> - <Secondary>{manuscript.email || '(via ORCID)'}</Secondary> - </UserInfo> - </UserCombo> */} </Cell> <Cell>{convertTimestampToDate(manuscript.created)}</Cell> <Cell> - <Status status={manuscript.status} /> + <StatusBadge status={manuscript.status} /> </Cell> <Cell> {manuscript.submitter && ( diff --git a/app/components/component-manuscripts/src/style.js b/app/components/component-manuscripts/src/style.js index d6e558a0c7..6f5c40a4ad 100644 --- a/app/components/component-manuscripts/src/style.js +++ b/app/components/component-manuscripts/src/style.js @@ -20,29 +20,15 @@ export { CaretDown, Spinner, Pagination, + SuccessStatus, + ErrorStatus, + NormalStatus, + StatusBadge, } from '../../shared' // TODO: Extract common above // Specific -const Status = styled.span` - border-radius: 8px; - font-variant: all-small-caps; - padding: ${grid(0.5)} ${grid(1)}; -` -export const SuccessStatus = styled(Status)` - background-color: ${th('colorSuccess')}; -` - -export const ErrorStatus = styled(Status)` - background-color: ${th('colorError')}; -` - -export const NormalStatus = styled(Status)` - background-color: ${th('colorWarning')}; - // color: ${th('colorTextReverse')}; -` - export const UserAction = styled(Action)` font-size: inherit; ` diff --git a/app/components/shared/Badge.js b/app/components/shared/Badge.js new file mode 100644 index 0000000000..f7f1a2e873 --- /dev/null +++ b/app/components/shared/Badge.js @@ -0,0 +1,73 @@ +import React from 'react' +import styled, { css } from 'styled-components' +import { grid, th } from '@pubsweet/ui-toolkit' + +const Status = styled.span` + border-radius: 8px; + font-variant: all-small-caps; + font-size: ${th('fontSizeBaseSmall')}; + ${props => + !props.minimal && + css` + padding: ${grid(0.5)} ${grid(1)}; + `} +` + +export const SuccessStatus = styled(Status)` + ${props => + props.minimal + ? css` + color: ${th('colorSuccess')}; + ` + : css` + background-color: ${th('colorSuccess')}; + color: ${th('colorTextReverse')}; + `} +` + +export const ErrorStatus = styled(Status)` + ${props => + props.minimal + ? css` + color: ${th('colorError')}; + ` + : css` + background-color: ${th('colorError')}; + color: ${th('colorTextReverse')}; + `} +` + +export const NormalStatus = styled(Status)` + // background-color: ${th('colorWarning')}; + // color: ${th('colorTextReverse')}; + ${props => + props.minimal + ? css` + color: ${th('colorPrimary')}; + ` + : css` + background-color: ${th('colorWarning')}; + `} +` + +const label = status => { + const labels = { + accepted: 'Accepted', + assignedToEditor: 'Assigned to editor', + assigningReviewers: 'Assigning reviewers', + new: 'Unsubmitted', + rejected: 'Rejected', + submitted: 'Submitted', + revise: 'Revising', + } + return labels[status] || `Unknown (${status})` +} + +export const StatusBadge = ({ status, minimal }) => { + if (status === 'accepted') { + return <SuccessStatus minimal={minimal}>{label(status)}</SuccessStatus> + } else if (status === 'rejected') { + return <ErrorStatus minimal={minimal}>{label(status)}</ErrorStatus> + } + return <NormalStatus minimal={minimal}>{label(status)}</NormalStatus> +} -- GitLab