Skip to content

Commit

Permalink
fix: 커스텀 훅 관련 오류 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
urjimyu committed May 28, 2024
1 parent 92683c2 commit 21dfffd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/components/DeleteButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from 'styled-components';
import { useDeleteUser } from '../hooks/queries/useDeleteUser';
import { useNavigate } from 'react-router-dom';

interface DeleteButtonInterface {
message: string;
Expand All @@ -8,14 +9,20 @@ interface DeleteButtonInterface {
const DeleteButton = ({ message }: DeleteButtonInterface) => {
const { deleteUser } = useDeleteUser();
const accessToken = localStorage.getItem('ACCESS_TOKEN');
const navigate = useNavigate();

if (!accessToken) {
console.error('Access token is missing');
return null;
}

const handleDeleteUser = () => {
deleteUser(accessToken);
const handleDeleteUser = async () => {
const result = await deleteUser(accessToken);
if (result.success) {
navigate('/complete');
} else {
navigate('/error');
}
};

return <ButtonWrapper onClick={handleDeleteUser}>{message}</ButtonWrapper>;
Expand Down
6 changes: 2 additions & 4 deletions src/hooks/queries/useDeleteUser.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { useNavigate } from 'react-router-dom';
import user from '../../apis/user';

export const useDeleteUser = () => {
const deleteUser = async (accessToken: string) => {
console.log('clicked?');
const navigate = useNavigate();
try {
await user.deleteUser(accessToken);
navigate('/complete');
return { success: true };
} catch (err) {
console.error(err);
navigate('/error');
return { success: false };
}
};

Expand Down

0 comments on commit 21dfffd

Please sign in to comment.