Skip to content

Commit

Permalink
feat: 메일 삭제 UI 및 API 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
moong23 committed Sep 8, 2024
1 parent d49bb9f commit 90bd765
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/api/hooks/useMailReadMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ export const patchFn = ({ mailId }: patchParam) => {
return axiosInstance.patch(`/inbox/mails/${mailId}`, { action: 'read' });
};

export const deleteFn = ({ mailId }: patchParam) => {
return axiosInstance.delete(`/inbox/mails/${mailId}`);
};

export const useMailReadMutation = () => {
return useMutation<AxiosResponse, AxiosError, patchParam>({
mutationFn: patchFn,
});
};

export const useMailDeleteMutation = () => {
return useMutation<AxiosResponse, AxiosError, patchParam>({
mutationFn: deleteFn,
});
};
33 changes: 33 additions & 0 deletions src/app/article/[id]/ArticleFooter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useMailDeleteMutation } from '@/api/hooks/useMailReadMutation';
import DeleteIcon from '@/assets/icons/DeleteIcon.svg';
import ListIcon from '@/assets/icons/ListIcon.svg';
import Image from 'next/image';

interface ArticleFooterProps {
mailId: string;
}

const ArticleFooter = ({ mailId }: ArticleFooterProps) => {
const deleteMutation = useMailDeleteMutation();

const handleDeleteMail = (mailId: string) => {
deleteMutation.mutate({ mailId });
};
return (
<div className='fixed bottom-0 flex flex-row items-center justify-center w-full h-12 bg-white border-t border-lightgrey'>
<div className='flex flex-row justify-end gap-6 px-6 w-content'>
<span
className='flex items-center justify-center w-6 h-6 cursor-pointer'
onClick={() => handleDeleteMail(mailId)}
>
<Image src={DeleteIcon} alt='delete' width={16} height={24} />
</span>
<span className='flex items-center justify-center w-6 h-6 cursor-pointer'>
<Image src={ListIcon} alt='list' width={24} height={24} />
</span>
</div>
</div>
);
};

export default ArticleFooter;
13 changes: 9 additions & 4 deletions src/app/article/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ import type { pageProps } from '@/types/page';
import ArticleContent from '@/app/article/[id]/ArticleContent';
import MainPageHeader from '@/components/Header/MainPageHeader';
import { useMailByIdQuery } from '@/api/hooks/useFetchMailQuery';
import ArticleFooter from './ArticleFooter';

interface ArticlePageProps extends pageProps {
interface ArticlePageProps {
params: { id: string };
}

const ArticlePage = ({ searchParams, params }: ArticlePageProps) => {
const ArticlePage = ({ params }: ArticlePageProps) => {
const { data } = useMailByIdQuery(params.id);

return (
<main className='flex flex-col items-center w-full bg-white'>
<MainPageHeader />
{/* TODO: 개별 mail 받아와서 데이터 넘겨줘야함~~ */}
{data && <ArticleContent mailData={data} />}
{data && (
<>
<ArticleContent mailData={data} />
<ArticleFooter mailId={data.mailId} />
</>
)}
</main>
);
};
Expand Down
9 changes: 9 additions & 0 deletions src/assets/icons/DeleteIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/icons/ListIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ export const handlers = [
return HttpResponse.json({}, { status: 204 });
}),

http.delete('/inbox/mails/:id', () => {
return HttpResponse.json({ status: 204 });
}),

http.get('/users', () => {
return HttpResponse.json({
user_id: 'RandomString',
Expand Down

0 comments on commit 90bd765

Please sign in to comment.