-
Notifications
You must be signed in to change notification settings - Fork 257
/
Copy pathCoreOptionButton.tsx
69 lines (68 loc) · 1.98 KB
/
CoreOptionButton.tsx
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
import type { ReactElement } from 'react';
import React, { useCallback } from 'react';
import classNames from 'classnames';
import { useViewSize, ViewSize } from '../../hooks';
import { useBuyCoresContext } from '../../contexts/BuyCoresContext';
import { Button, ButtonSize, ButtonVariant } from '../buttons/Button';
import { CoinIcon } from '../icons';
import {
Typography,
TypographyColor,
TypographyType,
} from '../typography/Typography';
import { LogEvent } from '../../lib/log';
import { useLogContext } from '../../contexts/LogContext';
type CoreOptionButtonProps = {
id: string;
};
export const CoreOptionButton = ({
id,
}: CoreOptionButtonProps): ReactElement => {
const isMobile = useViewSize(ViewSize.MobileL);
const { logEvent } = useLogContext();
const { selectedProduct, setSelectedProduct, openCheckout, origin } =
useBuyCoresContext();
const onSelect = useCallback(() => {
// TODO: Amount should be deducted from selected product entity
logEvent({
event_name: LogEvent.SelectCreditsQuantity,
extra: JSON.stringify({ origin, amount: id }),
});
setSelectedProduct(id);
if (!isMobile) {
openCheckout({ priceId: id });
}
}, [id, isMobile, logEvent, openCheckout, origin, setSelectedProduct]);
return (
<Button
className={classNames(
'w-full',
selectedProduct === id
? 'border-action-cores-default bg-action-cores-float'
: undefined,
)}
variant={ButtonVariant.Float}
icon={<CoinIcon />}
size={ButtonSize.Large}
aria-checked={selectedProduct === id}
role="radio"
onClick={onSelect}
>
<Typography
type={TypographyType.Body}
color={TypographyColor.Primary}
bold
>
100
</Typography>
<div className="flex-1" />
<Typography
type={TypographyType.Callout}
color={TypographyColor.Tertiary}
className="font-normal"
>
$0.99
</Typography>
</Button>
);
};