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

add user notifications ()

* added notification settings

* notifications: added list to profile

* notifications: changed appearance for comment notifications
This commit is contained in:
muerwre 2023-03-11 17:16:31 +06:00 committed by GitHub
parent 23701a5261
commit a39d000ff2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 552 additions and 218 deletions
src/hooks/notifications

View file

@ -0,0 +1,36 @@
import { isValid, parseISO } from 'date-fns';
import useSWR from 'swr';
import { apiGetNotificationSettings } from '~/api/notifications/settings';
import { API } from '~/constants/api';
import { useAuth } from '../auth/useAuth';
const refreshInterval = 60e3; // 1min
export const useNotificationSettingsRequest = () => {
const { isUser } = useAuth();
const {
data,
isValidating: isLoading,
error,
} = useSWR(
isUser ? API.NOTIFICATIONS.SETTINGS : null,
async () => apiGetNotificationSettings(),
{ refreshInterval },
);
return {
isLoading,
error,
lastSeen:
data?.last_seen && isValid(parseISO(data.last_seen))
? parseISO(data?.last_seen)
: undefined,
lastDate:
data?.last_date && isValid(parseISO(data.last_date))
? parseISO(data?.last_date)
: undefined,
enabled: !!data?.enabled && (data.flow || data.comments),
};
};