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 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import React, { useCallback, useState } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { ScrollView, Text, View, ViewStyle } from 'react-native';
  4. import { useDispatch, useSelector } from 'react-redux';
  5. import { IReduxState } from '../../../app/types';
  6. import Avatar from '../../../base/avatar/components/Avatar';
  7. import JitsiScreen from '../../../base/modal/components/JitsiScreen';
  8. import { getLocalParticipant } from '../../../base/participants/functions';
  9. import { updateSettings } from '../../../base/settings/actions';
  10. import Button from '../../../base/ui/components/native/Button';
  11. import Input from '../../../base/ui/components/native/Input';
  12. import { BUTTON_TYPES } from '../../../base/ui/constants.native';
  13. import { navigate } from '../../../mobile/navigation/components/settings/SettingsNavigationContainerRef';
  14. import { screen } from '../../../mobile/navigation/routes';
  15. import FormSection from './FormSection';
  16. import { AVATAR_SIZE } from './constants';
  17. import styles from './styles';
  18. const ProfileView = ({ isInWelcomePage }: { isInWelcomePage?: boolean; }) => {
  19. const { t } = useTranslation();
  20. const dispatch = useDispatch();
  21. const { displayName: reduxDisplayName, email: reduxEmail } = useSelector(
  22. (state: IReduxState) => state['features/base/settings']
  23. );
  24. const participant = useSelector((state: IReduxState) => getLocalParticipant(state));
  25. const [ displayName, setDisplayName ] = useState(reduxDisplayName);
  26. const [ email, setEmail ] = useState(reduxEmail);
  27. const onDisplayNameChanged = useCallback(newDisplayName => {
  28. setDisplayName(newDisplayName);
  29. }, [ setDisplayName ]);
  30. const onEmailChanged = useCallback(newEmail => {
  31. setEmail(newEmail);
  32. }, [ setEmail ]);
  33. const onApplySettings = useCallback(() => {
  34. dispatch(updateSettings({
  35. displayName,
  36. email
  37. }));
  38. navigate(screen.settings.main);
  39. },
  40. [ dispatch, updateSettings, email, displayName ]);
  41. return (
  42. <JitsiScreen
  43. disableForcedKeyboardDismiss = { true }
  44. // @ts-ignore
  45. safeAreaInsets = { [ !isInWelcomePage && 'bottom', 'left', 'right' ].filter(Boolean) }
  46. style = { styles.settingsViewContainer }>
  47. <ScrollView
  48. bounces = { isInWelcomePage }
  49. contentContainerStyle = { styles.profileView as ViewStyle }>
  50. <View>
  51. <View style = { styles.avatarContainer as ViewStyle }>
  52. <Avatar
  53. participantId = { participant?.id }
  54. size = { AVATAR_SIZE } />
  55. </View>
  56. <FormSection>
  57. <Input
  58. customStyles = {{ container: styles.customContainer }}
  59. label = { t('settingsView.displayName') }
  60. onChange = { onDisplayNameChanged }
  61. placeholder = { t('settingsView.displayNamePlaceholderText') }
  62. textContentType = { 'name' } // iOS only
  63. value = { displayName ?? '' } />
  64. <Input
  65. autoCapitalize = 'none'
  66. customStyles = {{ container: styles.customContainer }}
  67. keyboardType = { 'email-address' }
  68. label = { t('settingsView.email') }
  69. onChange = { onEmailChanged }
  70. placeholder = { t('settingsView.emailPlaceholderText') }
  71. textContentType = { 'emailAddress' } // iOS only
  72. value = { email ?? '' } />
  73. <Text style = { styles.gavatarMessageContainer }>
  74. { t('settingsView.gavatarMessage') }
  75. </Text>
  76. </FormSection>
  77. </View>
  78. <Button
  79. accessibilityLabel = { t('settingsView.apply') }
  80. labelKey = { 'settingsView.apply' }
  81. onClick = { onApplySettings }
  82. style = { styles.applyProfileSettingsButton }
  83. type = { BUTTON_TYPES.PRIMARY } />
  84. </ScrollView>
  85. </JitsiScreen>
  86. );
  87. };
  88. export default ProfileView;