Hello,
@SocialPlus_Support Yes, I did make some changes to the UI Kit as I removed the display name field from the UserProfileForm
component in the UI Kit. This field is now in my React app (which uses the UI Kit) as there is some additional validation I needed to do around the format of the display name, which wasn’t possible to do within the UI Kit.
This is what the UserProfileForm
component looks like now in the UI Kit. I simply removed the displayName
from the form props and added a message redirecting the user to a different page (within my app) if they want to change the display name.
import {
AboutTextarea,
Counter,
ErrorMessage,
Field,
Form,
FormBlockBody,
FormBlockContainer,
FormBlockHeader,
FormBody,
Label,
LabelCounterWrapper,
} from '~/social/components/CommunityForm/styles';
import { Controller, useForm } from 'react-hook-form';
import { FormattedMessage, useIntl } from 'react-intl';
import React, { memo } from 'react';
import AvatarUploader from '~/social/components/CommunityForm/AvatarUploader';
import { PrimaryButton } from '~/core/components/Button';
import styled from 'styled-components';
const ButtonContainer = styled.div`
margin-top: 16px;
`;
const MyAppText = styled.p`
margin: 0;
`;
const MyAppLink = styled.a`
color: ${({ theme }) => theme.palette.primary.main};
text-decoration: none;
&:hover {
text-decoration: underline;
}
`;
interface FormBlockProps {
title: React.ReactNode;
children: React.ReactNode;
}
const FormBlock = ({ title, children }: FormBlockProps) => (
<FormBlockContainer>
<FormBlockHeader>{title}</FormBlockHeader>
<FormBlockBody>{children}</FormBlockBody>
</FormBlockContainer>
);
interface UserProfileFormProps {
user: Amity.User;
onSubmit: (
data: Partial<Pick<Amity.User, 'displayName'>> &
Pick<Amity.User, 'description' | 'avatarFileId'>,
) => Promise<void>;
className?: string;
}
const UserProfileForm = ({ user, onSubmit, className }: UserProfileFormProps) => {
const { formatMessage } = useIntl();
const {
register,
handleSubmit,
formState: { errors },
watch,
control,
} = useForm({
defaultValues: {
description: user.description ?? '',
avatarFileId: user.avatarFileId ?? undefined,
},
});
const description = watch('description');
return (
<Form
className={className}
onSubmit={handleSubmit((data) => {
onSubmit(data);
})}
>
<FormBody>
<FormBlock title={<FormattedMessage id="UserProfileForm.title" />}>
<Controller
name="avatarFileId"
render={({ field: { ref, ...rest } }) => (
<AvatarUploader {...rest} data-qa-anchor="user-profile-form-avatar-uploader" />
)}
control={control}
/>
<Field>
<LabelCounterWrapper>
<Label htmlFor="displayName">
<FormattedMessage id="UserProfileForm.displayname" />
</Label>
</LabelCounterWrapper>
<MyAppText>
<FormattedMessage id="UserProfileForm.goToMyAppMessageStart" />{' '}
<MyAppLink href="account-settings">
<FormattedMessage id="UserProfileForm.goToMyAppLink" />
</MyAppLink>
{''}.
</MyAppText>
</Field>
<Field error={errors.description}>
<LabelCounterWrapper>
<Label htmlFor="description">
<FormattedMessage id="UserProfileForm.about" />
</Label>
<Counter>{description?.length || 0}/180</Counter>
</LabelCounterWrapper>
<AboutTextarea
{...register('description')}
data-qa-anchor="user-profile-form-description-textarea"
placeholder={formatMessage({ id: 'UserProfileForm.requiredDescription' })}
maxLength={180}
/>
<ErrorMessage errors={errors} name="description" />
</Field>
<ButtonContainer>
<PrimaryButton data-qa-anchor="user-profile-form-save-button" type="submit">
<FormattedMessage id="save" />
</PrimaryButton>
</ButtonContainer>
</FormBlock>
</FormBody>
</Form>
);
};
export default memo(UserProfileForm);
In my app, I have a form field for the display name. When the form gets submitted, I call the PUT /api/v3/users
endpoint of the Amity API (via a BFF), with the new display name value.
My React app then loads the Amity UI Kit like this (it uses secure auth mode):
if (userId && apiKey && communityDisplayName) {
return (
<AmityUiKitProvider
key={userId}
apiKey={apiKey}
apiEndpoint={{
http: 'https://api.eu.amity.co',
}}
getAuthToken={requestAccessToken}
userId={userId}
displayName={communityDisplayName}
apiRegion='EU'
socialCommunityCreationButtonVisible={false}
>
<AmityUiKitSocial />
</AmityUiKitProvider>
);
}
The value of communityDisplayName
is definitely set to the new display name, and the call to the Amity API definitely succeeded as I can see that the user details have been updated in the portal. However, on the UI (e.g. their Amity profile page), the user sees the previous display name until they reload the Amity community page.
Is this due to some kind of caching?
Thanks for your help.