Disable profile controls if the HS doesn't allow them to be set (#12652)
* Disable profile controls if the HS doesn't allow them to be set Also updates to the js-sdk interface changes in https://github.com/matrix-org/matrix-js-sdk/pull/4246 * Remove unnecessary await * Pass disabled prop to accessiblebutton in avatarsetting * Use getCapabilities in case there are no cached capabilities * Fix test * Go back to just using getCapabilities Rather than change the other places
This commit is contained in:
parent
922676a7cc
commit
510fb1ba2f
6 changed files with 42 additions and 7 deletions
|
@ -55,10 +55,17 @@ const UsernameBox: React.FC<UsernameBoxProps> = ({ username }) => {
|
|||
);
|
||||
};
|
||||
|
||||
interface UserProfileSettingsProps {
|
||||
// Whether the homeserver allows the user to set their display name.
|
||||
canSetDisplayName: boolean;
|
||||
// Whether the homeserver allows the user to set their avatar.
|
||||
canSetAvatar: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* A group of settings views to allow the user to set their profile information.
|
||||
*/
|
||||
const UserProfileSettings: React.FC = () => {
|
||||
const UserProfileSettings: React.FC<UserProfileSettingsProps> = ({ canSetDisplayName, canSetAvatar }) => {
|
||||
const [avatarURL, setAvatarURL] = useState(OwnProfileStore.instance.avatarMxc);
|
||||
const [displayName, setDisplayName] = useState(OwnProfileStore.instance.displayName ?? "");
|
||||
const [initialDisplayName, setInitialDisplayName] = useState(OwnProfileStore.instance.displayName ?? "");
|
||||
|
@ -143,10 +150,16 @@ const UserProfileSettings: React.FC = () => {
|
|||
[client],
|
||||
);
|
||||
|
||||
const someFieldsDisabled = !canSetDisplayName || !canSetAvatar;
|
||||
|
||||
return (
|
||||
<div className="mx_UserProfileSettings">
|
||||
<h2>{_t("common|profile")}</h2>
|
||||
<div>{_t("settings|general|profile_subtitle")}</div>
|
||||
<div>
|
||||
{someFieldsDisabled
|
||||
? _t("settings|general|profile_subtitle_oidc")
|
||||
: _t("settings|general|profile_subtitle")}
|
||||
</div>
|
||||
<div className="mx_UserProfileSettings_profile">
|
||||
<AvatarSetting
|
||||
avatar={avatarURL ?? undefined}
|
||||
|
@ -155,6 +168,7 @@ const UserProfileSettings: React.FC = () => {
|
|||
removeAvatar={avatarURL ? onAvatarRemove : undefined}
|
||||
placeholderName={displayName}
|
||||
placeholderId={client.getUserId() ?? ""}
|
||||
disabled={!canSetAvatar}
|
||||
/>
|
||||
<EditInPlace
|
||||
className="mx_UserProfileSettings_profile_displayName"
|
||||
|
@ -169,6 +183,7 @@ const UserProfileSettings: React.FC = () => {
|
|||
onCancel={onDisplayNameCancel}
|
||||
onSave={onDisplayNameSave}
|
||||
error={displayNameError ? _t("settings|general|display_name_error") : undefined}
|
||||
disabled={!canSetDisplayName}
|
||||
/>
|
||||
</div>
|
||||
{avatarError && (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue