mattermost-mobile/app/screens/edit_profile/components/email_field.tsx
Guillermo Vayá 0addf49021
[MM-62701] [MM-62176]Edit custom profile attributes in user profile (#8557)
* feat: Add support for custom profile attributes in edit profile form

feat: Add support for custom profile attributes in edit profile

refactor: Normalize whitespace in CustomAttribute type definition

fix: Resolve type mismatch for customAttributes in UserInfo interface

test: Add test for udpateCustomProfileAttributeValues method

fix typing, submit changes to server

missing files

test: Add tests for CustomProfileField component

fix naming

fix imports

fix

feat: Add field_refs hook for managing field references

feat: Make `setRef` ref parameter optional with default no-op implementation

refactor: Replace CustomProfileField with useFieldRefs for profile form

refactor: Optimize edit profile screen imports and custom attributes handling

refactor: Move custom attributes logic to remote actions in user.ts

address PR reviews

test: Add tests for custom attributes in edit profile

test: Add tests for EditProfile component with custom attributes

fix: Add UserModel type assertion to currentUser in edit profile tests

test: Add tests for ProfileForm custom attributes functionality

test: Add comprehensive tests for useFieldRefs hook

test: Add tests for fetchCustomAttributes and updateCustomAttributes

add tests

remove unneeded files

review changes

remove counter from hook

remove package.resolved

create interface for reuse of record

* fix signature type
2025-02-19 15:51:59 +01:00

107 lines
3 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {type ComponentProps} from 'react';
import {useIntl} from 'react-intl';
import {Text, View} from 'react-native';
import FloatingTextInput from '@components/floating_text_input_label';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
import {typography} from '@utils/typography';
import Field from './field';
const services: Record<string, string> = {
gitlab: 'GitLab',
google: 'Google Apps',
office365: 'Entra ID',
ldap: 'AD/LDAP',
saml: 'SAML',
};
const getStyleSheet = makeStyleSheetFromTheme((theme) => {
return {
container: {
marginTop: 2,
},
text: {
...typography('Body', 75),
color: changeOpacity(theme.centerChannelColor, 0.5),
},
};
});
type EmailSettingsProps = {
authService: string;
email: string;
fieldRef: ComponentProps<typeof FloatingTextInput>['ref'];
onChange: (fieldKey: string, value: string) => void;
onFocusNextField: (fieldKey: string) => void;
isDisabled: boolean;
label: string;
theme: Theme;
isTablet: boolean;
}
const EmailField = ({
authService,
email,
fieldRef,
onChange,
onFocusNextField,
isDisabled,
label,
theme,
isTablet,
}: EmailSettingsProps) => {
const intl = useIntl();
const service = services[authService];
const style = getStyleSheet(theme);
let fieldDescription: string;
if (service) {
fieldDescription = intl.formatMessage({
id: 'user.edit_profile.email.auth_service',
defaultMessage: 'Login occurs through {service}. Email cannot be updated. Email address used for notifications is {email}.'}, {email, service});
} else {
fieldDescription = intl.formatMessage({
id: 'user.edit_profile.email.web_client',
defaultMessage: 'Email must be updated using a web client or desktop application.'}, {email, service});
}
const descContainer = [style.container, {paddingHorizontal: isTablet ? 42 : 20}];
return (
<>
<Field
blurOnSubmit={false}
enablesReturnKeyAutomatically={true}
fieldKey='email'
fieldRef={fieldRef}
isDisabled={isDisabled}
keyboardType='email-address'
label={label}
onFocusNextField={onFocusNextField}
onTextChange={onChange}
returnKeyType='next'
testID='edit_profile_form.email'
value={email}
/>
<View
style={descContainer}
>
<Text
style={style.text}
testID='edit_profile_form.email.input.description'
>
{fieldDescription}
</Text>
</View>
</>
);
};
export default EmailField;