mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
added profile quick info
This commit is contained in:
parent
1241d2c784
commit
141b9c0d60
8 changed files with 84 additions and 32 deletions
14
src/hooks/auth/useUserActiveStatus.ts
Normal file
14
src/hooks/auth/useUserActiveStatus.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { differenceInDays, parseISO } from 'date-fns';
|
||||
|
||||
import { INACTIVE_ACCOUNT_DAYS } from '~/constants/user';
|
||||
|
||||
const today = new Date();
|
||||
|
||||
export const useUserActiveStatus = (lastSeen?: string) => {
|
||||
try {
|
||||
const lastSeenDate = lastSeen ? parseISO(lastSeen) : undefined;
|
||||
return lastSeenDate && differenceInDays(today, lastSeenDate) < INACTIVE_ACCOUNT_DAYS;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
|
@ -1,11 +1,7 @@
|
|||
import { differenceInDays, parseISO } from 'date-fns';
|
||||
|
||||
import { useRandomPhrase } from '~/constants/phrases';
|
||||
import { INACTIVE_ACCOUNT_DAYS } from '~/constants/user';
|
||||
import { useUserActiveStatus } from '~/hooks/auth/useUserActiveStatus';
|
||||
import { IUser } from '~/types/auth';
|
||||
|
||||
const today = new Date();
|
||||
|
||||
export const useUserDescription = (user?: Partial<IUser>) => {
|
||||
const randomPhrase = useRandomPhrase('USER_DESCRIPTION');
|
||||
|
||||
|
@ -13,8 +9,9 @@ export const useUserDescription = (user?: Partial<IUser>) => {
|
|||
return '';
|
||||
}
|
||||
|
||||
const lastSeen = user.last_seen ? parseISO(user.last_seen) : undefined;
|
||||
if (!lastSeen || differenceInDays(today, lastSeen) > INACTIVE_ACCOUNT_DAYS) {
|
||||
const isActive = useUserActiveStatus(user.last_seen);
|
||||
|
||||
if (!isActive) {
|
||||
return 'Юнит деактивирован';
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue