From 05c2475d8dd2c49fd5b7b16a65b2102b1dd2558e Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Fri, 2 Feb 2024 17:19:07 -0300 Subject: [PATCH 1/3] feat: push quota --- .../troubleshootingNotification.test.ts | 4 +- app/reducers/troubleshootingNotification.ts | 9 ++-- app/sagas/troubleshootingNotification.ts | 5 ++- app/views/PushTroubleshootView/index.tsx | 44 ++++++++++--------- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/app/reducers/troubleshootingNotification.test.ts b/app/reducers/troubleshootingNotification.test.ts index b34ed265a..83938d47d 100644 --- a/app/reducers/troubleshootingNotification.test.ts +++ b/app/reducers/troubleshootingNotification.test.ts @@ -19,7 +19,9 @@ describe('test troubleshootingNotification reducer', () => { deviceNotificationEnabled: true, highlightTroubleshooting: false, defaultPushGateway: true, - pushGatewayEnabled: true + pushGatewayEnabled: true, + consumptionPercentage: 0, + isCommunityEdition: false }; mockedStore.dispatch(setTroubleshootingNotification(payload)); const state = mockedStore.getState().troubleshootingNotification; diff --git a/app/reducers/troubleshootingNotification.ts b/app/reducers/troubleshootingNotification.ts index be7311060..9da7bbf73 100644 --- a/app/reducers/troubleshootingNotification.ts +++ b/app/reducers/troubleshootingNotification.ts @@ -6,16 +6,17 @@ export interface ITroubleshootingNotification { pushGatewayEnabled: boolean; defaultPushGateway: boolean; highlightTroubleshooting: boolean; + consumptionPercentage: number; + isCommunityEdition: boolean; } export const initialState: ITroubleshootingNotification = { deviceNotificationEnabled: false, pushGatewayEnabled: false, defaultPushGateway: false, - highlightTroubleshooting: false - // TODO: This will be used in the near future when the consumption percentage is implemented on the server. - // consumptionPercentage: 0, - // isCommunityEdition: false, + highlightTroubleshooting: false, + consumptionPercentage: 0, + isCommunityEdition: false }; export default (state = initialState, action: TActionTroubleshootingNotification): ITroubleshootingNotification => { diff --git a/app/sagas/troubleshootingNotification.ts b/app/sagas/troubleshootingNotification.ts index 634f11c74..30dbf7216 100644 --- a/app/sagas/troubleshootingNotification.ts +++ b/app/sagas/troubleshootingNotification.ts @@ -20,13 +20,14 @@ function* request() { let defaultPushGateway = false; let pushGatewayEnabled = false; try { - const { authorizationStatus } = yield* call(notifee.getNotificationSettings); + const { authorizationStatus } = yield * call(notifee.getNotificationSettings); deviceNotificationEnabled = authorizationStatus > 0; - const pushInfoResult = yield* call(pushInfo); + const pushInfoResult = yield * call(pushInfo); if (pushInfoResult.success) { pushGatewayEnabled = pushInfoResult.pushGatewayEnabled; defaultPushGateway = pushInfoResult.defaultPushGateway; } + // TODO: Need to request the information of push quota and if the server is a community edition } catch (e) { log(e); } finally { diff --git a/app/views/PushTroubleshootView/index.tsx b/app/views/PushTroubleshootView/index.tsx index 280d5f02c..091001620 100644 --- a/app/views/PushTroubleshootView/index.tsx +++ b/app/views/PushTroubleshootView/index.tsx @@ -15,8 +15,7 @@ import { compareServerVersion, isIOS, showErrorAlert } from '../../lib/methods/h import { requestTroubleshootingNotification } from '../../actions/troubleshootingNotification'; import { useAppSelector, usePermissions } from '../../lib/hooks'; import { Services } from '../../lib/services'; -// TODO: This will be used in the near future when the consumption percentage is implemented on the server. -// import ListPercentage from './components/ListPercentage'; +import ListPercentage from './components/ListPercentage'; interface IPushTroubleshootViewProps { navigation: StackNavigationProp; @@ -26,18 +25,23 @@ const PushTroubleshootView = ({ navigation }: IPushTroubleshootViewProps): JSX.E const { colors } = useTheme(); const dispatch = useDispatch(); - const { deviceNotificationEnabled, defaultPushGateway, pushGatewayEnabled, foreground, serverVersion } = useAppSelector( - state => ({ - deviceNotificationEnabled: state.troubleshootingNotification.deviceNotificationEnabled, - pushGatewayEnabled: state.troubleshootingNotification.pushGatewayEnabled, - defaultPushGateway: state.troubleshootingNotification.defaultPushGateway, - foreground: state.app.foreground, - serverVersion: state.server.version - // TODO: This will be used in the near future when the consumption percentage is implemented on the server. - // isCommunityEdition: state.troubleshootingNotification.isCommunityEdition, - // consumptionPercentage: state.troubleshootingNotification.consumptionPercentage, - }) - ); + const { + deviceNotificationEnabled, + defaultPushGateway, + pushGatewayEnabled, + consumptionPercentage, + isCommunityEdition, + foreground, + serverVersion + } = useAppSelector(state => ({ + deviceNotificationEnabled: state.troubleshootingNotification.deviceNotificationEnabled, + pushGatewayEnabled: state.troubleshootingNotification.pushGatewayEnabled, + defaultPushGateway: state.troubleshootingNotification.defaultPushGateway, + foreground: state.app.foreground, + serverVersion: state.server.version, + isCommunityEdition: state.troubleshootingNotification.isCommunityEdition, + consumptionPercentage: state.troubleshootingNotification.consumptionPercentage + })); const [testPushNotificationsPermission] = usePermissions(['test-push-notifications']); @@ -65,10 +69,9 @@ const PushTroubleshootView = ({ navigation }: IPushTroubleshootViewProps): JSX.E ); }; - // TODO: This will be used in the near future when the consumption percentage is implemented on the server. - // const alertWorkspaceConsumption = () => { - // Alert.alert(I18n.t('Push_consumption_alert_title'), I18n.t('Push_consumption_alert_description')); - // }; + const alertWorkspaceConsumption = () => { + Alert.alert(I18n.t('Push_consumption_alert_title'), I18n.t('Push_consumption_alert_description')); + }; const goToNotificationSettings = () => { if (isIOS) { @@ -84,7 +87,7 @@ const PushTroubleshootView = ({ navigation }: IPushTroubleshootViewProps): JSX.E const result = await Services.pushTest(); if (result.success) { message = I18n.t('Your_push_was_sent_to_s_devices', { s: result.tokensCount }); - } + } } catch (error: any) { message = I18n.isTranslated(error?.data?.errorType) ? I18n.t(error?.data?.errorType) : error?.data?.error; } finally { @@ -120,7 +123,6 @@ const PushTroubleshootView = ({ navigation }: IPushTroubleshootViewProps): JSX.E - {/* TODO: This will be used in the near future when the consumption percentage is implemented on the server. {isCommunityEdition ? ( @@ -133,7 +135,7 @@ const PushTroubleshootView = ({ navigation }: IPushTroubleshootViewProps): JSX.E - ) : null} */} + ) : null} {compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '6.6.0') ? ( Date: Fri, 2 Feb 2024 17:31:34 -0300 Subject: [PATCH 2/3] refactor the percentage state --- .../components/ListPercentage.tsx | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/views/PushTroubleshootView/components/ListPercentage.tsx b/app/views/PushTroubleshootView/components/ListPercentage.tsx index e0c23184a..913112b9d 100644 --- a/app/views/PushTroubleshootView/components/ListPercentage.tsx +++ b/app/views/PushTroubleshootView/components/ListPercentage.tsx @@ -12,6 +12,22 @@ const styles = StyleSheet.create({ } }); +type TPercentageState = 'success' | 'warning' | 'danger'; + +const DANGER_VALUE = 90; +const WARNING_MINIMUM_VALUE = 70; +const WARNING_MAXIMUM_VALUE = 90; + +const getPercentageState = (value: number): TPercentageState => { + if (value > WARNING_MINIMUM_VALUE && value < WARNING_MAXIMUM_VALUE) { + return 'warning'; + } + if (value >= DANGER_VALUE) { + return 'danger'; + } + return 'success'; +}; + const ListPercentage = ({ value = 0, title, @@ -24,13 +40,14 @@ const ListPercentage = ({ onPress: () => void; }) => { const { colors } = useTheme(); - const percentage = `${Math.floor(value)}%`; + const percentageState = getPercentageState(value); + let percentageTextColor = colors.statusFontOnSuccess; - if (value > 70 && value < 90) { + if (percentageState === 'warning') { percentageTextColor = colors.statusFontOnWarning; } - if (value >= 90) { + if (percentageState === 'danger') { percentageTextColor = colors.statusFontOnDanger; } From d84df580c5dfab2f0cbd8f11d10bd0b53c2c41d0 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 14 Feb 2024 17:53:36 -0300 Subject: [PATCH 3/3] updated some of the push quota texts --- app/i18n/locales/en.json | 4 ++-- app/i18n/locales/pt-BR.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/i18n/locales/en.json b/app/i18n/locales/en.json index 62fa09911..8cb8bab86 100644 --- a/app/i18n/locales/en.json +++ b/app/i18n/locales/en.json @@ -750,9 +750,9 @@ "Device_notification_settings": "Device notification settings", "Allow_push_notifications_for_rocket_chat": "Allow push notifications for Rocket.Chat", "Go_to_device_settings": "Go to device settings", - "Community_edition_push_quota": "Community Edition push quota", + "Community_edition_push_quota": "Community push quota", "Workspace_consumption": "Workspace consumption", - "Workspace_consumption_description": "There's a set amount of push of allowed push notifications per month", + "Workspace_consumption_description": "There’s a set amount of push notifications per month", "Push_gateway_connection": "Push Gateway Connection", "Custom_push_gateway_connection": "Custom Gateway Connection", "Test_push_notification": "Test push notification", diff --git a/app/i18n/locales/pt-BR.json b/app/i18n/locales/pt-BR.json index 577654cf4..502383b0a 100644 --- a/app/i18n/locales/pt-BR.json +++ b/app/i18n/locales/pt-BR.json @@ -770,7 +770,7 @@ "Go_to_device_settings": "Ir para configurações do dispositivo", "Community_edition_push_quota": "Cota de notificações push Community Edition", "Workspace_consumption": "Consumo do Workspace", - "Workspace_consumption_description": "Existe uma quantidade definida de notificações push permitidas por mês.", + "Workspace_consumption_description": "Existe uma quantidade definida de notificações push por mês", "Push_gateway_connection": "Conexão com o Gateway de Push", "Custom_push_gateway_connection": "Conexão Personalizada com o Gateway", "Test_push_notification": "Testar notificação push",