Skip to content

Commit

Permalink
fix: add a product check first for some features (#22581)
Browse files Browse the repository at this point in the history
* add a product check first for some features

* Update payGateMiniLogic.tsx

* Update payGateMiniLogic.tsx

* Update payGateMiniLogic.tsx
  • Loading branch information
zlwaterfield authored Jun 3, 2024
1 parent 5ef5937 commit 9f5551a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions frontend/src/lib/components/PayGateMini/payGateMiniLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,24 @@ export const payGateMiniLogic = kea<payGateMiniLogicType>([
productWithFeature: [
(s) => [s.billing],
(billing) => {
// check addons first since their features are rolled up into the parent
// TODO(@zach): revisit this logic after subscribe to all products is released
// There are some features where we want to check the product first
const checkProductFirst = [AvailableFeature.ORGANIZATIONS_PROJECTS]

let foundProduct: BillingProductV2Type | BillingProductV2AddonType | undefined = undefined

if (checkProductFirst.includes(props.featureKey)) {
foundProduct = billing?.products?.find((product) =>
product.features?.some((f) => f.key === props.featureKey)
)
}

// Check addons first (if not included in checkProductFirst) since their features are rolled up into the parent
const allAddons = billing?.products?.map((product) => product.addons).flat() || []
let foundProduct: BillingProductV2Type | BillingProductV2AddonType | undefined = allAddons.find(
(addon) => addon.features?.some((f) => f.key === props.featureKey)
)
if (!foundProduct) {
foundProduct = allAddons.find((addon) => addon.features?.some((f) => f.key === props.featureKey))
}

if (!foundProduct) {
foundProduct = billing?.products?.find((product) =>
product.features?.some((f) => f.key === props.featureKey)
Expand Down

0 comments on commit 9f5551a

Please sign in to comment.