mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-24 17:51:14 +02:00
* refactor: update test deps * refactor: remove unused ts-expect-error annotations * refactor: add missing arg and return types * refactor: the loading prop is optional * refactor: add missing arg and return types * reafactor: fix value arg type * refactor: fix missing array type * refactor: the parameters field is an array * refactor: use undefined instead of null in state * refactor: add missing params type * refactor: add missing children prop * refactor: add missing array type * refactor: add missing React imports * refactor: use correct IProjectEnvironment type * refactor: type errors as unknown * refactor: the index prop is required * refactor: fix date prop type * refactor: fix tooltip placement prop type * refactor: fix environments state type * refactor: add missing arg types * refactor: add guard for undefined field * refactor: fix ChangePassword prop types * refactor: fix MUI import paths * refactor: add missing arg type * refactor: fix showDialog prop type * refactor: remove unused openUpdateDialog prop * refactor: add missing non-null assertion * refactor: remove unused types prop * refactor: stricten API error handler types * refactor: add missing undefined check * refactor: add missing IProject id field * refactor: fix ConditionallyRender condition prop types * refactor: remove unused args * refactor: add AddVariant prop types * refactor: add types to UIContext * refactor: fix event arg type * refactor: add missing default impressionData field * refactor: fix handleDeleteEnvironment prop args * refactor: fix IFeatureMetrics field requirements * refactor: add missing element types to ConditionallyRender * refactor: remove unused ProjectAccess projectId prop * refactor: add missing undefined check * refactor: fix getCreateTogglePath arg type * refactor: add missing IStrategyPayload import * refactor: remove unused user arg * refactor: add missing event arg type * refactor: add missing style object types * refactor: improve userApiErrors prop type * refactor: the Dialogue onClose prop is optional * refactor: fix the AddonEvents setEventValue prop type
183 lines
7.4 KiB
TypeScript
183 lines
7.4 KiB
TypeScript
import React, { useState } from 'react';
|
|
import ConditionallyRender from '../../../common/ConditionallyRender';
|
|
import {
|
|
Avatar,
|
|
Button,
|
|
FormControl,
|
|
InputLabel,
|
|
Paper,
|
|
Select,
|
|
Typography,
|
|
} from '@material-ui/core';
|
|
import classnames from 'classnames';
|
|
import { useStyles } from './UserProfileContent.styles';
|
|
import { useCommonStyles } from '../../../../common.styles';
|
|
import { Alert } from '@material-ui/lab';
|
|
import EditProfile from '../EditProfile/EditProfile';
|
|
import legacyStyles from '../../user.module.scss';
|
|
import { getBasePath } from '../../../../utils/format-path';
|
|
import useUiConfig from '../../../../hooks/api/getters/useUiConfig/useUiConfig';
|
|
import { IUser } from '../../../../interfaces/user';
|
|
import { ILocationSettings } from '../../../../hooks/useLocationSettings';
|
|
|
|
interface IUserProfileContentProps {
|
|
showProfile: boolean;
|
|
profile: IUser;
|
|
possibleLocales: string[];
|
|
imageUrl: string;
|
|
currentLocale?: string;
|
|
setCurrentLocale: (value: string) => void;
|
|
setLocationSettings: React.Dispatch<
|
|
React.SetStateAction<ILocationSettings>
|
|
>;
|
|
}
|
|
|
|
const UserProfileContent = ({
|
|
showProfile,
|
|
profile,
|
|
possibleLocales,
|
|
imageUrl,
|
|
currentLocale,
|
|
setCurrentLocale,
|
|
setLocationSettings,
|
|
}: IUserProfileContentProps) => {
|
|
const commonStyles = useCommonStyles();
|
|
const { uiConfig } = useUiConfig();
|
|
const [updatedPassword, setUpdatedPassword] = useState(false);
|
|
const [editingProfile, setEditingProfile] = useState(false);
|
|
const styles = useStyles();
|
|
|
|
const profileAvatarClasses = classnames(styles.avatar, {
|
|
[styles.editingAvatar]: editingProfile,
|
|
});
|
|
|
|
const profileEmailClasses = classnames(styles.profileEmail, {
|
|
[styles.editingEmail]: editingProfile,
|
|
});
|
|
|
|
const handleChange = (e: React.ChangeEvent<{ value: unknown }>) => {
|
|
const locale = e.target.value as string;
|
|
setCurrentLocale(locale);
|
|
setLocationSettings({ locale });
|
|
};
|
|
|
|
return (
|
|
<ConditionallyRender
|
|
condition={showProfile}
|
|
show={
|
|
<Paper
|
|
className={classnames(
|
|
styles.profile,
|
|
commonStyles.flexColumn,
|
|
commonStyles.itemsCenter,
|
|
commonStyles.contentSpacingY
|
|
)}
|
|
>
|
|
<Avatar
|
|
alt="user image"
|
|
src={imageUrl}
|
|
className={profileAvatarClasses}
|
|
/>
|
|
<Typography variant="body1" className={profileEmailClasses}>
|
|
{profile?.email}
|
|
</Typography>
|
|
<ConditionallyRender
|
|
condition={updatedPassword}
|
|
show={
|
|
<Alert onClose={() => setUpdatedPassword(false)}>
|
|
Successfully updated password.
|
|
</Alert>
|
|
}
|
|
/>
|
|
<ConditionallyRender
|
|
condition={!editingProfile}
|
|
show={
|
|
<>
|
|
<ConditionallyRender
|
|
condition={!uiConfig.disablePasswordAuth}
|
|
show={
|
|
<Button
|
|
variant="contained"
|
|
onClick={() =>
|
|
setEditingProfile(true)
|
|
}
|
|
>
|
|
Update password
|
|
</Button>
|
|
}
|
|
/>
|
|
<div className={commonStyles.divider} />
|
|
<div className={legacyStyles.showUserSettings}>
|
|
<FormControl
|
|
variant="outlined"
|
|
size="small"
|
|
style={{
|
|
width: '100%',
|
|
minWidth: '120px',
|
|
}}
|
|
>
|
|
<InputLabel
|
|
htmlFor="locale-select"
|
|
style={{ backgroundColor: '#fff' }}
|
|
>
|
|
Date/Time formatting
|
|
</InputLabel>
|
|
<Select
|
|
id="locale-select"
|
|
value={currentLocale || ''}
|
|
native
|
|
onChange={handleChange}
|
|
MenuProps={{
|
|
style: {
|
|
zIndex: 9999,
|
|
},
|
|
}}
|
|
>
|
|
{possibleLocales.map(locale => {
|
|
return (
|
|
<option
|
|
key={locale}
|
|
value={locale}
|
|
>
|
|
{locale}
|
|
</option>
|
|
);
|
|
})}
|
|
</Select>
|
|
</FormControl>
|
|
</div>
|
|
<div className={commonStyles.divider} />
|
|
<a
|
|
className={styles.link}
|
|
href="https://www.getunleash.io/privacy-policy"
|
|
rel="noopener noreferrer"
|
|
target="_blank"
|
|
>
|
|
Privacy policy
|
|
</a>
|
|
<div className={commonStyles.divider} />
|
|
|
|
<Button
|
|
variant="contained"
|
|
color="primary"
|
|
href={`${getBasePath()}/logout`}
|
|
>
|
|
Logout
|
|
</Button>
|
|
</>
|
|
}
|
|
elseShow={
|
|
<EditProfile
|
|
setEditingProfile={setEditingProfile}
|
|
setUpdatedPassword={setUpdatedPassword}
|
|
/>
|
|
}
|
|
/>
|
|
</Paper>
|
|
}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default UserProfileContent;
|