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

Commit

Permalink
refactor: страницы поиска, проектов
Browse files Browse the repository at this point in the history
  • Loading branch information
DieWerkself committed Nov 27, 2023
1 parent b65ea06 commit c575d84
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 42 deletions.
13 changes: 10 additions & 3 deletions src/entities/project/filter/ui/Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import { useFilterStore } from '../model';

interface FilterProps {
totalItems?: number | null;
isLoading?: boolean;
}

export const Filter = ({ totalItems = 0 }: FilterProps) => {
export const Filter = ({ isLoading, totalItems = 0 }: FilterProps) => {
const { isOpen, onOpen, onClose } = useDisclosure();

const { filter, removeFilter, updateFilter } = useFilterStore();
Expand Down Expand Up @@ -128,8 +129,14 @@ export const Filter = ({ totalItems = 0 }: FilterProps) => {
</Stack>
</Container>
<Container maxW="md" py={6} bg="bg" position="sticky" bottom="0" mt="auto">
<Button fontSize="sm" fontWeight="600" w="full" onClick={onClose}>
Найдено позиций: {totalItems ?? 0}
<Button
isLoading={isLoading}
fontSize="sm"
fontWeight="600"
w="full"
onClick={onClose}
>
{totalItems ? `Найдено позиций: ${totalItems}` : 'Позиций не найдено'}
</Button>
</Container>
</ModalContent>
Expand Down
17 changes: 17 additions & 0 deletions src/entities/user/avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
SkeletonText,
Avatar as ChakraAvatar,
} from '@chakra-ui/react';
import { useEffect } from 'react';

import { useFilterStore } from '~/entities/project';

import { useGetAvatar, useGetProfile } from '../api';

Expand All @@ -17,6 +20,20 @@ interface AvatarProps {
export const Avatar = ({ userId }: AvatarProps) => {
const { data, isLoading } = useGetProfile(userId);

const { updateFilter } = useFilterStore();

useEffect(() => {
if (data) {
if (data.main_specialization_id) {
data.secondary_specialization_id
? updateFilter({
specs: [data.main_specialization_id, data.secondary_specialization_id],
})
: updateFilter({ specs: [data.main_specialization_id] });
}
}
}, [data]);

const { data: avatar } = useGetAvatar(userId);

return (
Expand Down
1 change: 1 addition & 0 deletions src/features/project/request/api/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './useUpdateParticipant';
export * from './useUpdateProject';
15 changes: 15 additions & 0 deletions src/features/project/request/api/useUpdateProject.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';

import { UpdateProjectParams, UpdateProjectRequest } from '~/shared/api/types';
import { api } from '~/shared/contexts';

export const useUpdateProject = () => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: UpdateProjectRequest & UpdateProjectParams) =>
api.projectsApi.updateProject(data),
onSuccess: (response) => {
queryClient.invalidateQueries(['getCurrentProject', response.id]);
},
});
};
51 changes: 39 additions & 12 deletions src/pages/projects/ui/ProjectBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Link, generatePath } from 'react-router-dom';

import { RequestParticipant, Requests } from '~/widgets/project';

import { useUpdateParticipant } from '~/features/project';
import { useUpdateParticipant, useUpdateProject } from '~/features/project';

import {
Avatar,
Expand Down Expand Up @@ -54,10 +54,17 @@ export const ProjectBase = ({ projectId }: ProjectBase) => {
onOpen: leftOnOpen,
onClose: leftOnClose,
} = useDisclosure();
const {
isOpen: closeProjectIsOpen,
onOpen: closeProjectOnOpen,
onClose: closeProjectOnClose,
} = useDisclosure();
const [specsIds, setSpecsIds] = useState<string[]>([]);
const [unvaluedSkillsIds, setUnvaluedSkillsIds] = useState<string[][]>([]);
const [readySkillsIds, setReadySkillsIds] = useState<string[][]>([]);
const { mutateAsync: updateParticipant } = useUpdateParticipant();
const { mutateAsync: updateProject, isLoading: updateProjectLoading } =
useUpdateProject();

const { data: allParticipant } = useGetParticipants({
project_id: projectId,
Expand Down Expand Up @@ -113,17 +120,14 @@ export const ProjectBase = ({ projectId }: ProjectBase) => {
}
};

const cancelProject = async () => {
await updateProject({ project_id: projectId, status: 'finished' });
closeProjectOnClose();
};

return (
<Container maxW="md" display="flex" flexDirection="column">
<Flex
position="sticky"
bg="bg"
zIndex={3}
top={0}
alignItems="center"
justifyContent="space-between"
py={4}
>
<Container maxW="md" display="flex" flexDirection="column" mb={4}>
<Flex bg="bg" top={0} alignItems="center" justifyContent="space-between" py={4}>
<Flex alignItems="center">
<GoBack />
<Heading variant="h2" mb={0}>
Expand Down Expand Up @@ -219,9 +223,32 @@ export const ProjectBase = ({ projectId }: ProjectBase) => {
</CardBody>
</ChakraCard>
)}
{layout?.footer && (
{layout?.footer && project?.status !== 'Проект завершён' && (
<Portal containerRef={layout.footer}>
<Container py={2} maxW="md">
{!userNotOwner && (
<Button
onClick={closeProjectOnOpen}
bg="gray.300"
color="gray.900"
_hover={{ bg: 'gray.300' }}
fontSize="sm"
fontWeight="600"
w="full"
>
Завершить проект
</Button>
)}
<Modal
isOpen={closeProjectIsOpen}
onClose={closeProjectOnClose}
submitText="Завершить проект"
cancelText="Отмена"
onSubmit={cancelProject}
isLoading={updateProjectLoading}
>
Вы уверены, что хотите завершить проект?
</Modal>
{userStatus === 'request' && (
<Button
isDisabled
Expand Down
1 change: 1 addition & 0 deletions src/pages/search/api/useGetAllPositions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const useGetAllPositions = ({ specs, skills, date, searchText }: Search)
skills_ids: skills?.map((skill) => skill.value),
project_startline_le: date,
project_query_text: searchText,
// project_status: ['preparation', 'in_work'],
}),
getNextPageParam: (lastPage) =>
lastPage.page < lastPage.total_pages ? lastPage.page + 1 : undefined,
Expand Down
5 changes: 3 additions & 2 deletions src/pages/search/ui/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ export const SearchPage = ({ user }: BasePageProps) => {
date: filter.date,
skills: filter.skills,
specs: filter.specs,

searchText,
});

const { data: allSpecs } = useGetSpecs();

const { data: allSkills } = useQuery({
queryKey: ['skills'],
queryFn: () => storageApi.getSkills({}),
queryFn: () => storageApi.getSkills({ per_page: 2000 }),
staleTime: Infinity,
});

Expand Down Expand Up @@ -91,7 +92,7 @@ export const SearchPage = ({ user }: BasePageProps) => {
</Flex>
<Flex gap="1" mb={4}>
<SearchProject onChange={handleSumbit} />
<Filter totalItems={data?.pages[0].total_items} />
<Filter totalItems={data?.pages[0].total_items} isLoading={isLoading} />
</Flex>
{isLoading || !data ? (
<>
Expand Down
14 changes: 14 additions & 0 deletions src/shared/api/clients/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import {
UpdateParticipantRequest,
UpdateProjectAvatar,
UpdateProjectAvatarID,
UpdateProjectParams,
UpdateProjectRequest,
UpdateProjectResponse,
UpdateSkillsParams,
} from '../types/project.types';

Expand Down Expand Up @@ -79,6 +82,17 @@ export class ProjectsApiClient extends BaseApiClient {
return data;
}

async updateProject({
status,
project_id,
}: UpdateProjectRequest & UpdateProjectParams) {
const { data } = await this.client.patch<UpdateProjectResponse>(
`/api/rest/projects/${project_id}`,
{ status },
);
return data;
}

async getParticipants(request: GetAllParticipantsRequest) {
const { data } = await this.client.get<GetAllParticipantsResponse>(
`/api/rest/participants/`,
Expand Down
6 changes: 6 additions & 0 deletions src/shared/api/types/project.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export type UpdateParticipantParams =
paths['/api/rest/participants/{participant_id}']['post']['parameters']['path'];
export type UpdateParticipantRequest =
paths['/api/rest/participants/{participant_id}']['post']['requestBody']['content']['application/json'];
export type UpdateProjectParams =
paths['/api/rest/projects/{project_id}']['patch']['parameters']['path'];
export type UpdateProjectRequest =
paths['/api/rest/projects/{project_id}']['patch']['requestBody']['content']['application/json'];
export type UpdateProjectResponse =
paths['/api/rest/projects/{project_id}']['patch']['responses']['200']['content']['application/json'];
export type CreateParticipantRequest =
paths['/api/rest/participants/']['post']['requestBody']['content']['application/json'];
export type CreateParticipantResponse =
Expand Down
4 changes: 4 additions & 0 deletions src/shared/ui/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface ModalCustomProps {
submitText: string;
cancelText: string;
children: string;
isLoading?: boolean;
}

export const Modal = ({
Expand All @@ -24,6 +25,7 @@ export const Modal = ({
children,
submitText,
cancelText,
isLoading,
}: ModalCustomProps) => {
return (
<ChakraModal onClose={onClose} isOpen={isOpen} isCentered>
Expand All @@ -37,6 +39,7 @@ export const Modal = ({
<ModalFooter flexDirection="column" gap={2}>
<Button
type="button"
isLoading={isLoading}
onClick={onSubmit}
fontSize="sm"
fontWeight="600"
Expand All @@ -46,6 +49,7 @@ export const Modal = ({
</Button>
<Button
variant="ghost"
isLoading={isLoading}
type="button"
bg="gray.300"
onClick={onClose}
Expand Down
24 changes: 0 additions & 24 deletions src/shared/ui/status/Status.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/shared/ui/status/index.ts

This file was deleted.

0 comments on commit c575d84

Please sign in to comment.