All files / modules/45-projects-orgs/pages/HomePageTemplate HomePageTemplate.tsx

80% Statements 16/20
0% Branches 0/3
66.67% Functions 2/3
78.95% Lines 15/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 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108              13x 13x                 13x 13x 13x   13x 13x 13x 13x                                   13x               14x   14x                     14x   14x                                                       1x                            
/*
 * 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 from 'react'
import {
  ButtonVariation,
  Container,
  FlexExpander,
  Heading,
  Layout,
  Link as ExternalLink,
  Text
} from '@wings-software/uicore'
import { Color } from '@harness/design-system'
import { useStrings } from 'framework/strings'
import { useProjectModal } from '@projects-orgs/modals/ProjectModal/useProjectModal'
import type { Project } from 'services/cd-ng'
import { useAppStore } from 'framework/AppStore/AppStoreContext'
import RbacButton from '@rbac/components/Button/Button'
import { FeatureIdentifier } from 'framework/featureStore/FeatureIdentifier'
import css from './HomePageTemplate.module.scss'
 
interface CTAProps {
  text?: string
  onClick?: () => void
}
 
interface HomePageTemplate {
  title: string
  subTitle: string
  bgImageUrl: string
  documentText: string
  projectCreateSuccessHandler: (data?: Project) => void
  documentURL?: string
  ctaProps?: CTAProps
  disableAdditionalCta?: boolean
}
 
export const HomePageTemplate: React.FC<HomePageTemplate> = ({
  title,
  bgImageUrl,
  subTitle,
  documentText,
  documentURL = 'https://ngdocs.harness.io/',
  projectCreateSuccessHandler
}) => {
  const { updateAppStore } = useAppStore()
 
  const { openProjectModal, closeProjectModal } = useProjectModal({
    onSuccess: projectCreateSuccessHandler,
    onWizardComplete: data => {
      closeProjectModal()
      if (data) {
        updateAppStore({ selectedProject: data })
        projectCreateSuccessHandler(data)
      }
    }
  })
 
  const { getString } = useStrings()
 
  return (
    <>
      <Container className={css.container} style={{ background: `transparent url(${bgImageUrl}) no-repeat` }}>
        <Layout.Vertical spacing="medium">
          <Heading font={{ weight: 'bold', size: 'large' }} color={Color.BLACK_100}>
            {title}
          </Heading>
          <Text color={'var(--grey-500)'} className={css.subTitle}>
            {subTitle}
          </Text>
          <ExternalLink
            className={css.link}
            color={'var(--primary-6)'}
            font={{ size: 'normal' }}
            href={documentURL}
            target="_blank"
          >
            {documentText}
          </ExternalLink>
          <Layout.Horizontal spacing="large" flex>
            <RbacButton
              variation={ButtonVariation.PRIMARY}
              featuresProps={{
                featuresRequest: {
                  featureNames: [FeatureIdentifier.MULTIPLE_PROJECTS]
                }
              }}
              large
              onClick={() => openProjectModal()}
            >
              {getString('createProject')}
            </RbacButton>
            <Text font={{ size: 'medium' }} color={Color.BLACK}>
              {getString('orSelectExisting')}
            </Text>
            <FlexExpander />
          </Layout.Horizontal>
        </Layout.Vertical>
      </Container>
    </>
  )
}