All files / modules/33-auth-settings/pages/subscriptions/plans PlansPanel.tsx

84.21% Statements 16/19
50% Branches 4/8
33.33% Functions 1/3
84.21% Lines 16/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63              2x 2x 2x 2x 2x     2x 2x 2x             2x 6x 6x 6x 6x 6x 6x                                                               2x  
/*
 * Copyright 2022 Harness Inc. All rights reserved.
 * Use of this source code is governed by the PolyForm Shield 1.0.0 license
 * that can be found in the licenses directory at the root of this repository, also available at
 * https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
 */
 
import React, { useState } from 'react'
import { Color } from '@harness/design-system'
import { Layout, Text } from '@wings-software/uicore'
import cx from 'classnames'
import { useStrings } from 'framework/strings'
import type { FetchPlansQuery } from 'services/common/services'
import type { ModuleName } from 'framework/types/ModuleName'
import { TIME_TYPE } from './planUtils'
import PlanContainer from './PlanContainer'
import css from './Plans.module.scss'
 
interface PlansPanelProps {
  module: ModuleName
  plans?: NonNullable<FetchPlansQuery['pricing']>['ciSaasPlans' | 'ffPlans' | 'cdPlans' | 'ccPlans']
}
 
const PlansPanel: React.FC<PlansPanelProps> = ({ plans, module }) => {
  const { getString } = useStrings()
  const [timeType, setTimeType] = useState<TIME_TYPE>(TIME_TYPE.YEARLY)
  const yearlySelected = timeType === TIME_TYPE.YEARLY ? css.selected : ''
  const monthlySelected = timeType === TIME_TYPE.MONTHLY ? css.selected : ''
  Eif (plans) {
    return (
      <Layout.Vertical>
        <Layout.Horizontal flex={{ justifyContent: 'flex-end', alignItems: 'baseline' }}>
          <Text padding={{ right: 'medium', top: 'small' }}>{getString('common.billed')}</Text>
          <Text
            color={Color.PRIMARY_6}
            padding={{ left: 'medium', right: 'medium', top: 'small', bottom: 'small' }}
            className={cx(css.yearly, yearlySelected)}
            onClick={() => setTimeType(TIME_TYPE.YEARLY)}
          >
            {getString('common.yearly')}
          </Text>
          <Text
            color={Color.PRIMARY_6}
            padding={{ left: 'medium', right: 'medium', top: 'small', bottom: 'small' }}
            className={cx(css.monthly, monthlySelected)}
            onClick={() => setTimeType(TIME_TYPE.MONTHLY)}
          >
            {getString('common.monthly')}
          </Text>
        </Layout.Horizontal>
        {timeType === TIME_TYPE.YEARLY ? (
          <PlanContainer plans={plans} timeType={TIME_TYPE.YEARLY} moduleName={module} />
        ) : (
          <PlanContainer plans={plans} timeType={TIME_TYPE.MONTHLY} moduleName={module} />
        )}
      </Layout.Vertical>
    )
  }
  return <></>
}
 
export default PlansPanel