All files / modules/75-ce/components/SetupCloudProviderModalChild SetupCloudProviderModalChild.tsx

0% Statements 0/22
0% Branches 0/6
0% Functions 0/5
0% Lines 0/22

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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91                                                                                                                                                                                     
/*
 * Copyright 2021 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 cx from 'classnames'
import { Button, Card, Heading, Layout, Icon, IconName, Text } from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import { useAppStore } from 'framework/AppStore/AppStoreContext'
import { useStrings } from 'framework/strings'
import type { Project, ConnectorInfoDTO } from 'services/cd-ng'
 
import css from './SetupCloudProviderModalChild.module.scss'
 
interface SetupCloudProviderModalChild {
  closeModal?: () => void
  routeToCE: (provider: ConnectorInfoDTO['type'], project?: Project) => void
}
 
const SetupCloudProviderModalChild: React.FC<SetupCloudProviderModalChild> = props => {
  const { closeModal, routeToCE } = props
 
  const { getString } = useStrings()
  const { selectedProject } = useAppStore()
  const [selectedProvider, setSelectedProvider] = useState<ConnectorInfoDTO['type'] | undefined>(undefined)
 
  const isContinueDisabled = !selectedProvider
 
  const isAzureSelected = selectedProvider === 'CEAzure'
  const isAwsSelected = selectedProvider === 'CEAws'
 
  function handleSelectAzure(): void {
    setSelectedProvider('CEAzure')
  }
 
  function handleSelectAws(): void {
    setSelectedProvider('CEAws')
  }
 
  function handleSetupLater(): void {
    closeModal?.()
  }
 
  function handleContinueClick(): void {
    if (selectedProvider) {
      routeToCE(selectedProvider, selectedProject)
    }
  }
 
  return (
    <Layout.Vertical spacing="small">
      <Heading color={Color.BLACK} font={{ size: 'large', weight: 'bold' }} padding={{ top: 'xlarge' }}>
        {getString('ce.co.setupCloudProvider')}
      </Heading>
      <Text font={{ size: 'medium' }}>{getString('ce.co.getStarted')}</Text>
      <Layout.Horizontal spacing="medium" style={{ paddingTop: '30px' }}>
        <div className={cx(css.cardContainer)}>
          <Card interactive={true} selected={isAzureSelected} className={cx(css.card)} onClick={handleSelectAzure}>
            <Icon name={`service-azure` as IconName} size={24} />
          </Card>
          <Text font={{ size: 'xsmall', weight: 'bold' }} style={{ marginTop: 8 }}>
            {getString('authSettings.azure')}
          </Text>
        </div>
        <div className={cx(css.cardContainer)}>
          <Card interactive={true} selected={isAwsSelected} className={cx(css.card)} onClick={handleSelectAws}>
            <Icon name={`service-aws` as IconName} size={24} />
          </Card>
          <Text font={{ size: 'xsmall', weight: 'bold' }} style={{ marginTop: 8 }}>
            {getString('ce.co.cloudProviders.aws')}
          </Text>
        </div>
      </Layout.Horizontal>
      <Layout.Horizontal spacing="medium" style={{ paddingTop: '30px' }}>
        <Button
          intent="primary"
          disabled={isContinueDisabled}
          text={getString('continue')}
          onClick={handleContinueClick}
        />
        <Button intent="none" text={getString('pipeline.createPipeline.setupLater')} onClick={handleSetupLater} />
      </Layout.Horizontal>
    </Layout.Vertical>
  )
}
 
export default SetupCloudProviderModalChild