import React, { FunctionComponent } from 'react'; import { formatDistanceToNow } from 'date-fns'; import { localeWithSuffix } from '../../../scripts/dfnshelper'; import globalize from '../../../scripts/globalize'; import cardBuilder from '../../cardbuilder/cardBuilder'; const createLinkElement = ({ user, renderImgUrl }) => ({ __html: ` ${renderImgUrl} ` }); const createButtonElement = () => ({ __html: ` ` }); type IProps = { user?: Record; } const getLastSeenText = (lastActivityDate) => { if (lastActivityDate) { return globalize.translate('LastSeen', formatDistanceToNow(Date.parse(lastActivityDate), localeWithSuffix)); } return ''; }; const UserCardBox: FunctionComponent = ({ user = [] }: IProps) => { let cssClass = 'card squareCard scalableCard squareCard-scalable'; if (user.Policy.IsDisabled) { cssClass += ' grayscale'; } let imgUrl; if (user.PrimaryImageTag) { imgUrl = window.ApiClient.getUserImageUrl(user.Id, { width: 300, tag: user.PrimaryImageTag, type: 'Primary' }); } let imageClass = 'cardImage'; if (user.Policy.IsDisabled) { imageClass += ' disabledUser'; } const lastSeen = getLastSeenText(user.LastActivityDate); const renderImgUrl = imgUrl ? `` : ` `; return ( {user.Name} {lastSeen != '' ? lastSeen : ''} ); }; export default UserCardBox;