mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-03 04:10:43 +00:00
adds avatars constants module
This commit is contained in:
parent
8de05625a5
commit
6048d340b7
33
wherehows-web/app/constants/avatars/avatars.ts
Normal file
33
wherehows-web/app/constants/avatars/avatars.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { IAvatar } from 'wherehows-web/typings/app/avatars';
|
||||
import { avatar } from 'wherehows-web/constants/application';
|
||||
import { pick } from 'lodash';
|
||||
|
||||
/**
|
||||
* Defines a partial interface for an object that can be narrowed into an avatar
|
||||
*/
|
||||
type PartAvatar = Partial<IAvatar>;
|
||||
|
||||
const { url: avatarUrl } = avatar;
|
||||
|
||||
/**
|
||||
* Default image url if an avatar url cannot be determined
|
||||
* @type {string}
|
||||
*/
|
||||
const defaultAvatarImage = '/assets/assets/images/default_avatar.png';
|
||||
|
||||
/**
|
||||
* Takes a PartAvatar object and build an object confirming to an IAvatar
|
||||
* @param {PartAvatar} object
|
||||
* @return {IAvatar}
|
||||
*/
|
||||
const getAvatarProps = (object: PartAvatar): IAvatar => {
|
||||
const props = pick(object, ['email', 'userName', 'name']);
|
||||
const imageUrl = props.userName ? avatarUrl.replace('[username]', props.userName) : defaultAvatarImage;
|
||||
|
||||
return {
|
||||
imageUrl,
|
||||
...props
|
||||
};
|
||||
};
|
||||
|
||||
export { getAvatarProps };
|
||||
Loading…
x
Reference in New Issue
Block a user