-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc: refactor plan advanced settings section (#1684)
- Loading branch information
Showing
3 changed files
with
116 additions
and
109 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
src/components/plans/details/PlanDetailsAdvancedSettingsSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Stack } from '@mui/material' | ||
|
||
import { Accordion, Typography } from '~/components/designSystem' | ||
import { mapChargeIntervalCopy } from '~/components/plans/ChargeAccordion' | ||
import { getIntervalTranslationKey } from '~/core/constants/form' | ||
import { intlFormatNumber } from '~/core/formats/intlFormatNumber' | ||
import { deserializeAmount } from '~/core/serializers/serializeAmount' | ||
import { CurrencyEnum, EditPlanFragment, PlanInterval } from '~/generated/graphql' | ||
import { useInternationalization } from '~/hooks/core/useInternationalization' | ||
import { DetailsInfoGrid, DetailsSectionTitle } from '~/styles/detailsPage' | ||
|
||
import DetailsTableDisplay from '../../details/DetailsTableDisplay' | ||
|
||
const PlanDetailsAdvancedSettingsSection = ({ | ||
currency, | ||
plan, | ||
}: { | ||
currency: CurrencyEnum | ||
plan?: EditPlanFragment | null | ||
}) => { | ||
const { translate } = useInternationalization() | ||
const hasMinimumCommitment = isNaN(Number(plan?.minimumCommitment?.amountCents)) | ||
|
||
if (!hasMinimumCommitment) return null | ||
|
||
return ( | ||
<section> | ||
<DetailsSectionTitle variant="subhead" noWrap> | ||
{translate('text_65d601bffb11e0f9d1d9f567')} | ||
</DetailsSectionTitle> | ||
|
||
<Stack direction="column" gap={12}> | ||
{hasMinimumCommitment && ( | ||
<Stack direction="column" gap={4}> | ||
<div> | ||
<Typography variant="bodyHl" color="grey700"> | ||
{translate('text_65d601bffb11e0f9d1d9f569')} | ||
</Typography> | ||
<Typography variant="caption" color="grey600"> | ||
{translate('text_6661fc17337de3591e29e451', { | ||
interval: translate( | ||
mapChargeIntervalCopy(plan?.interval ?? PlanInterval.Monthly, false), | ||
).toLocaleLowerCase(), | ||
})} | ||
</Typography> | ||
</div> | ||
|
||
<Accordion | ||
summary={ | ||
<Typography variant="bodyHl" color="grey700"> | ||
{plan?.minimumCommitment?.invoiceDisplayName || | ||
translate('text_65d601bffb11e0f9d1d9f569')} | ||
</Typography> | ||
} | ||
> | ||
<Stack direction="column" spacing={4}> | ||
<DetailsTableDisplay | ||
header={[translate('text_65d601bffb11e0f9d1d9f571')]} | ||
body={[ | ||
[ | ||
intlFormatNumber( | ||
deserializeAmount( | ||
plan?.minimumCommitment?.amountCents || 0, | ||
plan?.amountCurrency || CurrencyEnum.Usd, | ||
), | ||
{ | ||
currency: currency, | ||
}, | ||
), | ||
], | ||
]} | ||
/> | ||
|
||
<DetailsInfoGrid | ||
grid={[ | ||
{ | ||
label: translate('text_65201b8216455901fe273dc1'), | ||
value: translate(getIntervalTranslationKey[plan?.interval as PlanInterval]), | ||
}, | ||
{ | ||
label: translate('text_645bb193927b375079d28a8f'), | ||
value: !!plan?.minimumCommitment?.taxes?.length | ||
? plan?.minimumCommitment?.taxes?.map((tax, i) => ( | ||
<Typography | ||
key={`plan-details-fixed-fee-taxe-${i}`} | ||
variant="body" | ||
color="grey700" | ||
> | ||
{tax.name} ( | ||
{intlFormatNumber(Number(tax.rate) / 100 || 0, { | ||
maximumFractionDigits: 2, | ||
style: 'percent', | ||
})} | ||
) | ||
</Typography> | ||
)) | ||
: '-', | ||
}, | ||
]} | ||
/> | ||
</Stack> | ||
</Accordion> | ||
</Stack> | ||
)} | ||
</Stack> | ||
</section> | ||
) | ||
} | ||
|
||
export default PlanDetailsAdvancedSettingsSection |
97 changes: 0 additions & 97 deletions
97
src/components/plans/details/PlanDetailsCommitmentsSection.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters