You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProfileView.tsx 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { useNavigation } from '@react-navigation/native';
  2. import React, { useCallback, useLayoutEffect, useState } from 'react';
  3. import { useTranslation } from 'react-i18next';
  4. import { ScrollView, Text, View, ViewStyle } from 'react-native';
  5. import { Edge } from 'react-native-safe-area-context';
  6. import { useDispatch, useSelector } from 'react-redux';
  7. import { IReduxState } from '../../../app/types';
  8. import { login, logout } from '../../../authentication/actions.native';
  9. import Avatar from '../../../base/avatar/components/Avatar';
  10. import { IconArrowLeft } from '../../../base/icons/svg';
  11. import JitsiScreen from '../../../base/modal/components/JitsiScreen';
  12. import { getLocalParticipant } from '../../../base/participants/functions';
  13. import { updateSettings } from '../../../base/settings/actions';
  14. import BaseThemeNative from '../../../base/ui/components/BaseTheme.native';
  15. import Button from '../../../base/ui/components/native/Button';
  16. import Input from '../../../base/ui/components/native/Input';
  17. import { BUTTON_TYPES } from '../../../base/ui/constants.native';
  18. import HeaderNavigationButton
  19. from '../../../mobile/navigation/components/HeaderNavigationButton';
  20. import {
  21. goBack,
  22. navigate
  23. } from '../../../mobile/navigation/components/settings/SettingsNavigationContainerRef';
  24. import { screen } from '../../../mobile/navigation/routes';
  25. import FormSection from './FormSection';
  26. import { AVATAR_SIZE } from './constants';
  27. import styles from './styles';
  28. const ProfileView = ({ isInWelcomePage }: {
  29. isInWelcomePage?: boolean;
  30. }) => {
  31. const { t } = useTranslation();
  32. const dispatch = useDispatch();
  33. const navigation = useNavigation();
  34. const { displayName: reduxDisplayName, email: reduxEmail } = useSelector(
  35. (state: IReduxState) => state['features/base/settings']
  36. );
  37. const participant = useSelector((state: IReduxState) => getLocalParticipant(state));
  38. const { locationURL } = useSelector((state: IReduxState) => state['features/base/connection']);
  39. const [ displayName, setDisplayName ] = useState(reduxDisplayName);
  40. const [ email, setEmail ] = useState(reduxEmail);
  41. const { authLogin: isAutenticated } = useSelector((state: IReduxState) => state['features/base/conference']);
  42. const onDisplayNameChanged = useCallback(newDisplayName => {
  43. setDisplayName(newDisplayName);
  44. }, [ setDisplayName ]);
  45. const onEmailChanged = useCallback(newEmail => {
  46. setEmail(newEmail);
  47. }, [ setEmail ]);
  48. const onApplySettings = useCallback(() => {
  49. dispatch(updateSettings({
  50. displayName,
  51. email
  52. }));
  53. navigate(screen.settings.main);
  54. },
  55. [ dispatch, updateSettings, email, displayName ]);
  56. const onLogin = useCallback(() => {
  57. dispatch(login());
  58. }, [ dispatch ]);
  59. const onLogout = useCallback(() => {
  60. dispatch(logout());
  61. }, [ dispatch ]);
  62. const headerLeft = () => (
  63. <HeaderNavigationButton
  64. color = { BaseThemeNative.palette.link01 }
  65. onPress = { goBack }
  66. src = { IconArrowLeft }
  67. style = { styles.backBtn }
  68. twoActions = { true } />
  69. );
  70. const headerRight = () => {
  71. if (isAutenticated) {
  72. return (
  73. <HeaderNavigationButton
  74. label = { t('toolbar.logout') }
  75. onPress = { onLogout }
  76. style = { styles.logBtn }
  77. twoActions = { true } />
  78. );
  79. }
  80. return (
  81. <HeaderNavigationButton
  82. label = { t('toolbar.login') }
  83. onPress = { onLogin }
  84. style = { styles.logBtn }
  85. twoActions = { true } />
  86. );
  87. };
  88. useLayoutEffect(() => {
  89. navigation.setOptions({
  90. headerLeft,
  91. headerRight: !isInWelcomePage
  92. && !locationURL?.hostname?.includes('8x8.vc')
  93. && headerRight
  94. });
  95. }, [ navigation ]);
  96. return (
  97. <JitsiScreen
  98. disableForcedKeyboardDismiss = { true }
  99. // @ts-ignore
  100. safeAreaInsets = { [ !isInWelcomePage && 'bottom', 'left', 'right' ].filter(Boolean) as Edge[] }
  101. style = { styles.settingsViewContainer }>
  102. <ScrollView
  103. bounces = { isInWelcomePage }
  104. contentContainerStyle = { styles.profileView as ViewStyle }>
  105. <View>
  106. <View style = { styles.avatarContainer as ViewStyle }>
  107. <Avatar
  108. participantId = { participant?.id }
  109. size = { AVATAR_SIZE } />
  110. </View>
  111. <FormSection>
  112. <Input
  113. customStyles = {{ container: styles.customContainer }}
  114. label = { t('settingsView.displayName') }
  115. onChange = { onDisplayNameChanged }
  116. placeholder = { t('settingsView.displayNamePlaceholderText') }
  117. textContentType = { 'name' } // iOS only
  118. value = { displayName ?? '' } />
  119. <Input
  120. autoCapitalize = 'none'
  121. customStyles = {{ container: styles.customContainer }}
  122. keyboardType = { 'email-address' }
  123. label = { t('settingsView.email') }
  124. onChange = { onEmailChanged }
  125. placeholder = { t('settingsView.emailPlaceholderText') }
  126. textContentType = { 'emailAddress' } // iOS only
  127. value = { email ?? '' } />
  128. <Text style = { styles.gavatarMessageContainer }>
  129. { t('settingsView.gavatarMessage') }
  130. </Text>
  131. </FormSection>
  132. </View>
  133. <Button
  134. accessibilityLabel = { t('settingsView.apply') }
  135. labelKey = { 'settingsView.apply' }
  136. onClick = { onApplySettings }
  137. style = { styles.applyProfileSettingsButton }
  138. type = { BUTTON_TYPES.PRIMARY } />
  139. </ScrollView>
  140. </JitsiScreen>
  141. );
  142. };
  143. export default ProfileView;