-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hiding messaging when external payments are provided #1425
Merged
travjenkins
merged 4 commits into
main
from
travjenkins/bug/fix-billing-content-for-external-payments
Jan 23, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
adf5571
Making function just set all the related data
travjenkins 146b0d4
Setting some changes back as they are not needed
travjenkins 70e1e71
Moving stuff into a hook to make it a bit simpler and sharable
travjenkins 4c3145d
Merge branch 'main' into travjenkins/bug/fix-billing-content-for-exte…
travjenkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ import { MAX_TENANTS } from 'api/billing'; | |
import FullPageError from 'components/fullPage/Error'; | ||
import { useUserInfoSummaryStore } from 'context/UserInfoSummary/useUserInfoSummaryStore'; | ||
import { useTenantsDetailsForPayment } from 'hooks/useTenants'; | ||
import { createContext, useContext } from 'react'; | ||
import { createContext, useContext, useMemo } from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { useEntitiesStore_tenantsWithAdmin } from 'stores/Entities/hooks'; | ||
import { BaseComponentProps, TenantPaymentDetails } from 'types'; | ||
|
@@ -14,7 +14,7 @@ const TenantContext = createContext<TenantContextData>({ | |
tenantBillingDetails: null, | ||
}); | ||
|
||
const TenantBillingDetailsContextProvider = ({ | ||
export const TenantBillingDetailsContextProvider = ({ | ||
children, | ||
}: BaseComponentProps) => { | ||
const hasSupportRole = useUserInfoSummaryStore( | ||
|
@@ -62,8 +62,21 @@ const TenantBillingDetailsContextProvider = ({ | |
// TODO (optimization): Consider defining a hook that returns an array of mapped tenant names. | ||
// The majority of the components that call useTenantDetails do so to extract a memoized | ||
// array of tenant names. | ||
const useTenantBillingDetails = () => { | ||
export const useTenantBillingDetails = () => { | ||
return useContext(TenantContext); | ||
}; | ||
|
||
export { TenantBillingDetailsContextProvider, useTenantBillingDetails }; | ||
export const useTenantUsesExternalPayment = (selectedTenant: string) => { | ||
const { tenantBillingDetails } = useTenantBillingDetails(); | ||
|
||
return useMemo(() => { | ||
return !tenantBillingDetails | ||
? false | ||
: tenantBillingDetails.some((tenantBillingDetail) => { | ||
return ( | ||
tenantBillingDetail.tenant === selectedTenant && | ||
tenantBillingDetail.payment_provider === 'external' | ||
); | ||
}); | ||
Comment on lines
+73
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a benefit to using a ternary as opposed to the nullish coalescing operator? |
||
}, [selectedTenant, tenantBillingDetails]); | ||
}; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this component shouldn't return
null
when an external payment method is detected? The argument I would make against returningnull
in this scenario is to more easily accommodate external payment method messaging in the future.The only minor oddity with the current approach is that the loading state will still be displayed when
externalPaymentMethod
istrue
despite the message not having any content.