1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

added user description for deactivated units

This commit is contained in:
Fedor Katurov 2021-10-05 15:32:02 +07:00
parent f19fed1c5a
commit 07852df0dc
3 changed files with 27 additions and 6 deletions

View 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;
};