Skip to content

Commit ec879f4

Browse files
committed
refactor: enhance WebhooksPricingSection and calculator for improved usability
- Updated WebhooksPricingSection to remove the hideActivation prop and handle loading states with a spinner. - Modified PricingDiagram and WebhooksPricingCalculator components to accept an isDisabled prop, allowing for better control over user interactions. - Improved input handling in WebhooksPricingCalculator to prevent changes when disabled, enhancing user experience. - Adjusted the layout and opacity of components based on the isDisabled state for clearer visual feedback. These changes collectively improve the usability and clarity of the webhooks pricing features.
1 parent b4e2333 commit ec879f4

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

src/features/tonapi/pricing/ui/WebhooksPricingSection.tsx

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import {
1010
Flex,
1111
Grid,
1212
Button,
13-
Badge
13+
Badge,
14+
Center,
15+
Spinner
1416
} from '@chakra-ui/react';
15-
import { UsdCurrencyAmount } from 'src/shared';
17+
import { UsdCurrencyAmount, Network } from 'src/shared';
18+
import { useWebhooksQuery } from '../../webhooks/model/queries';
1619
import { WebhookTiers, calculateExpectedPrice } from '../utils/calculating';
1720

18-
export const PricingDiagram = () => {
21+
export const PricingDiagram: FC<{ isDisabled?: boolean }> = ({ isDisabled = false }) => {
1922
return (
20-
<Grid gap={3}>
23+
<Grid gap={3} opacity={isDisabled ? 0.6 : 1}>
2124
<Box>
2225
<Text textStyle="label2" pb={2} fontWeight={600}>
2326
Subscribed accounts
@@ -120,7 +123,7 @@ export const PricingDiagram = () => {
120123
);
121124
};
122125

123-
export const WebhooksPricingCalculator = () => {
126+
export const WebhooksPricingCalculator: FC<{ isDisabled?: boolean }> = ({ isDisabled = false }) => {
124127
const [accounts, setAccounts] = useState<number | null>(null);
125128
const [messages, setMessages] = useState<number | null>(null);
126129

@@ -136,7 +139,7 @@ export const WebhooksPricingCalculator = () => {
136139

137140
const currentPrice = new UsdCurrencyAmount(calculateExpectedPrice(accounts, messages));
138141
return (
139-
<Card w="100%">
142+
<Card flexDir="column" display="flex" w="100%" opacity={isDisabled ? 0.6 : 1}>
140143
<CardHeader>
141144
<Text textStyle="text.label2" fontWeight={600}>
142145
Pricing Calculator
@@ -146,14 +149,16 @@ export const WebhooksPricingCalculator = () => {
146149
<Input
147150
bg="white"
148151
border="1px solid #83898F52"
149-
onChange={e => parseIntInput(e, setAccounts)}
152+
isDisabled={isDisabled}
153+
onChange={e => !isDisabled && parseIntInput(e, setAccounts)}
150154
placeholder="Subscribed accounts"
151155
value={accounts ?? ''}
152156
/>
153157
<Input
154158
bg="white"
155159
border="1px solid #83898F52"
156-
onChange={e => parseIntInput(e, setMessages)}
160+
isDisabled={isDisabled}
161+
onChange={e => !isDisabled && parseIntInput(e, setMessages)}
157162
placeholder="Number of messages sent"
158163
value={messages ?? ''}
159164
/>
@@ -170,28 +175,41 @@ export const WebhooksPricingCalculator = () => {
170175
);
171176
};
172177

173-
export const WebhooksPricingSection: FC<{ hideActivation?: boolean }> = ({
174-
hideActivation = false
175-
}) => {
178+
export const WebhooksPricingSection: FC = () => {
176179
const navigate = useNavigate();
180+
const { data: webhooks = [], isLoading, error } = useWebhooksQuery(Network.MAINNET);
177181

178-
const handleActivateWebhooks = () => {
182+
const isWebhooksUnavailable = Boolean(error);
183+
const isWebhooksInactive = webhooks.length === 0 && !isLoading && !isWebhooksUnavailable;
184+
185+
const handleTryWebhooks = () => {
179186
navigate('../webhooks');
180187
};
181188

189+
// Loading state
190+
if (isLoading) {
191+
return (
192+
<Center py="8">
193+
<Spinner />
194+
</Center>
195+
);
196+
}
197+
182198
return (
183199
<Box>
200+
{/* Header with Inactive badge */}
184201
<Flex align="baseline" gap="3" mb="4">
185202
<Text textStyle="h4" fontWeight={600}>
186203
Webhooks
187204
</Text>
188-
{!hideActivation && (
205+
{isWebhooksInactive && (
189206
<Badge fontSize="xs" colorScheme="gray">
190207
Inactive
191208
</Badge>
192209
)}
193210
</Flex>
194211

212+
{/* Main content: Pricing diagram and calculator */}
195213
<Flex align="flex-start" wrap="wrap" gap="6">
196214
<Box flex="3 1 300px" minW="300px">
197215
<Text textStyle="body2" mb="3" color="text.secondary">
@@ -202,9 +220,9 @@ export const WebhooksPricingSection: FC<{ hideActivation?: boolean }> = ({
202220
</Box>
203221
<Box flex="1 1 308px" minW="280px">
204222
<WebhooksPricingCalculator />
205-
{!hideActivation && (
206-
<Button w="100%" mt="4" onClick={handleActivateWebhooks} variant="primary">
207-
Activate Webhooks
223+
{isWebhooksInactive && (
224+
<Button w="100%" mt="4" onClick={handleTryWebhooks} variant="primary">
225+
Try Webhooks
208226
</Button>
209227
)}
210228
</Box>

src/pages/landing/TonApiPricing.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const TonApiPricing = forwardRef<HTMLDivElement, BoxProps>((props, ref) => {
1515
<Divider my="8" />
1616
<LiteserversTiersSection />
1717
<Divider my="8" />
18-
<WebhooksPricingSection hideActivation />
18+
<WebhooksPricingSection />
1919
</Box>
2020
</Box>
2121
);

0 commit comments

Comments
 (0)