Skip to content
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 src/features/join/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './join';
34 changes: 34 additions & 0 deletions src/features/join/api/join.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useSetAtom } from 'jotai';
import { useMutation } from '@tanstack/react-query';

import { post, REQUEST } from '@/shared/api';
import { RAW_PATH } from '@/shared/constants';
import { replace } from '@/shared/utils';
import { userTokenAtom } from '@/shared/atom';
import type { Token, User } from '@/shared/types';

const submitUserJoin = async (data: User) => {
const response = await post<User, Token>({
request: REQUEST.JOIN,
data: data,
});
return response.data;
};

export const useUserJoin = () => {
const setUserToken = useSetAtom(userTokenAtom);
return useMutation<Token, Error, { data: User }>({
mutationFn: ({ data }) => submitUserJoin(data),
onSuccess: data => {
const accessToken = data.accessToken;
setUserToken({
accessToken: accessToken,
});
replace(RAW_PATH.SIGNUP_LOADING);
},
onError: () => {
alert('회원가입에 실패했어요. 다시 시도해 주세요!');
replace(RAW_PATH.HOME);
},
});
};
69 changes: 69 additions & 0 deletions src/features/join/ui/JoinForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { useAtomValue, useSetAtom } from 'jotai';
import { useForm } from 'react-hook-form';

import { userEmailAtom, userModeAtom } from '@/shared/atom';
import { Button, Input } from '@/shared/ui';
import type { User } from '@/shared/types';
import { useUserJoin } from '../api';

export default function JoinForm() {
const setUserMode = useSetAtom(userModeAtom);
const { kakaoEmail } = useAtomValue(userEmailAtom);
const { mutate } = useUserJoin();
const { register, handleSubmit } = useForm<User>({
defaultValues: {
kakaoEmail: kakaoEmail,
name: '',
collegeMajorName: '컴퓨터공학전공',
studentEmail: 'faker@kyonggi.ac.kr',
walletAddress: '0x1234abcd5678',
keyId: 'kas-key-id',
krn: 'krn:1001:abcd',
},
});

return (
<form
className="flex flex-col gap-y-12"
onSubmit={handleSubmit(data => {
mutate({ data });
})}
>
<div className="w-full space-y-3">
<Input
intent="login"
placeholder="이름"
{...register('name', { required: true })}
/>
<Input intent="login" placeholder="비밀번호" type="password" />
</div>
<div className="space-y-3">
<div className="flex items-center gap-3">
<div className="bg-s h-[0.5px] flex-1" />
<span className="text-s text-sm">가입 방식</span>
<div className="bg-s h-[0.5px] flex-1" />
</div>
<Button
intent="login"
className="py-[14px] text-lg"
type="submit"
onClick={() => {
setUserMode({ mode: 'STUDENT' as const });
}}
>
학생으로 시작하기
</Button>
<Button
intent="loginWhite"
className="py-[14px] text-lg"
type="submit"
onClick={() => {
setUserMode({ mode: 'ADMIN' as const });
}}
>
관리자로 시작하기
</Button>
</div>
</form>
);
}
1 change: 1 addition & 0 deletions src/features/join/ui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as JoinForm } from './JoinForm';
53 changes: 0 additions & 53 deletions src/screen/auth/api/auth.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,3 @@
// import { useMutation } from '@tanstack/react-query';

// import { post, REQUEST } from '@/shared/api';
// import { RAW_PATH } from '@/shared/constants';
// import { replace } from '@/shared/utils';
// import { userTokenAtom } from '@/shared/atom';
// import { useSetAtom } from 'jotai';

// interface KakaoLoginRequest {
// code: string;
// }

// interface KakaoLoginResponse {
// kakaoEmail: string;
// tokenDto: {
// grantType: string;
// accessToken: string;
// accessTokenExpiresIn: number;
// refreshToken: string;
// };
// signedUp: boolean;
// }

// const submitKakaoLogin = async (code: string) => {
// const response = await post<KakaoLoginRequest, KakaoLoginResponse>({
// request: REQUEST.LOGIN,
// data: { code: code },
// });
// return response.data;
// };

// export const useKakaoLogin = () => {
// const setKakaoLogin = useSetAtom(userTokenAtom);
// return useMutation<KakaoLoginResponse, Error, { code: string }>({
// mutationFn: ({ code }) => submitKakaoLogin(code),
// onSuccess: data => {
// const kakaoAccessToken = data.tokenDto.accessToken;
// setKakaoLogin({
// accessToken: kakaoAccessToken,
// });
// if (data.signedUp) replace(RAW_PATH.HOME);
// else {
// alert('회원가입 화면으로 이동합니다!');
// replace(RAW_PATH.SIGNUP);
// }
// },
// onError: () => {
// alert('로그인에 실패했어요. 다시 시도해 주세요!');
// replace(RAW_PATH.HOME);
// },
// });
// };

import { useQuery } from '@tanstack/react-query';

import { get, REQUEST } from '@/shared/api';
Expand Down
2 changes: 1 addition & 1 deletion src/screen/auth/ui/AuthScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LoginBg } from '@/assets/image';
import { replace } from '@/shared/utils';
import { RAW_PATH } from '@/shared/constants';
import { userEmailAtom, userTokenAtom } from '@/shared/atom';
import Loader from '@/shared/ui/Loader';
import { Loader } from '@/shared/ui';

export default function AuthScreen() {
const setUserToken = useSetAtom(userTokenAtom);
Expand Down
7 changes: 7 additions & 0 deletions src/shared/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ export type User = {
keyId: string;
krn: string;
};

export type Token = {
grantType: string;
accessToken: string;
accessTokenExpiresIn: number;
refreshToken: string;
};
1 change: 1 addition & 0 deletions src/shared/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { default as Button } from './Button';
export { default as Card } from './Card';
export { default as DateBadge } from './DateBadge';
export { default as Input } from './Input';
export { default as Loader } from './Loader';
40 changes: 2 additions & 38 deletions src/widgets/join/ui/JoinContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { userModeAtom } from '@/shared/atom';
import { RAW_PATH } from '@/shared/constants';
import { Button, Input } from '@/shared/ui';
import { replace } from '@/shared/utils';
import { useSetAtom } from 'jotai';
import { JoinForm } from '@/features/join/ui';

export default function LoginContainer() {
const setUserMode = useSetAtom(userModeAtom);
return (
<div className="p-normal z-10 grid size-full place-items-center">
<div className="shadow-login box-border grid h-[530px] w-full place-items-center rounded-lg border-[1px] border-white bg-white/50 p-6 backdrop-blur-sm">
Expand All @@ -15,38 +10,7 @@ export default function LoginContainer() {
<br />
선거에 참여할 수 있어요!
</p>
<div className="w-full space-y-3">
<Input intent="login" placeholder="학번" />
<Input intent="login" placeholder="비밀번호" type="password" />
</div>

<div className="space-y-3">
<div className="flex items-center gap-3">
<div className="bg-s h-[0.5px] flex-1" />
<span className="text-s text-sm">가입 방식</span>
<div className="bg-s h-[0.5px] flex-1" />
</div>
<Button
intent="login"
className="py-[14px] text-lg"
onClick={() => {
setUserMode({ mode: 'STUDENT' as const });
replace(RAW_PATH.SIGNUP_LOADING);
}}
>
학생으로 시작하기
</Button>
<Button
intent="loginWhite"
className="py-[14px] text-lg"
onClick={() => {
setUserMode({ mode: 'ADMIN' as const });
replace(RAW_PATH.SIGNUP_LOADING);
}}
>
관리자로 시작하기
</Button>
</div>
<JoinForm />
</div>
</div>
</div>
Expand Down