-
Notifications
You must be signed in to change notification settings - Fork 3.9k
create pay and downgrade rhp #59070
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
create pay and downgrade rhp #59070
Changes from all commits
c0874ec
3460611
d0a25cd
98a397b
8821f19
8f61fae
1e3337c
fe20442
0b4a434
5a8483b
287bed2
d9fa99d
ad6593e
938d99d
6f1f40d
3e35805
66d7a57
a1b7c49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import {useEffect, useRef} from 'react'; | ||
| import {useOnyx} from 'react-native-onyx'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
|
|
||
| function usePayAndDowngrade(setIsDeleteModalOpen: (value: boolean) => void) { | ||
| const [isLoadingBill] = useOnyx(ONYXKEYS.IS_LOADING_BILL_WHEN_DOWNGRADE, {canBeMissing: true}); | ||
| const [shouldBillWhenDowngrading] = useOnyx(ONYXKEYS.SHOULD_BILL_WHEN_DOWNGRADING, {canBeMissing: true}); | ||
| const isDeletingPaidWorkspaceRef = useRef(false); | ||
|
|
||
| const setIsDeletingPaidWorkspace = (value: boolean) => { | ||
| isDeletingPaidWorkspaceRef.current = value; | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| if (!isDeletingPaidWorkspaceRef.current || isLoadingBill) { | ||
| return; | ||
| } | ||
|
|
||
| if (!shouldBillWhenDowngrading) { | ||
| setIsDeleteModalOpen(true); | ||
|
Contributor
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. This line created a bug. More details - #61040 |
||
| } else { | ||
| Navigation.navigate(ROUTES.WORKSPACE_PAY_AND_DOWNGRADE.getRoute(Navigation.getActiveRoute())); | ||
| } | ||
|
|
||
| isDeletingPaidWorkspaceRef.current = false; | ||
| }, [isLoadingBill, shouldBillWhenDowngrading, setIsDeleteModalOpen]); | ||
|
|
||
| return {setIsDeletingPaidWorkspace, isLoadingBill}; | ||
| } | ||
|
|
||
| export default usePayAndDowngrade; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,6 +177,15 @@ Onyx.connect({ | |
| waitForCollectionCallback: true, | ||
| }); | ||
|
|
||
| // Indicates if downgrading the current subscription plan is allowed for the user. | ||
| let canDowngrade = false; | ||
|
Contributor
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. NAB: comment improvement /** Indicates if downgrading the current subscription plan is allowed for the user. */ |
||
| Onyx.connect({ | ||
| key: ONYXKEYS.ACCOUNT, | ||
| callback: (val) => { | ||
| canDowngrade = val?.canDowngrade ?? false; | ||
| }, | ||
| }); | ||
|
|
||
| /** | ||
| * @returns The date when the grace period ends. | ||
| */ | ||
|
|
@@ -569,6 +578,10 @@ function shouldRestrictUserBillableActions(policyID: string): boolean { | |
| return false; | ||
| } | ||
|
|
||
| function shouldCalculateBillNewDot(): boolean { | ||
| return canDowngrade && getOwnedPaidPolicies(allPolicies, currentUserAccountID).length === 1; | ||
|
Contributor
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. @dukenv0307 @blimpich, Just confirming—
Contributor
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. Can downgrade doesn't concern the 3 purchases logic, it has other logic. The three purchases logic is covered by the |
||
| } | ||
|
|
||
| function checkIfHasTeam2025Pricing() { | ||
| if (hasManualTeamPricing2025) { | ||
| return true; | ||
|
|
@@ -676,6 +689,7 @@ export { | |
| shouldShowPreTrialBillingBanner, | ||
| shouldShowDiscountBanner, | ||
| getEarlyDiscountInfo, | ||
| shouldCalculateBillNewDot, | ||
| getSubscriptionPlanInfo, | ||
| getSubscriptionPrice, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5080,6 +5080,78 @@ function getAssignedSupportData(policyID: string) { | |
| API.read(READ_COMMANDS.GET_ASSIGNED_SUPPORT_DATA, parameters); | ||
| } | ||
|
|
||
| /** | ||
| * Call the API to calculate the bill for the new dot | ||
| */ | ||
| function calculateBillNewDot() { | ||
|
Contributor
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. Let’s add a brief comment for the |
||
| const optimisticData: OnyxUpdate[] = [ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: ONYXKEYS.IS_LOADING_BILL_WHEN_DOWNGRADE, | ||
| value: true, | ||
| }, | ||
| ]; | ||
| const successData: OnyxUpdate[] = [ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: ONYXKEYS.IS_LOADING_BILL_WHEN_DOWNGRADE, | ||
| value: false, | ||
| }, | ||
| ]; | ||
| const failureData: OnyxUpdate[] = [ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: ONYXKEYS.IS_LOADING_BILL_WHEN_DOWNGRADE, | ||
| value: false, | ||
| }, | ||
| ]; | ||
| API.read(READ_COMMANDS.CALCULATE_BILL_NEW_DOT, null, { | ||
| optimisticData, | ||
| successData, | ||
| failureData, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Call the API to pay and downgrade | ||
| */ | ||
| function payAndDowngrade() { | ||
| const optimisticData: OnyxUpdate[] = [ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: ONYXKEYS.BILLING_RECEIPT_DETAILS, | ||
| value: { | ||
| errors: null, | ||
| isLoading: true, | ||
| }, | ||
| }, | ||
| ]; | ||
| const successData: OnyxUpdate[] = [ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: ONYXKEYS.BILLING_RECEIPT_DETAILS, | ||
| value: { | ||
| isLoading: false, | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| const failureData: OnyxUpdate[] = [ | ||
| { | ||
| onyxMethod: Onyx.METHOD.MERGE, | ||
| key: ONYXKEYS.BILLING_RECEIPT_DETAILS, | ||
| value: { | ||
| isLoading: false, | ||
| }, | ||
| }, | ||
| ]; | ||
| API.write(WRITE_COMMANDS.PAY_AND_DOWNGRADE, null, {optimisticData, successData, failureData}); | ||
| } | ||
|
|
||
| function clearBillingReceiptDetailsErrors() { | ||
| Onyx.merge(ONYXKEYS.BILLING_RECEIPT_DETAILS, {errors: null}); | ||
| } | ||
|
|
||
| export { | ||
| leaveWorkspace, | ||
| addBillingCardAndRequestPolicyOwnerChange, | ||
|
|
@@ -5180,6 +5252,9 @@ export { | |
| updateDefaultPolicy, | ||
| getAssignedSupportData, | ||
| downgradeToTeam, | ||
| calculateBillNewDot, | ||
| payAndDowngrade, | ||
| clearBillingReceiptDetailsErrors, | ||
| clearQuickbooksOnlineAutoSyncErrorField, | ||
| updateLastAccessedWorkspaceSwitcher, | ||
| }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.