Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ProfileView.tsx 6.0KB

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