Last active
July 10, 2019 19:12
-
-
Save ryanahamilton/8e4d66fa9517c61e3b40e1b719734e58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import React, { type StatelessFunctionalComponent } from 'react'; | |
import gql from 'graphql-tag'; | |
import { Query } from 'react-apollo'; | |
import { Badge } from '~/public/shared/components'; | |
const STATUS_COUNT_QUERY = gql` | |
query sellerItemStatusCounts($contractId: ID) { | |
sellerItemStatusCounts(contractId: $contractId) { | |
processing | |
preview | |
live | |
ended | |
} | |
} | |
`; | |
export const ContractStatusBadge: StatelessFunctionalComponent<{ | |
contractId: string, | |
}> = ({ | |
contractId, | |
}) => { | |
return ( | |
<Query query={STATUS_COUNT_QUERY} variables={{ contractId: contractId }}> | |
{({ loading, error, data: statusCounts }) => { | |
if (loading || error) return null; | |
const counts = { ...statusCounts.sellerItemStatusCounts }; | |
const sum = counts.processing + counts.preview + counts.live + counts.ended; | |
if (!sum) return null; | |
let badgeStyle; | |
let badgeText; | |
if (counts.ended === sum) { | |
badgeText = 'Ended'; | |
} else if (counts.live + counts.ended) { | |
badgeStyle = 'positive'; | |
badgeText = 'Live'; | |
} else { | |
badgeStyle = 'neutral'; | |
badgeText = 'Processing'; | |
} | |
return ( | |
<Badge status={badgeStyle}>{badgeText}</Badge> | |
); | |
}} | |
</Query> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment