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

Commit

Permalink
Feat: add new project api (#61)
Browse files Browse the repository at this point in the history
Co-authored-by: Ruslan Kutliakhmetov <[email protected]>
  • Loading branch information
DieWerkself and ko22009 authored Nov 17, 2023
1 parent 33d8a94 commit f442b52
Show file tree
Hide file tree
Showing 69 changed files with 1,391 additions and 560 deletions.
81 changes: 72 additions & 9 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@
"@emotion/styled": "^11.11.0",
"@tanstack/react-query": "^4.35.3",
"@types/lodash": "^4.14.200",
"axios": "^1.5.0",
"@types/uuid": "^9.0.7",
"axios": "^1.6.0",
"chakra-react-select": "^4.7.6",
"form-data": "^4.0.0",
"framer-motion": "^10.16.4",
"lodash": "^4.17.21",
"query-string": "^8.1.0",
"react": "^18.2.0",
"react-device-detect": "^2.2.3",
"react-dom": "^18.2.0",
"react-hook-form": "^7.45.4",
"react-icons": "^4.11.0",
"react-router-dom": "^6.15.0",
"uuid": "^9.0.1",
"zustand": "^4.4.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/app/providers/layout/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Flex } from '@chakra-ui/react';
import { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';

import { IsAuthResponse } from '~/shared/api';
import { IsAuthResponse } from '~/shared/api/types';
import { AuthContext, initAuth } from '~/shared/contexts';
import { useApi } from '~/shared/hooks';
import { Loader } from '~/shared/ui/Loader';
Expand Down
5 changes: 5 additions & 0 deletions src/entities/project/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './useGetPositions';
export * from './useGetPositionsSkills';
export * from './useGetProject';
export * from './useGetProjectAvatar';
export * from './useGetUser';
9 changes: 9 additions & 0 deletions src/entities/project/api/useGetPositions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';

export const useGetPositions = (projectId: string) =>
useQuery({
queryKey: ['getProjectPositions', projectId],
queryFn: () => api.projectsApi.getProjectPositions(projectId),
});
19 changes: 19 additions & 0 deletions src/entities/project/api/useGetPositionsSkills.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useQueries } from '@tanstack/react-query';

import { GetProjectPositionsData } from '~/shared/api/types';
import { api } from '~/shared/contexts';

export const useGetPositionsSkills = (
projectId: string,
projectPositions?: GetProjectPositionsData,
) =>
useQueries({
queries: projectPositions
? projectPositions.map(({ id }) => {
return {
queryKey: ['positionSkills', projectId, id],
queryFn: () => api.projectsApi.getPositionSkills(projectId, id),
};
})
: [],
});
9 changes: 9 additions & 0 deletions src/entities/project/api/useGetProject.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';

export const useGetProject = (projectId: string) =>
useQuery({
queryKey: ['getCurrentProject', projectId],
queryFn: () => api.projectsApi.getCurrentProject(projectId),
});
9 changes: 9 additions & 0 deletions src/entities/project/api/useGetProjectAvatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';

export const useGetProjectAvatar = (projectId: string) =>
useQuery({
queryKey: ['useGetProjectAvatar', projectId],
queryFn: () => api.projectsApi.getProjectAvatar(projectId),
});
9 changes: 9 additions & 0 deletions src/entities/project/api/useGetUser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '~/shared/contexts';

export const useGetUser = (userID: string) =>
useQuery({
queryKey: ['userID', userID],
queryFn: () => api.userApi.getUser(userID),
});
30 changes: 30 additions & 0 deletions src/entities/project/contacts/Contacts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Flex, Heading, Stack, Text } from '@chakra-ui/layout';
import { Avatar, Skeleton } from '@chakra-ui/react';
import React from 'react';

import { Rating } from '~/shared/ui/rating';

import { useGetUser } from '../api';

export const Contacts = ({ ownerId }: { ownerId: string }) => {
const { data: owner, isSuccess: loadedOwner } = useGetUser(ownerId);
return (
<>
<Heading variant="h2">Контакты</Heading>
<Skeleton isLoaded={loadedOwner} borderRadius="2xl" fadeDuration={2}>
<Flex alignItems="flex-start">
<Avatar src="" name={`${owner?.first_name} ${owner?.last_name}`} />
<Stack pl={2} gap={0}>
<Heading variant="h3">
{owner?.first_name} {owner?.last_name}
</Heading>
<Text variant="caption">Организатор</Text>
</Stack>
<Flex ml="auto">
<Rating />
</Flex>
</Flex>
</Skeleton>
</>
);
};
1 change: 1 addition & 0 deletions src/entities/project/contacts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Contacts';
3 changes: 3 additions & 0 deletions src/entities/project/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export * from './card';
export * from './contacts';
export * from './avatars-group';
export * from './api';
export * from './info';
71 changes: 71 additions & 0 deletions src/entities/project/info/ProjectInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Heading, Stack } from '@chakra-ui/layout';
import { Skeleton } from '@chakra-ui/react';
import React from 'react';

import { GetSpecsData } from '~/shared/api';
import { GetProjectPositionsData } from '~/shared/api/types';
import { STag } from '~/shared/ui/STag';
import { Status } from '~/shared/ui/status';

import { Card } from '../card';

interface Project {
deadline: string;
status: string;
id: string;
name: string;
description: string | null;
owner_id: string;
startline: string;
created_at: string;
updated_at: string;
}

interface ProjectInfoProps {
allSpecs?: GetSpecsData;
specs: string[];
skills: string[][];
project: Project;
positions?: GetProjectPositionsData;
ioadedPositions: boolean;
}

export const ProjectInfo = ({
allSpecs,
specs,
skills,
project,
positions,
ioadedPositions,
}: ProjectInfoProps) => {
const filterMainTag = (positionId?: string) => {
const mainTag = allSpecs
?.filter(({ id }) => id === positionId)
.map(({ name }) => name ?? '');
return mainTag;
};
return (
<>
<Stack gap={0} mb={3} alignItems="start">
<Status mb={['3', '4']}>{project.status}</Status>
<Card
title={project.name}
date={project.deadline}
description={project.description}
fullDescription={true}
/>
</Stack>

<Stack gap={0} mb={6}>
<Heading variant="h2">В проект требуются</Heading>
<Skeleton isLoaded={ioadedPositions} borderRadius="2xl" fadeDuration={2}>
<Stack>
{positions?.map((_, i) => (
<STag key={i} mainTags={filterMainTag(specs[i])} tags={skills[i]} />
))}
</Stack>
</Skeleton>
</Stack>
</>
);
};
1 change: 1 addition & 0 deletions src/entities/project/info/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ProjectInfo';
Loading

0 comments on commit f442b52

Please sign in to comment.