Hide avatar input for unregistered users

This commit is contained in:
Robert Long 2021-12-17 11:40:13 -08:00
parent d493b95782
commit 6ea821a36e
3 changed files with 35 additions and 8 deletions

View file

@ -724,13 +724,19 @@ export function useProfile(client) {
try { try {
await client.setDisplayName(displayName); await client.setDisplayName(displayName);
const url = await client.uploadContent(avatar); let mxcAvatarUrl;
await client.setAvatarUrl(url);
if (avatar) {
mxcAvatarUrl = await client.uploadContent(avatar);
await client.setAvatarUrl(mxcAvatarUrl);
}
setState((prev) => ({ setState((prev) => ({
...prev, ...prev,
displayName, displayName,
avatarUrl: getAvatarUrl(client, url), avatarUrl: mxcAvatarUrl
? getAvatarUrl(client, mxcAvatarUrl)
: prev.avatarUrl,
loading: false, loading: false,
success: true, success: true,
})); }));

View file

@ -4,7 +4,13 @@ import { useProfile } from "./ConferenceCallManagerHooks";
import { FieldRow, InputField, ErrorMessage } from "./Input"; import { FieldRow, InputField, ErrorMessage } from "./Input";
import { Modal, ModalContent } from "./Modal"; import { Modal, ModalContent } from "./Modal";
export function ProfileModal({ client, ...rest }) { export function ProfileModal({
client,
isAuthenticated,
isPasswordlessUser,
isGuest,
...rest
}) {
const { onClose } = rest; const { onClose } = rest;
const { const {
success, success,
@ -60,9 +66,16 @@ export function ProfileModal({ client, ...rest }) {
onChange={onChangeDisplayName} onChange={onChangeDisplayName}
/> />
</FieldRow> </FieldRow>
<FieldRow> {isAuthenticated && !isGuest && !isPasswordlessUser && (
<InputField type="file" id="avatar" name="avatar" label="Avatar" /> <FieldRow>
</FieldRow> <InputField
type="file"
id="avatar"
name="avatar"
label="Avatar"
/>
</FieldRow>
)}
{error && ( {error && (
<FieldRow> <FieldRow>
<ErrorMessage>{error.message}</ErrorMessage> <ErrorMessage>{error.message}</ErrorMessage>

View file

@ -108,7 +108,15 @@ export function UserMenu({ disableLogout }) {
</Menu> </Menu>
)} )}
</PopoverMenuTrigger> </PopoverMenuTrigger>
{modalState.isOpen && <ProfileModal client={client} {...modalProps} />} {modalState.isOpen && (
<ProfileModal
client={client}
isAuthenticated={isAuthenticated}
isGuest={isGuest}
isPasswordlessUser={isPasswordlessUser}
{...modalProps}
/>
)}
</> </>
); );
} }