Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 80 additions & 23 deletions apps/meteor/client/views/account/profile/AccountProfileForm.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import type { IUser } from '@rocket.chat/core-typings';
import { css } from '@rocket.chat/css-in-js';
import {
Box,
Button,
Field,
FieldError,
FieldGroup,
FieldHint,
FieldLabel,
FieldRow,
FieldError,
FieldHint,
TextInput,
TextAreaInput,
Box,
Icon,
Button,
TextAreaInput,
TextInput,
} from '@rocket.chat/fuselage';
import { CustomFieldsForm } from '@rocket.chat/ui-client';
import {
useAccountsCustomFields,
useEndpoint,
useLayout,
useMethod,
useToastMessageDispatch,
useTranslation,
useEndpoint,
useUser,
useMethod,
} from '@rocket.chat/ui-contexts';
import { useMutation } from '@tanstack/react-query';
import type { AllHTMLAttributes, ReactElement } from 'react';
import { useId, useCallback } from 'react';
import { useCallback, useId } from 'react';
import { Controller, useFormContext } from 'react-hook-form';

import type { AccountProfileFormValues } from './getProfileInitialValues';
Expand All @@ -33,12 +35,20 @@ import { getUserEmailAddress } from '../../../../lib/getUserEmailAddress';
import UserStatusMenu from '../../../components/UserStatusMenu';
import UserAvatarEditor from '../../../components/avatar/UserAvatarEditor';
import { useUpdateAvatar } from '../../../hooks/useUpdateAvatar';
import { USER_STATUS_TEXT_MAX_LENGTH, BIO_TEXT_MAX_LENGTH } from '../../../lib/constants';
import { BIO_TEXT_MAX_LENGTH, USER_STATUS_TEXT_MAX_LENGTH } from '../../../lib/constants';

function getAriaDescribedByList(data: { include: boolean; name: string }[]) {
return data
.filter((item) => item.include)
.map((item) => item.name)
.join(' ');
}

const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactElement => {
const t = useTranslation();
const user = useUser();
const dispatchToastMessage = useToastMessageDispatch();
const { isMobile } = useLayout();

const checkUsernameAvailability = useEndpoint('GET', '/v1/users.checkUsernameAvailability');
const sendConfirmationEmail = useEndpoint('POST', '/v1/users.sendConfirmationEmail');
Expand Down Expand Up @@ -157,8 +167,18 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
)}
/>
</Field>
<Box display='flex' flexDirection='row' justifyContent='space-between'>
<Field mie={8} flexShrink={1}>
<Box
display='flex'
flexDirection={isMobile ? 'column' : 'row'}
alignItems='stretch'
justifyContent='space-between'
className={[
css`
gap: 16px;
`,
]}
>
<Field flexShrink={1}>
<FieldLabel required htmlFor={nameId}>
{t('Name')}
</FieldLabel>
Expand All @@ -177,7 +197,13 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
disabled={!allowRealNameChange}
aria-required='true'
aria-invalid={errors.username ? 'true' : 'false'}
aria-describedby={`${nameId}-error ${nameId}-hint`}
aria-describedby={getAriaDescribedByList([
{
include: !!errors.name,
name: `${nameId}-error`,
},
{ include: !allowRealNameChange, name: `${nameId}-hint` },
])}
/>
)}
/>
Expand All @@ -189,7 +215,7 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
)}
{!allowRealNameChange && <FieldHint id={`${nameId}-hint`}>{t('RealName_Change_Disabled')}</FieldHint>}
</Field>
<Field mis={8} flexShrink={1}>
<Field flexShrink={1}>
<FieldLabel required htmlFor={usernameId}>
{t('Username')}
</FieldLabel>
Expand All @@ -210,7 +236,13 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
addon={<Icon name='at' size='x20' />}
aria-required='true'
aria-invalid={errors.username ? 'true' : 'false'}
aria-describedby={`${usernameId}-error ${usernameId}-hint`}
aria-describedby={getAriaDescribedByList([
{
include: !!errors?.username,
name: `${usernameId}-error`,
},
{ include: !canChangeUsername, name: `${usernameId}-hint` },
])}
/>
)}
/>
Expand All @@ -229,7 +261,12 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
<Controller
control={control}
name='statusText'
rules={{ maxLength: { value: USER_STATUS_TEXT_MAX_LENGTH, message: t('Max_length_is', USER_STATUS_TEXT_MAX_LENGTH) } }}
rules={{
maxLength: {
value: USER_STATUS_TEXT_MAX_LENGTH,
message: t('Max_length_is', USER_STATUS_TEXT_MAX_LENGTH),
},
}}
render={({ field }) => (
<TextInput
{...field}
Expand All @@ -239,7 +276,13 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
flexGrow={1}
placeholder={t('StatusMessage_Placeholder')}
aria-invalid={errors.statusText ? 'true' : 'false'}
aria-describedby={`${statusTextId}-error ${statusTextId}-hint`}
aria-describedby={getAriaDescribedByList([
{
include: !!errors?.statusText,
name: `${statusTextId}-error`,
},
{ include: !allowUserStatusMessageChange, name: `${statusTextId}-hint` },
])}
addon={
<Controller
control={control}
Expand All @@ -254,11 +297,11 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
/>
</FieldRow>
{errors?.statusText && (
<FieldError aria-live='assertive' id={`${statusTextId}-error`}>
<FieldError aria-live='assertive' id={`${statusTextId} - error`}>
{errors?.statusText.message}
</FieldError>
)}
{!allowUserStatusMessageChange && <FieldHint id={`${statusTextId}-hint`}>{t('StatusMessage_Change_Disabled')}</FieldHint>}
{!allowUserStatusMessageChange && <FieldHint id={`${statusTextId} - hint`}>{t('StatusMessage_Change_Disabled')}</FieldHint>}
</Field>
<Field>
<FieldLabel htmlFor={nicknameId}>{t('Nickname')}</FieldLabel>
Expand Down Expand Up @@ -288,7 +331,7 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
flexGrow={1}
addon={<Icon name='edit' size='x20' alignSelf='center' />}
aria-invalid={errors.statusText ? 'true' : 'false'}
aria-describedby={`${bioId}-error`}
aria-describedby={getAriaDescribedByList([{ include: !!errors?.bio, name: `${bioId}-error` }])}
/>
)}
/>
Expand All @@ -303,7 +346,15 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
<FieldLabel required htmlFor={emailId}>
{t('Email')}
</FieldLabel>
<FieldRow display='flex' flexDirection='row' justifyContent='space-between'>
<FieldRow
display='flex'
flexDirection={isMobile ? 'column' : 'row'}
alignItems='stretch'
justifyContent='space-between'
className={css`
gap: 8px;
`}
>
<Controller
control={control}
name='email'
Expand All @@ -321,12 +372,18 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
disabled={!allowEmailChange}
aria-required='true'
aria-invalid={errors.email ? 'true' : 'false'}
aria-describedby={`${emailId}-error ${emailId}-hint`}
aria-describedby={getAriaDescribedByList([
{
include: !!errors.email,
name: `${emailId}-error`,
},
{ include: !allowEmailChange, name: `${emailId}-hint` },
])}
/>
)}
/>
{!isUserVerified && (
<Button disabled={email !== previousEmail} onClick={handleSendConfirmationEmail} mis={24}>
<Button disabled={email !== previousEmail} onClick={handleSendConfirmationEmail}>
{t('Resend_verification_email')}
</Button>
)}
Expand Down