Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#157[Fix] Revise, sections 페이지 api 연결 #161

Merged
merged 6 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"framer-motion": "^11.0.12",
"moment": "^2.30.1",
"qrcode.react": "^3.1.0",
"query-string": "^9.0.0",
"react": "^18.2.0",
"react-bootstrap-icons": "^1.11.3",
"react-datepicker": "^6.4.0",
Expand Down
10 changes: 5 additions & 5 deletions src/api/@types/Retrospectives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export interface onlyGetRetrospectiveResponse {
}

export interface RetrospectiveData {
retrospectiveId: number;
title: string;
templateId: number;
teamId: number;
userId: number;
description: string;
retrospectiveId: number;
status: keyof TStatus;
teamId: number;
templateId: number;
thumbnail: string;
title: string;
userId: number;
}

// get
Expand Down
2 changes: 1 addition & 1 deletion src/api/@types/Section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ export interface SectionClient {
get(request: GetSectionRequest): Promise<GetSectionResponse>;
create(request: CreateSectionRequest): Promise<PostSectionResponse>;
patch(request: PatchSectionRequest): Promise<PatchSectionResponse>;
delete(request: DeleteSectionRequest): Promise<void>;
delete(request: DeleteSectionRequest): Promise<DeleteSectionResponse>;
likePost(request: PostLikesSectionRequest): Promise<PostLikeSectionResponse>;
}
2 changes: 1 addition & 1 deletion src/api/__mock__/retrospective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const MockRetrospective: RetrospectiveResponse = {
id: 0,
title: 'hee',
userId: 0,
teamId: 0,
teamId: 1,
templateId: 1,
status: Status.NOT_STARTED,
isBookmarked: true,
Expand Down
15 changes: 15 additions & 0 deletions src/api/__mock__/teamMembers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { GetTeamMembersResponse, TeamMembersData } from '../@types/TeamController';

export const MockTeamMembers: GetTeamMembersResponse = {
code: 1,
message: 'no',
data: [
{ userId: 1, username: 'gg', profileImage: 'gggg' },
{ userId: 1, username: 'ff', profileImage: 'gggg' },
],
};

export const MockTeamMembersData: TeamMembersData[] = [
{ userId: 1, username: 'gg', profileImage: 'gggg' },
{ userId: 1, username: 'ff', profileImage: 'gggg' },
];
5 changes: 5 additions & 0 deletions src/api/client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import axios from 'axios';

import axiosInstance from './axiosConfig';
import { logRequest } from './interceptors/request';
import { unwrapResponse } from './interceptors/response';
// import { logAndProcessError, logResponse, unwrapResponse } from './interceptors/response';
// import { flow } from '@/utils/flow';


export const mswInstance = axios.create({
baseURL: '/',
timeout: 4000,
Expand All @@ -18,7 +20,10 @@ export const mswInstance = axios.create({
// withCredentials: true,
// });



axiosInstance.interceptors.request.use(logRequest);
// axiosInstance.interceptors.response.use(flow([logResponse, unwrapResponse]), logAndProcessError);


mswInstance.interceptors.response.use(unwrapResponse);
59 changes: 47 additions & 12 deletions src/api/services/Retrospectives.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
import { RetrospectivesClient } from '../@types/Retrospectives';
import {
DeleteRetrospectiveRequest,
GetRetrospectiveData,
GetRetrospectiveRequest,
onlyGetRetrospectiveRequest,
onlyGetRetrospectiveResponse,
PostRetrospectivesRequest,
PostRetrospectivesResponse,
RetrospectivesClient,
} from '../@types/Retrospectives';
import axiosInstance from '../axiosConfig';
import { mswInstance } from '../client';

const ROUTE = 'retrospectives';

export const RetrospectiveService: RetrospectivesClient = {
onlyGet: async ({ retrospectiveId }) => {
return await axiosInstance.get(`${ROUTE}/${retrospectiveId}`);
onlyGet: async ({ retrospectiveId }: onlyGetRetrospectiveRequest): Promise<onlyGetRetrospectiveResponse> => {
try {
const response = await axiosInstance.get<onlyGetRetrospectiveResponse>(`${ROUTE}/${retrospectiveId}`);
return response.data;
} catch (error) {
throw new Error('템플릿 조회 실패');
}
},
create: async request => {
return await mswInstance.post(`${ROUTE}/`, request);
create: async (request: PostRetrospectivesRequest): Promise<PostRetrospectivesResponse> => {
try {
const response = await axiosInstance.post<PostRetrospectivesResponse>(`${ROUTE}/`, request);
return response.data;
} catch (error) {
throw new Error(error as string);
}
},
get: async request => {
return await mswInstance.get(`${ROUTE}/`, {
params: request,
});
get: async (request: GetRetrospectiveRequest): Promise<GetRetrospectiveData> => {
try {
const response = await mswInstance.get(`${ROUTE}/`, {
params: request,
});
return response.data;
} catch (error) {
throw new Error(error as string);
}
},
delete: async ({ retrospectiveId }) => {
return await mswInstance.delete(`${ROUTE}/${retrospectiveId}`);

delete: async ({ retrospectiveId }: DeleteRetrospectiveRequest): Promise<void> => {
try {
const response = await mswInstance.delete(`${ROUTE}/${retrospectiveId}`);
return response.data;
} catch (error) {
throw new Error(error as string);
}
},
put: async ({ retrospectiveId }, ...request) => {
return await axiosInstance.put(`${ROUTE}/${retrospectiveId}`, request);
try {
const response = await axiosInstance.put(`${ROUTE}/${retrospectiveId}`, request);
return response.data;
} catch (error) {
throw new Error(error as string);
}
},
};
55 changes: 45 additions & 10 deletions src/api/services/Section.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,57 @@
import { SectionClient } from '../@types/Section';
import {
CreateSectionRequest,
DeleteSectionRequest,
DeleteSectionResponse,
GetSectionRequest,
GetSectionResponse,
PostLikeSectionResponse,
PostLikesSectionRequest,
PostSectionResponse,
SectionClient,
} from '../@types/Section';
import axiosInstance from '../axiosConfig';

const ROUTE = 'sections';

export const SectionServices: SectionClient = {
get: async request => {
return await axiosInstance.get(`${ROUTE}`, { params: request });
get: async (request: GetSectionRequest): Promise<GetSectionResponse> => {
try {
const response = await axiosInstance.get<GetSectionResponse>(`${ROUTE}`, { params: request });
return response.data;
} catch (error) {
throw new Error(error as string);
}
},
create: async request => {
return await axiosInstance.post(`${ROUTE}/`, request);
create: async (request: CreateSectionRequest): Promise<PostSectionResponse> => {
try {
const response = await axiosInstance.post<PostSectionResponse>(`${ROUTE}/`, request);
return response.data;
} catch (error) {
throw new Error(error as string);
}
},
patch: async ({ sectionId, ...request }) => {
return await axiosInstance.patch(`${ROUTE}/${sectionId}`, request);
try {
const response = await axiosInstance.patch(`${ROUTE}/${sectionId}`, request);
return response.data;
} catch (error) {
throw new Error(error as string);
}
},
delete: async ({ sectionId }) => {
return await axiosInstance.delete(`${ROUTE}/${sectionId}`);
delete: async ({ sectionId }: DeleteSectionRequest): Promise<DeleteSectionResponse> => {
try {
const response = await axiosInstance.delete<DeleteSectionResponse>(`${ROUTE}/${sectionId}`);
return response.data;
} catch (error) {
throw new Error(error as string);
}
},
likePost: async ({ sectionId }) => {
return await axiosInstance.post(`${ROUTE}/${sectionId}/likes`);
likePost: async ({ sectionId }: PostLikesSectionRequest): Promise<PostLikeSectionResponse> => {
try {
const response = await axiosInstance.post<PostLikeSectionResponse>(`${ROUTE}/${sectionId}/likes`);
return response.data;
} catch (error) {
throw new Error(error as string);
}
},
};
13 changes: 9 additions & 4 deletions src/api/services/TeamController.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { TeamControllerClient } from '../@types/TeamController';
import { mswInstance } from '../client';
import { GetTeamMembersRequest, TeamControllerClient } from '../@types/TeamController';
import axiosInstance from '../axiosConfig';

const ROUTE = 'teams';

export const TeamControllerServices: TeamControllerClient = {
get: async ({ teamId, ...request }) => {
return await mswInstance.get(`${ROUTE}/${teamId}/users`, { params: request });
get: async ({ teamId, ...request }: GetTeamMembersRequest) => {
try {
const response = await axiosInstance.get(`${ROUTE}/${teamId}/users`, { params: request });
return response.data;
} catch (error) {
throw new Error(error as string);
}
},
};
67 changes: 43 additions & 24 deletions src/components/writeRetro/revise/DeleteRetrospective.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
import { FC } from 'react';
import { IoIosInformationCircle } from 'react-icons/io';
import { useNavigate } from 'react-router-dom';
import { Button, Popover, PopoverTrigger, PopoverContent, PopoverBody, PopoverFooter, Portal } from '@chakra-ui/react';
import { MockRetrospective } from '@/api/__mock__/retrospective';
import {
Button,
Popover,
PopoverTrigger,
PopoverContent,
PopoverBody,
PopoverFooter,
Portal,
Flex,
} from '@chakra-ui/react';
import { RetrospectiveService } from '@/api/services/Retrospectives';
import { useCustomToast } from '@/hooks/useCustomToast';
import * as L from '@/styles/writeRetroStyles/Layout.style';
import * as S from '@/styles/writeRetroStyles/ReviseLayout.style';

// interface Props {
// fetch: RetrospectiveData;
// }
interface Props {
retrospectiveId: number;
}

const DeleteRetrospective: FC = () => {
const DeleteRetrospective: FC<Props> = ({ retrospectiveId }) => {
const toast = useCustomToast();
const navigate = useNavigate();
const handleDeleteRetrospective = async () => {
try {
await RetrospectiveService.delete({ retrospectiveId: MockRetrospective.data.id });
await RetrospectiveService.delete({ retrospectiveId: retrospectiveId });
navigate('/retrolist');
toast.info('회고가 삭제되었습니다.');
} catch (e) {
Expand All @@ -23,23 +34,31 @@ const DeleteRetrospective: FC = () => {
};
return (
<>
<Popover>
<PopoverTrigger>
<Button colorScheme="red" variant="outline">
회고 삭제
</Button>
</PopoverTrigger>
<Portal>
<PopoverContent>
<PopoverBody margin="0 auto">회고를 정말 삭제하시겠습니까?</PopoverBody>
<PopoverFooter display="flex" flexDirection="row-reverse" margin="0 auto">
<Button colorScheme="red" onClick={handleDeleteRetrospective}>
</Button>
</PopoverFooter>
</PopoverContent>
</Portal>
</Popover>
<L.reviseTitleText>회고 삭제</L.reviseTitleText>
<S.SettingLine />
<Flex margin="20px 10px">
<IoIosInformationCircle color="#FF4646" size={20} style={{ margin: 'auto 0' }} />
<S.SettingDetailText>삭제 후 복구할 수 없습니다.</S.SettingDetailText>
</Flex>
<Flex flexDirection="row-reverse" margin="30px">
<Popover>
<PopoverTrigger>
<Button colorScheme="red" variant="outline">
회고 삭제
</Button>
</PopoverTrigger>
<Portal>
<PopoverContent>
<PopoverBody margin="0 auto">회고를 정말 삭제하시겠습니까?</PopoverBody>
<PopoverFooter display="flex" flexDirection="row-reverse" margin="0 auto">
<Button colorScheme="red" onClick={handleDeleteRetrospective}>
</Button>
</PopoverFooter>
</PopoverContent>
</Portal>
</Popover>
</Flex>
</>
);
};
Expand Down
Loading
Loading