|
| 1 | +import React, { FC, useEffect } from 'react' |
| 2 | +import Constants from 'common/constants' |
| 3 | +import InfoMessage from 'components/InfoMessage' |
| 4 | +import BlockedOrgInfo from 'components/BlockedOrgInfo' |
| 5 | +import { Organisation } from 'common/types/responses' |
| 6 | +import { PricingToggle } from './PricingToggle' |
| 7 | +import { PricingPanel } from './PricingPanel' |
| 8 | +import { STARTUP_FEATURES, ENTERPRISE_FEATURES } from './pricingFeatures' |
| 9 | +import { |
| 10 | + CHARGEBEE_SCRIPT_URL, |
| 11 | + CONTACT_US_URL, |
| 12 | + ON_PREMISE_HOSTING_URL, |
| 13 | + SUPPORT_EMAIL, |
| 14 | + SUPPORT_EMAIL_URL, |
| 15 | +} from './constants' |
| 16 | +import { useScript } from 'common/hooks/useScript' |
| 17 | +import { usePaymentState } from './hooks' |
| 18 | +import { initChargebee } from './chargebee' |
| 19 | + |
| 20 | +export type PaymentProps = { |
| 21 | + isDisableAccountText?: string |
| 22 | + organisation: Organisation |
| 23 | + isPaymentsEnabled?: boolean |
| 24 | +} |
| 25 | + |
| 26 | +export const Payment: FC<PaymentProps> = ({ |
| 27 | + isDisableAccountText, |
| 28 | + isPaymentsEnabled = false, |
| 29 | + organisation, |
| 30 | +}) => { |
| 31 | + const { error, ready } = useScript(CHARGEBEE_SCRIPT_URL) |
| 32 | + const { hasActiveSubscription, isAWS, plan, setYearly, yearly } = |
| 33 | + usePaymentState({ organisation }) |
| 34 | + |
| 35 | + useEffect(() => { |
| 36 | + API.trackPage(Constants.modals.PAYMENT) |
| 37 | + }, []) |
| 38 | + |
| 39 | + useEffect(() => { |
| 40 | + if (ready && !error) { |
| 41 | + initChargebee({ isPaymentsEnabled }) |
| 42 | + } |
| 43 | + }, [ready, error, isPaymentsEnabled]) |
| 44 | + |
| 45 | + if (isAWS) { |
| 46 | + return ( |
| 47 | + <div className='col-md-8'> |
| 48 | + <InfoMessage collapseId='aws-marketplace'> |
| 49 | + Customers with AWS Marketplace subscriptions will need to{' '} |
| 50 | + <a href={CONTACT_US_URL} target='_blank' rel='noreferrer'> |
| 51 | + contact us |
| 52 | + </a> |
| 53 | + </InfoMessage> |
| 54 | + </div> |
| 55 | + ) |
| 56 | + } |
| 57 | + |
| 58 | + if (!ready) { |
| 59 | + return ( |
| 60 | + <div className='text-center'> |
| 61 | + <Loader /> |
| 62 | + </div> |
| 63 | + ) |
| 64 | + } |
| 65 | + |
| 66 | + return ( |
| 67 | + <div> |
| 68 | + <div className='col-md-12'> |
| 69 | + <Row space className='mb-4'> |
| 70 | + {isDisableAccountText && ( |
| 71 | + <div className='d-lg-flex flex-lg-row align-items-end justify-content-between w-100 gap-4'> |
| 72 | + <div> |
| 73 | + <h4> |
| 74 | + {isDisableAccountText}{' '} |
| 75 | + <a target='_blank' href={SUPPORT_EMAIL_URL} rel='noreferrer'> |
| 76 | + {SUPPORT_EMAIL} |
| 77 | + </a> |
| 78 | + </h4> |
| 79 | + </div> |
| 80 | + <div> |
| 81 | + <BlockedOrgInfo /> |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + )} |
| 85 | + </Row> |
| 86 | + |
| 87 | + <PricingToggle isYearly={yearly} onChange={setYearly} /> |
| 88 | + |
| 89 | + <Row className='pricing-container align-start'> |
| 90 | + <PricingPanel |
| 91 | + title='Start-Up' |
| 92 | + priceYearly='40' |
| 93 | + priceMonthly='45' |
| 94 | + isYearly={yearly} |
| 95 | + chargebeePlanId={ |
| 96 | + yearly |
| 97 | + ? Project.plans?.startup?.annual |
| 98 | + : Project.plans?.startup?.monthly |
| 99 | + } |
| 100 | + isPurchased={plan.includes('startup')} |
| 101 | + isDisableAccount={isDisableAccountText} |
| 102 | + features={STARTUP_FEATURES} |
| 103 | + hasActiveSubscription={hasActiveSubscription} |
| 104 | + organisationId={organisation.id} |
| 105 | + /> |
| 106 | + |
| 107 | + <PricingPanel |
| 108 | + title='Enterprise' |
| 109 | + isYearly={yearly} |
| 110 | + isEnterprise |
| 111 | + features={ENTERPRISE_FEATURES} |
| 112 | + hasActiveSubscription={hasActiveSubscription} |
| 113 | + organisationId={organisation.id} |
| 114 | + headerContent={ |
| 115 | + <> |
| 116 | + Optional{' '} |
| 117 | + <a |
| 118 | + className='text-primary fw-bold' |
| 119 | + target='_blank' |
| 120 | + href={ON_PREMISE_HOSTING_URL} |
| 121 | + rel='noreferrer' |
| 122 | + > |
| 123 | + On Premise |
| 124 | + </a>{' '} |
| 125 | + or{' '} |
| 126 | + <a |
| 127 | + className='text-primary fw-bold' |
| 128 | + target='_blank' |
| 129 | + href={ON_PREMISE_HOSTING_URL} |
| 130 | + rel='noreferrer' |
| 131 | + > |
| 132 | + Private Cloud |
| 133 | + </a>{' '} |
| 134 | + Install |
| 135 | + </> |
| 136 | + } |
| 137 | + /> |
| 138 | + </Row> |
| 139 | + <div className='text-center mt-4'> |
| 140 | + *Need something in-between our Enterprise plan for users or API |
| 141 | + limits? |
| 142 | + <div> |
| 143 | + <a href={CONTACT_US_URL}>Reach out</a> to us and we'll help you out |
| 144 | + </div> |
| 145 | + </div> |
| 146 | + </div> |
| 147 | + </div> |
| 148 | + ) |
| 149 | +} |
0 commit comments