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

feat-fe: 로그아웃 #574

Merged
merged 8 commits into from
Aug 21, 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
2 changes: 2 additions & 0 deletions frontend/src/api/domain/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const authApi = {
path: '/login',
body: { email, password },
}),

logout: async () => apiClient.post({ path: '/logout' }),
};

export default authApi;
7 changes: 5 additions & 2 deletions frontend/src/components/common/Spinner/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { StyleProps } from './style';
import S from './style';

export default function Spinner({ width }: StyleProps) {
export default function Spinner({ width, color = 'white' }: StyleProps) {
return (
<S.Spinner width={width}>
<S.Spinner
width={width}
color={color}
>
<S.Bounce className="bounce1" />
<S.Bounce className="bounce2" />
<S.Bounce />
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/common/Spinner/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from '@emotion/styled';

export interface StyleProps {
width?: number;
color?: 'white' | 'primary';
}

const bounceDelay = keyframes`
Expand All @@ -17,6 +18,8 @@ const bounceDelay = keyframes`
const Spinner = styled.div<StyleProps>`
--design-width: ${({ width }) => (width ? `${width}px` : '100%')};
--design-height: ${({ width }) => (width ? `${width * 0.23}px` : '1.8rem')};
--design-color: ${({ theme, color }) =>
color === 'primary' ? theme.colors.brand.primary : theme.baseColors.grayscale[50]};

display: flex;
justify-content: center;
Expand All @@ -28,7 +31,7 @@ const Bounce = styled.div`
width: var(--design-height);
aspect-ratio: 1/1;

background-color: ${({ theme }) => theme.baseColors.grayscale[50]};
background-color: var(--design-color);
border-radius: 100%;
animation: ${bounceDelay} 1.4s infinite ease-in-out both;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ const meta: Meta<typeof DashboardSidebar> = {
export default meta;
type Story = StoryObj<typeof DashboardSidebar>;

export const Default: Story = {};
export const Default: Story = {
args: {
options: [
{ text: '우아한테크코스 6기 프론트엔드', isSelected: true, postId: 1 },
{ text: '우아한테크코스 6기 백엔드', isSelected: false, postId: 2 },
{ text: '우아한테크코스 6기 안드로이드', isSelected: false, postId: 3 },
],
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import useSignOut from '@hooks/useSignOut';
import Spinner from '@components/common/Spinner';
import S from './style';

export default function LogoutButton() {
const { mutate: logout, isPending } = useSignOut();

return (
<S.LogoutButton onClick={() => logout()}>
{isPending ? (
<Spinner
width={40}
color="primary"
/>
) : (
'로그아웃'
)}
</S.LogoutButton>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import styled from '@emotion/styled';

const LogoutButton = styled.button`
${({ theme }) => theme.typography.common.default};
color: ${({ theme }) => theme.baseColors.grayscale[600]};

position: absolute;
bottom: 2.4rem;
left: 50%;
transform: translateX(-50%);
`;

const S = {
LogoutButton,
};

export default S;
3 changes: 3 additions & 0 deletions frontend/src/components/dashboard/DashboardSidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Logo from '@assets/images/logo.svg';
import Accordion from '@components/common/Accordion';
import { Link, useParams } from 'react-router-dom';
import LogoutButton from './LogoutButton';
import S from './style';

interface Option {
Expand Down Expand Up @@ -37,6 +38,8 @@ export default function DashboardSidebar({ options }: DashboardSidebarProps) {
))}
</Accordion>
</S.Contents>

<LogoutButton />
</S.Container>
);
}
2 changes: 2 additions & 0 deletions frontend/src/components/dashboard/DashboardSidebar/style.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import styled from '@emotion/styled';

const Container = styled.div`
position: relative;

width: 20%;
min-width: 25rem;
max-width: 30rem;
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/hooks/useSignOut/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import authApi from '@api/domain/auth';
import { useMutation } from '@tanstack/react-query';
import { useNavigate } from 'react-router-dom';

export default function useSignOut() {
const navigate = useNavigate();

return useMutation({
mutationFn: () => authApi.logout(),
onSuccess: () => {
navigate('/sign-in');
},
});
}
6 changes: 6 additions & 0 deletions frontend/src/mocks/handlers/authHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-promise-executor-return */
import { AUTH } from '@api/endPoint';
import { http } from 'msw';
import { Success } from './response';

interface LoginFormData {
email: string;
Expand Down Expand Up @@ -32,6 +33,11 @@ const authHandlers = [
},
});
}),

http.post(`${AUTH}/logout`, async () => {
await new Promise((resolve) => setTimeout(resolve, 2000));
return Success();
}),
];

export default authHandlers;
Loading