Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
feat: added server
Browse files Browse the repository at this point in the history
  • Loading branch information
nmashchenko committed Dec 18, 2023
1 parent 5ca68fa commit 156b936
Show file tree
Hide file tree
Showing 31 changed files with 557 additions and 657 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@storybook/addon-styling": "^1.3.6",
"@tanstack/react-query": "^5.0.0",
"@tanstack/react-query-devtools": "^5.0.1",
"@teameights/types": "^1.1.24",
"@teameights/types": "^1.1.27",
"@types/js-cookie": "^3.0.5",
"@types/lodash.debounce": "^4.0.7",
"@types/node": "20.4.8",
Expand Down
19 changes: 19 additions & 0 deletions client/src/entities/session/api/useGetNotifications.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use client';
import { useQuery } from '@tanstack/react-query';
import { InfinityPaginationResultType, NotificationType } from '@teameights/types';
import { API } from '@/shared/api';
import { API_NOTIFICATIONS } from '@/shared/constant';

export const useGetNotifications = () => {
return useQuery({
queryKey: ['useGetNotifications'],
queryFn: async () => {
const { data } =
await API.get<InfinityPaginationResultType<NotificationType>>(API_NOTIFICATIONS);
console.log(data);
return data;
},
refetchOnMount: false,
refetchOnWindowFocus: false,
});
};
17 changes: 17 additions & 0 deletions client/src/entities/session/api/useReadNotifications.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { API } from '@/shared/api';
import { API_NOTIFICATIONS } from '@/shared/constant';

export const useReadNotifications = () => {
const queryClient = useQueryClient();
return useMutation({
// TODO: add types here
mutationFn: async (id: string) => await API.patch(API_NOTIFICATIONS + `/${id}`),
onSuccess: () => {
// Invalidate and refetch
queryClient
.invalidateQueries({ queryKey: ['useGetNotifications'] })
.then(() => console.log('invalidated'));
},
});
};
2 changes: 2 additions & 0 deletions client/src/shared/constant/server-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export const API_LOGOUT = '/auth/logout';
export const API_GOOGLE_LOGIN = '/auth/google/login';
export const API_GITHUB_LOGIN = '/auth/github/login';
export const API_USERS = '/users';

export const API_NOTIFICATIONS = '/notifications';
1 change: 0 additions & 1 deletion client/src/shared/lib/mock/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './team';
export * from './user';
export * from './notification';
40 changes: 6 additions & 34 deletions client/src/shared/lib/mock/notification.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,16 @@
import { faker } from '@faker-js/faker';
import { getRandomItemFromArray } from './common';
import {
ISystemNotification,
ITeam,
ITeamInvitationNotification,
IUserBase,
StatusType,
} from '@teameights/types';
import { generateMockFileEntity, generateMockUser } from './user';
import { generateMockTeam } from './team';
import { ISystemNotification, IUserBase } from '@teameights/types';
import { generateMockUser } from './user';

export const generateSystemNotification = (initialUser?: IUserBase): ISystemNotification => ({
id: faker.number.int(),
user: initialUser ? initialUser : generateMockUser(),
receiver: initialUser ? initialUser : generateMockUser(),
type: 'system',
read: faker.datatype.boolean(),
expiresAt: faker.date.future(),
createdAt: faker.date.recent(),
updatedAt: faker.date.recent(),
system_message: faker.lorem.sentence(),
deletedAt: faker.date.recent(),
});

export const generateTeamInvitationNotification = (
initialUser?: IUserBase,
initialTeam?: ITeam,
initialFromUser?: IUserBase
): ITeamInvitationNotification => ({
id: faker.number.int(),
user: initialUser ? initialUser : generateMockUser(),
type: 'team_invite',
read: faker.datatype.boolean(),
expiresAt: faker.date.future(),
createdAt: faker.date.recent(),
updatedAt: faker.date.recent(),
team: initialTeam ? initialTeam : generateMockTeam(initialTeam),
from_user: initialFromUser ? initialFromUser : generateMockUser(),
to_user_email: faker.internet.email(),
status: getRandomItemFromArray(['pending', 'accepted', 'rejected']) as StatusType,
photo: generateMockFileEntity(),
message: faker.lorem.sentence(),
deletedAt: faker.date.recent(),
data: {
system_message: faker.lorem.sentence(),
},
});
26 changes: 0 additions & 26 deletions client/src/shared/lib/mock/team.ts

This file was deleted.

11 changes: 1 addition & 10 deletions client/src/shared/lib/mock/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import {
IProject,
IRole,
IStatus,
ITeam,
IUniversity,
IUserBase,
IUserProtectedResponse,
NotificationType,
} from '@teameights/types';
import { getRandomItemFromArray, shuffleArray } from './common';
import {
Expand Down Expand Up @@ -116,11 +114,7 @@ export const generateMockUniversity = (): IUniversity => ({
graduationDate: faker.datatype.boolean() ? faker.date.past() : null,
});

export const generateMockUser = (
type: Speciality = 'developer',
initialTeam?: ITeam,
initialNotifications?: NotificationType[]
): IUserBase => {
export const generateMockUser = (type: Speciality = 'developer'): IUserBase => {
const user: IUserBase = {
id: faker.number.int(),
username: faker.internet.userName(),
Expand Down Expand Up @@ -151,9 +145,6 @@ export const generateMockUser = (
),
links: faker.datatype.boolean() ? generateMockLinks() : null,
skills: null,
notifications: initialNotifications ? initialNotifications : [],
// to avoid dead lock we can't generate team here, we will need to add team
team: initialTeam ? initialTeam : null,
createdAt: faker.date.recent(),
updatedAt: faker.date.recent(),
deletedAt: faker.datatype.boolean() ? faker.date.recent() : null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.span_text {
color: var(--green-bright-color);
}
//.span_text {
// color: var(--green-bright-color);
//}

This file was deleted.

Loading

0 comments on commit 156b936

Please sign in to comment.