1- import {
2- Tag ,
3- StatusCompletedIcon ,
4- StatusIncomingIcon ,
5- StatusRunningIcon ,
6- CampaignExperientialIcon ,
7- CampaignFunctionalIcon ,
8- } from '@appquality/unguess-design-system' ;
1+ import { Tag } from '@appquality/unguess-design-system' ;
92import { theme } from 'src/app/theme' ;
10- import { TFunction , useTranslation } from 'react-i18next' ;
11-
12- export type CampaignStatus =
13- | 'running'
14- | 'completed'
15- | 'incoming'
16- | 'functional'
17- | 'experiential' ;
3+ import { CampaignStatus } from 'src/types' ;
4+ import { getStatusInfo } from '../utils/getStatusInfo' ;
185
196interface StatusTagArgs extends React . HTMLAttributes < HTMLDivElement > {
207 status : CampaignStatus ;
@@ -23,83 +10,30 @@ interface StatusTagArgs extends React.HTMLAttributes<HTMLDivElement> {
2310 isRound ?: boolean ;
2411}
2512
26- const getColorByStatus = ( status : CampaignStatus ) => {
27- switch ( status ) {
28- case 'running' :
29- return theme . palette . yellow [ 700 ] ;
30- case 'completed' :
31- return theme . palette . green [ 800 ] ;
32- case 'incoming' :
33- return theme . palette . azure [ 600 ] ;
34- case 'functional' :
35- return theme . palette . blue [ 700 ] ;
36- case 'experiential' :
37- return theme . palette . green [ 700 ] ;
38- default :
39- return theme . palette . grey [ 700 ] ;
40- }
41- } ;
42-
43- const getIconByStatus = ( status : CampaignStatus ) => {
44- switch ( status ) {
45- case 'running' :
46- return < StatusRunningIcon /> ;
47- case 'completed' :
48- return < StatusCompletedIcon /> ;
49- case 'incoming' :
50- return < StatusIncomingIcon /> ;
51- case 'functional' :
52- return < CampaignFunctionalIcon /> ;
53- case 'experiential' :
54- return < CampaignExperientialIcon /> ;
55- default :
56- return undefined ;
57- }
58- } ;
59-
60- const getDefaultTextByStatus = ( status : CampaignStatus , t : TFunction ) => {
61- switch ( status ) {
62- case 'running' :
63- return t ( '__CAMPAIGN_STATUS_RUNNING__' ) ;
64- case 'completed' :
65- return t ( '__CAMPAIGN_STATUS_COMPLETED__' ) ;
66- case 'incoming' :
67- return t ( '__CAMPAIGN_STATUS_INCOMING__' ) ;
68- case 'functional' :
69- return t ( '__CAMPAIGN_TYPE_FUNCTIONAL__' ) ;
70- case 'experiential' :
71- return t ( '__CAMPAIGN_TYPE_EXPERIENTIAL__' ) ;
72- default :
73- return undefined ;
74- }
75- } ;
76-
7713export const StatusTag = ( {
7814 status,
7915 children,
8016 counter,
8117 isRound,
8218 ...props
8319} : StatusTagArgs ) => {
84- const { t } = useTranslation ( ) ;
20+ const statusInfo = getStatusInfo ( status ) ;
21+
8522 return (
8623 < Tag
8724 size = "large"
8825 className = { `campaign-status-pill ${ status } ` }
89- color = { getColorByStatus ( status ) }
26+ color = { statusInfo . color }
9027 hue = "rgba(0,0,0,0)"
9128 isRound = { isRound }
9229 { ...props }
9330 >
94- { typeof getIconByStatus ( status ) !== 'undefined' && (
95- < Tag . Avatar > { getIconByStatus ( status ) } </ Tag . Avatar >
31+ { typeof statusInfo . icon !== 'undefined' && (
32+ < Tag . Avatar > { statusInfo . icon } </ Tag . Avatar >
9633 ) }
9734 {
9835 // children if passed, otherwise default text for normal pills and icon for round pills
99- children ||
100- ( isRound
101- ? getIconByStatus ( status )
102- : getDefaultTextByStatus ( status , t ) )
36+ children || ( isRound ? statusInfo . icon : statusInfo . text )
10337 }
10438 { typeof counter !== 'undefined' && (
10539 < Tag . SecondaryText isBold color = { theme . palette . grey [ 700 ] } >
0 commit comments