Skip to content

Commit be07402

Browse files
committed
Fix additional feeds unable to be set to 0
1 parent 4bdf66c commit be07402

1 file changed

Lines changed: 33 additions & 20 deletions

File tree

  • services/backend-api/client/src/components/PricingDialog

services/backend-api/client/src/components/PricingDialog/index.tsx

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -383,31 +383,44 @@ export const PricingDialog = ({ isOpen, onClose, onOpen }: Props) => {
383383
setLoadingAdditionalFeedsChange(true);
384384

385385
async function getPreview() {
386-
const [preview, chargePreviewResult] = await Promise.all([
387-
getPricePreview([
388-
{
389-
priceId: priceIdOfAdditionalFeeds as string,
390-
quantity: newQuantity,
391-
},
392-
]),
393-
getChargePreview([
394-
{
395-
priceId: priceIdOfAdditionalFeeds as string,
396-
quantity: newQuantity,
397-
},
386+
if (newQuantity > 0) {
387+
const [preview, chargePreviewResult] = await Promise.all([
388+
getPricePreview([
389+
{
390+
priceId: priceIdOfAdditionalFeeds as string,
391+
quantity: newQuantity,
392+
},
393+
]),
394+
getChargePreview([
395+
{
396+
priceId: priceIdOfAdditionalFeeds as string,
397+
quantity: newQuantity,
398+
},
399+
{
400+
priceId: priceIdOfTier3 as string,
401+
quantity: 1,
402+
},
403+
]),
404+
]);
405+
406+
const additionalFeedsPreview = preview.find((p) => p.id === ProductKey.Tier3Feed);
407+
408+
if (additionalFeedsPreview) {
409+
setAdditionalFeedPricePreview(additionalFeedsPreview);
410+
}
411+
412+
setChargePreview(chargePreviewResult.totalFormatted);
413+
} else {
414+
const chargePreviewResult = await getChargePreview([
398415
{
399416
priceId: priceIdOfTier3 as string,
400417
quantity: 1,
401418
},
402-
]),
403-
]);
404-
const additionalFeedsPreview = preview.find((p) => p.id === ProductKey.Tier3Feed);
419+
]);
405420

406-
if (additionalFeedsPreview) {
407-
setAdditionalFeedPricePreview(additionalFeedsPreview);
421+
setChargePreview(chargePreviewResult.totalFormatted);
408422
}
409423

410-
setChargePreview(chargePreviewResult.totalFormatted);
411424
setLoadingAdditionalFeedsChange(false);
412425
}
413426

@@ -435,7 +448,7 @@ export const PricingDialog = ({ isOpen, onClose, onOpen }: Props) => {
435448
(a) => a.key === ProductKey.Tier3Feed
436449
);
437450

438-
if (userAdditionalFeedsAddon?.quantity) {
451+
if (userAdditionalFeedsAddon?.quantity != null) {
439452
setAdditionalFeedsInput(userAdditionalFeedsAddon.quantity);
440453
}
441454

@@ -782,7 +795,7 @@ export const PricingDialog = ({ isOpen, onClose, onOpen }: Props) => {
782795
onClick={() => {
783796
const newQuantity = additionalFeedsInput - 1;
784797

785-
if (newQuantity > 0) {
798+
if (newQuantity >= 0) {
786799
onChangeAdditionalFeeds(newQuantity);
787800
setAdditionalFeedsInput(newQuantity);
788801
}

0 commit comments

Comments
 (0)