mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-05-01 15:46:40 +07:00
add user notifications (#148)
* added notification settings * notifications: added list to profile * notifications: changed appearance for comment notifications
This commit is contained in:
parent
23701a5261
commit
a39d000ff2
27 changed files with 552 additions and 218 deletions
src/hooks/notifications
36
src/hooks/notifications/useNotificationSettingsRequest.ts
Normal file
36
src/hooks/notifications/useNotificationSettingsRequest.ts
Normal 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),
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue