mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +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
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