mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
added user description for deactivated units
This commit is contained in:
parent
f19fed1c5a
commit
07852df0dc
3 changed files with 27 additions and 6 deletions
|
@ -3,24 +3,24 @@ import { INode } from '~/redux/types';
|
|||
import styles from './styles.module.scss';
|
||||
import { Avatar } from '~/components/common/Avatar';
|
||||
import { openUserProfile } from '~/utils/user';
|
||||
import { useRandomPhrase } from '~/constants/phrases';
|
||||
import { useUserDescription } from '~/utils/hooks/user/useUserDescription';
|
||||
|
||||
interface Props {
|
||||
node?: INode;
|
||||
}
|
||||
|
||||
const NodeAuthorBlock: FC<Props> = ({ node }) => {
|
||||
const randomPhrase = useRandomPhrase('USER_DESCRIPTION');
|
||||
|
||||
const onOpenProfile = useCallback(() => openUserProfile(node?.user?.username), [
|
||||
node?.user?.username,
|
||||
]);
|
||||
|
||||
const description = useUserDescription(node?.user);
|
||||
|
||||
if (!node?.user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { fullname, username, description, photo } = node.user;
|
||||
const { fullname, username, photo } = node.user;
|
||||
|
||||
return (
|
||||
<div className={styles.block} onClick={onOpenProfile}>
|
||||
|
@ -28,8 +28,7 @@ const NodeAuthorBlock: FC<Props> = ({ node }) => {
|
|||
|
||||
<div className={styles.info}>
|
||||
<div className={styles.username}>{fullname || username}</div>
|
||||
|
||||
<div className={styles.description}>{description || randomPhrase}</div>
|
||||
<div className={styles.description}>{description}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
1
src/constants/user.ts
Normal file
1
src/constants/user.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export const INACTIVE_ACCOUNT_DAYS = 40;
|
21
src/utils/hooks/user/useUserDescription.ts
Normal file
21
src/utils/hooks/user/useUserDescription.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { IUser } from '~/redux/auth/types';
|
||||
import { useRandomPhrase } from '~/constants/phrases';
|
||||
import { differenceInDays, parseISO } from 'date-fns';
|
||||
import { INACTIVE_ACCOUNT_DAYS } from '~/constants/user';
|
||||
|
||||
const today = new Date();
|
||||
|
||||
export const useUserDescription = (user?: Partial<IUser>) => {
|
||||
const randomPhrase = useRandomPhrase('USER_DESCRIPTION');
|
||||
|
||||
if (!user) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const lastSeen = user.last_seen ? parseISO(user.last_seen) : undefined;
|
||||
if (!lastSeen || differenceInDays(today, lastSeen) > INACTIVE_ACCOUNT_DAYS) {
|
||||
return 'Юнит деактивирован';
|
||||
}
|
||||
|
||||
return randomPhrase;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue