Rocket.Chat.ReactNative/app/views/PushTroubleshootView/components/PushGatewayConnection.tsx

66 lines
2.4 KiB
TypeScript
Raw Normal View History

feat: mobile troubleshoot notifications (#5330) * feat: troubleshoot notification (#5198) * navigation done * create the icon inside roomslistview, navigation to push troubleshot and layout push troubleshoot * custom header * fix the rooms list view header icon * layout done * update the pt-br i18n * tweak on colors * feat: create notification in room view (#5250) * button and simple navigation done, missing master detail * navigation * add withTheme and colors to rightuttons * fix e2e test * feat: add troubleshooting to notifications pages (#5276) * feat: add troubleshooting to notifications pages * fix e2e test * feat: device notification settings (#5277) * iOS go to device notification setting to change the configuration * go to notification settings with android * add notifee * add the reducer and action * saga request done * add the setInAlert action * tweak at name and add focus to dispatch the request * use the foreground inside pushTroubleShoot to request the notification and fix the icon color * add the request at roomslistview didmount * remove the notification modulo from android * add patch * minor tweak * feat: test push notification (#5329) * feat: test push notification * restApi and definition * push.info and change properly the troubleshootingNotification * use the finally at try/catch * minor tweak * alert and push.info just for 6.6 * fix the react-native.config * minor tweaks * minor tweak * push.test as rest api * change the name from inAlertNotification to highlightTroubleshooting * feat: push quota * refactor the percentage state * removed the push quota feature * minor tweaks * update the link to push notification * the notification icon in the room header will appear if notifications are disabled or highlight troubleshoot is true * remove push quota texts * updated some of the push quota texts * chore: rename highlightTroubleshooting * chore: better prop naming * wip * chore: fix function name * chore: fix colors * fix: copy * chore: 💅 * chore: use fork * chore: naming * chore: fix init * chore: naming * chore: naming * Comment CE code * Use put on troubleshooting saga * Add db column * fix: check notification payload * action: organized translations * fix: push init --------- Co-authored-by: GleidsonDaniel <gleidson10daniel@hotmail.com> Co-authored-by: Diego Mello <diegolmello@gmail.com> Co-authored-by: GleidsonDaniel <GleidsonDaniel@users.noreply.github.com>
2024-03-04 11:27:24 +00:00
import React, { useState } from 'react';
import { Alert } from 'react-native';
import * as List from '../../../containers/List';
import i18n from '../../../i18n';
import { useAppSelector, usePermissions } from '../../../lib/hooks';
import { compareServerVersion, showErrorAlertWithEMessage } from '../../../lib/methods/helpers';
import { Services } from '../../../lib/services';
import { useTheme } from '../../../theme';
import CustomListSection from './CustomListSection';
export default function PushGatewayConnection(): React.ReactElement | null {
const [loading, setLoading] = useState(false);
const { colors } = useTheme();
const [testPushNotificationsPermission] = usePermissions(['test-push-notifications']);
const { defaultPushGateway, pushGatewayEnabled, serverVersion } = useAppSelector(state => ({
pushGatewayEnabled: state.troubleshootingNotification.pushGatewayEnabled,
defaultPushGateway: state.troubleshootingNotification.defaultPushGateway,
foreground: state.app.foreground,
serverVersion: state.server.version
}));
if (!compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '6.6.0')) return null;
const handleTestPushNotification = async () => {
setLoading(true);
try {
const result = await Services.pushTest();
if (result.success) {
Alert.alert(i18n.t('Test_push_notification'), i18n.t('Your_push_was_sent_to_s_devices', { s: result.tokensCount }));
}
} catch (error: any) {
showErrorAlertWithEMessage(error, i18n.t('Test_push_notification'));
}
setLoading(false);
};
let infoColor = 'Push_gateway_not_connected_description';
let statusColor = colors.userPresenceBusy;
if (pushGatewayEnabled) {
statusColor = colors.userPresenceOnline;
infoColor = 'Push_gateway_connected_description';
}
if (pushGatewayEnabled && !defaultPushGateway) {
statusColor = colors.badgeBackgroundLevel3;
infoColor = 'Custom_push_gateway_connected_description';
}
return (
<CustomListSection
title={!defaultPushGateway ? 'Custom_push_gateway_connection' : 'Push_gateway_connection'}
statusColor={statusColor}
>
<List.Separator />
<List.Item
title='Test_push_notification'
disabled={!pushGatewayEnabled || !testPushNotificationsPermission || loading}
onPress={handleTestPushNotification}
testID='push-troubleshoot-view-push-gateway-connection'
/>
<List.Separator />
<List.Info info={infoColor} />
</CustomListSection>
);
}