Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. // @flow
  2.  
  3. import React, { type StatelessFunctionalComponent } from 'react';
  4. import gql from 'graphql-tag';
  5. import { Query } from 'react-apollo';
  6. import { Badge } from '~/public/shared/components';
  7.  
  8. const STATUS_COUNT_QUERY = gql`
  9. query sellerItemStatusCounts($contractId: ID) {
  10. sellerItemStatusCounts(contractId: $contractId) {
  11. processing
  12. preview
  13. live
  14. ended
  15. }
  16. }
  17. `;
  18.  
  19. export const ContractStatusBadge: StatelessFunctionalComponent<{
  20. contractId: string,
  21. }> = ({
  22. contractId,
  23. }) => {
  24. return (
  25. <Query query={STATUS_COUNT_QUERY} variables={{ contractId: contractId }}>
  26. {({ loading, error, data: statusCounts }) => {
  27. if (loading || error) return null;
  28.  
  29. const counts = { ...statusCounts.sellerItemStatusCounts };
  30. const sum = counts.processing + counts.preview + counts.live + counts.ended;
  31.  
  32. if (!sum) return null;
  33.  
  34. let badgeStyle;
  35. let badgeText;
  36.  
  37. if (counts.ended === sum) {
  38. badgeText = 'Ended';
  39. } else if (counts.live + counts.ended) {
  40. badgeStyle = 'positive';
  41. badgeText = 'Live';
  42. } else {
  43. badgeStyle = 'neutral';
  44. badgeText = 'Processing';
  45. }
  46.  
  47. return (
  48. <Badge status={badgeStyle}>{badgeText}</Badge>
  49. );
  50. }}
  51. </Query>
  52. );
  53. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement