forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: break down helpers.ts and create new files (RocketChat#28611)
- Loading branch information
1 parent
5408835
commit b31ccd4
Showing
20 changed files
with
240 additions
and
181 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
"@rocket.chat/meteor": patch | ||
--- | ||
|
||
chore: break down helpers.ts and create new files | ||
|
||
🔀 changed `handleAPIError` import in AppDetailsPage.tsx | ||
🔀 changed `apiCurlGetter` import in AppDetailsAPIs.tsx | ||
🔀 changed `formatPriceAndPurchaseType` import in AppStatusPriceDisplay.tsx | ||
|
||
❌ deleted `apiCurlGetter, handleInstallError, handleAPIError, warnAppInstall, warnEnableDisableApp, warnStatusChange, formatPriceAndPurchaseType` and moved them to new files, from helpers.ts | ||
|
||
✅ created apiCurlGetter.ts file | ||
✅ created appErroredStatuses.ts file | ||
✅ created formatPrice.ts file | ||
✅ created formatPriceAndPurchaseType.ts file | ||
✅ created formatPricingPlan.ts file | ||
✅ created handleAPIError.ts file | ||
✅ created handleInstallError.ts file | ||
✅ created installApp.ts file | ||
✅ created updateApp.ts file | ||
✅ created warnAppInstal.ts file | ||
✅ created warnEnableDisableApp.ts file | ||
✅ created warnStatusChange.ts file | ||
|
||
🔀 changed `handleAPIError` import in useAppInstallationHandler.tsx | ||
🔀 changed `handleAPIError` import in useCategories.ts | ||
🔀 changed `handleAPIError` import in useOpenIncompatibleModal.tsx | ||
|
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
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
18 changes: 18 additions & 0 deletions
18
apps/meteor/client/views/marketplace/helpers/apiCurlGetter.ts
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { IApiEndpointMetadata } from '@rocket.chat/apps-engine/definition/api'; | ||
|
||
import { Utilities } from '../../../../ee/lib/misc/Utilities'; | ||
|
||
export const apiCurlGetter = | ||
(absoluteUrl: (path: string) => string) => | ||
(method: string, api: IApiEndpointMetadata): string[] => { | ||
const example = api.examples?.[method]; | ||
return Utilities.curl({ | ||
url: absoluteUrl(api.computedPath), | ||
method, | ||
params: example?.params, | ||
query: example?.query, | ||
content: example?.content, | ||
headers: example?.headers, | ||
auth: '', | ||
}).split('\n'); | ||
}; |
8 changes: 8 additions & 0 deletions
8
apps/meteor/client/views/marketplace/helpers/appErroredStatuses.ts
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AppStatus } from '@rocket.chat/apps-engine/definition/AppStatus'; | ||
|
||
export const appErroredStatuses = [ | ||
AppStatus.COMPILER_ERROR_DISABLED, | ||
AppStatus.ERROR_DISABLED, | ||
AppStatus.INVALID_SETTINGS_DISABLED, | ||
AppStatus.INVALID_LICENSE_DISABLED, | ||
]; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const formatPrice = (price: number): string => `\$${price.toFixed(2)}`; |
32 changes: 32 additions & 0 deletions
32
apps/meteor/client/views/marketplace/helpers/formatPriceAndPurchaseType.ts
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { PurchaseType, AppPricingPlan } from '@rocket.chat/core-typings'; | ||
|
||
import { formatPrice } from './formatPrice'; | ||
import { formatPricingPlan } from './formatPricingPlan'; | ||
|
||
type PlanType = 'Subscription' | 'Paid' | 'Free'; | ||
|
||
type FormattedPriceAndPlan = { | ||
type: PlanType; | ||
price: string; | ||
}; | ||
|
||
export const formatPriceAndPurchaseType = ( | ||
purchaseType: PurchaseType, | ||
pricingPlans: AppPricingPlan[], | ||
price: number, | ||
): FormattedPriceAndPlan => { | ||
if (purchaseType === 'subscription') { | ||
const type = 'Subscription'; | ||
if (!pricingPlans || !Array.isArray(pricingPlans) || pricingPlans.length === 0) { | ||
return { type, price: '-' }; | ||
} | ||
|
||
return { type, price: formatPricingPlan(pricingPlans[0]) }; | ||
} | ||
|
||
if (price > 0) { | ||
return { type: 'Paid', price: formatPrice(price) }; | ||
} | ||
|
||
return { type: 'Free', price: '-' }; | ||
}; |
23 changes: 23 additions & 0 deletions
23
apps/meteor/client/views/marketplace/helpers/formatPricingPlan.ts
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { AppPricingPlan } from '@rocket.chat/core-typings'; | ||
|
||
import { t } from '../../../../app/utils/lib/i18n'; | ||
import { formatPrice } from './formatPrice'; | ||
|
||
export const formatPricingPlan = ({ strategy, price, tiers = [], trialDays }: AppPricingPlan): string => { | ||
const { perUnit = false } = (Array.isArray(tiers) && tiers.find((tier) => tier.price === price)) || {}; | ||
|
||
const pricingPlanTranslationString = [ | ||
'Apps_Marketplace_pricingPlan', | ||
Array.isArray(tiers) && tiers.length > 0 && '+*', | ||
strategy, | ||
trialDays && 'trialDays', | ||
perUnit && 'perUser', | ||
] | ||
.filter(Boolean) | ||
.join('_'); | ||
|
||
return t(pricingPlanTranslationString, { | ||
price: formatPrice(price), | ||
trialDays, | ||
}); | ||
}; |
20 changes: 20 additions & 0 deletions
20
apps/meteor/client/views/marketplace/helpers/handleAPIError.ts
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { dispatchToastMessage } from '../../../lib/toast'; | ||
|
||
const shouldHandleErrorAsWarning = (message: string): boolean => { | ||
const warnings = ['Could not reach the Marketplace']; | ||
|
||
return warnings.includes(message); | ||
}; | ||
|
||
export const handleAPIError = (error: unknown): void => { | ||
if (error instanceof Error) { | ||
const { message } = error; | ||
|
||
if (shouldHandleErrorAsWarning(message)) { | ||
dispatchToastMessage({ type: 'warning', message }); | ||
return; | ||
} | ||
|
||
dispatchToastMessage({ type: 'error', message }); | ||
} | ||
}; |
Oops, something went wrong.