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: 직업 선택 API 연동 #50

Merged
merged 6 commits into from
Aug 29, 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
8 changes: 8 additions & 0 deletions src/app/login/api/usePutUserJob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { http } from '@/apis/http';
import { useMutation } from '@tanstack/react-query';

type JobType = '개발자' | '디자이너';

const putUserJob = async (job: JobType) => http.put({ url: '/users/job', data: { job } });

export const usePutUserJob = () => useMutation({ mutationFn: putUserJob });
18 changes: 15 additions & 3 deletions src/app/login/components/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,25 @@ import { cn } from '@/utils';
import { useState } from 'react';
import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import { usePutUserJob } from '../api/usePutUserJob';

const jobMapper = {
developer: '개발자',
designer: '디자이너',
} as const;

export default function Select() {
const [position, setPosition] = useState<'designer' | 'developer' | ''>('');
const session = useSession();
const { push } = useRouter();
const { mutateAsync } = usePutUserJob();

const handleSubmit = async () => {
if (position === '') return;

await mutateAsync(jobMapper[position]);
push('/');
};

return (
<motion.section
Expand Down Expand Up @@ -66,9 +80,7 @@ export default function Select() {
'bg-neutral-5 rounded-6 py-13 h-48 px-20 w-full text-15 font-semibold text-neutral-30 transition-all',
position !== '' && 'text-white bg-[black]',
)}
onClick={() => {
push('/');
}}>
onClick={handleSubmit}>
선택 완료
</TouchButton>
</motion.section>
Expand Down
2 changes: 2 additions & 0 deletions src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
return session;
},
},

secret: process.env.NEXTAUTH_SECRET,
});

declare module 'next-auth' {
Expand Down
Loading