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
15 changes: 7 additions & 8 deletions pages/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import InputField from '@/components/Input';
import SnackBar from '@/components/SnackBar';
import { AuthAPI } from '@/services/api/auth';

function Login(): React.ReactElement {
export default function Login() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [isSubmitting, setIsSubmitting] = useState(false);
Expand Down Expand Up @@ -39,11 +39,12 @@ function Login(): React.ReactElement {

const isFormValid = validFields.email && validFields.password;

const handleSubmit = async (e: React.FormEvent) => {
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (isSubmitting || !isFormValid) return;

setIsSubmitting(true);

try {
const response = (await AuthAPI.signin({
email,
Expand All @@ -55,10 +56,10 @@ function Login(): React.ReactElement {
setSnackbarSeverity('success');
setSnackbarOpen(true);

// 3초 후 메인 페이지로 이동
// 페이지 이동 전까지는 버튼을 비활성화 상태로 유지
setTimeout(() => {
router.push('/');
}, 3000);
}, 1000);
} catch (error) {
if (error instanceof Error) {
setSnackbarMessage(error.message);
Expand All @@ -69,7 +70,7 @@ function Login(): React.ReactElement {
setSnackbarSeverity('fail');
setSnackbarOpen(true);
}
} finally {
// 에러가 발생한 경우에만 isSubmitting을 false로 변경
setIsSubmitting(false);
}
};
Expand Down Expand Up @@ -101,7 +102,7 @@ function Login(): React.ReactElement {
/>
<Button
type="submit"
disabled={!isFormValid}
disabled={!isFormValid || isSubmitting}
isLoading={isSubmitting}
variant="primary"
className="mt-[6px] h-[45px] w-full"
Expand Down Expand Up @@ -130,5 +131,3 @@ function Login(): React.ReactElement {
</div>
);
}

export default Login;
80 changes: 43 additions & 37 deletions pages/mypage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import Button from '@/components/Button';
import InputField from '@/components/Input';
import SnackBar from '@/components/SnackBar';
import { useValidation } from '@/hooks/useValidation';
import { useProfileContext } from '@/hooks/useProfileContext';
import { AuthAPI } from '@/services/api/auth';
import { ProfileAPI } from '@/services/api/profileAPI';
import { AxiosError } from 'axios';

function MyPage(): React.ReactElement {
const { profile } = useProfileContext();
const [currentPassword, setCurrentPassword] = useState('');
const [newPassword, setNewPassword] = useState('');
const [newPasswordConfirm, setNewPasswordConfirm] = useState('');
Expand Down Expand Up @@ -210,44 +212,48 @@ function MyPage(): React.ReactElement {
</div>
</div>
</form>
<div className="w-[400px] border-b border-gray-200 mo:w-[335px]"></div>
{/* 위키 생성 폼 */}
<form
onSubmit={handleWikiSubmit}
className="flex w-[400px] flex-col items-center gap-[32px] mo:w-[335px]"
>
<div className={inputSectionStyle}>
<div className={inputContainerStyle}>
<InputField
label="위키 생성하기"
type="text"
value={question}
width="100%"
onChange={handleQuestionChange}
placeholder="질문을 입력해 주세요"
/>
<InputField
label=""
type="text"
value={answer}
width="100%"
onChange={handleAnswerChange}
placeholder="답을 입력해 주세요"
/>
{/* 위키가 없을 때만 구분선과 위키 생성 폼 표시 */}
{!profile?.code && (
<>
<div className="w-[400px] border-b border-gray-200 mo:w-[335px]"></div>
<form
onSubmit={handleWikiSubmit}
className="flex w-[400px] flex-col items-center gap-[32px] mo:w-[335px]"
>
<div className={inputSectionStyle}>
<div className={inputContainerStyle}>
<InputField
label="위키 생성하기"
type="text"
value={question}
width="100%"
onChange={handleQuestionChange}
placeholder="질문을 입력해 주세요"
/>
<InputField
label=""
type="text"
value={answer}
width="100%"
onChange={handleAnswerChange}
placeholder="답을 입력해 주세요"
/>

<Button
type="submit"
disabled={!isWikiFormValid}
isLoading={Boolean(isWikiSubmitting)}
variant="primary"
size="small"
className="mt-[8px] self-end"
>
생성하기
</Button>
</div>
</div>
</form>
<Button
type="submit"
disabled={!isWikiFormValid}
isLoading={Boolean(isWikiSubmitting)}
variant="primary"
size="small"
className="mt-[8px] self-end"
>
생성하기
</Button>
</div>
</div>
</form>
</>
)}
</div>
<SnackBar
open={snackbarOpen}
Expand Down
10 changes: 10 additions & 0 deletions services/api/profileAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ export const ProfileAPI = {
handleApiError(error);
}
},

// 현재 로그인한 사용자의 프로필 정보를 조회
getProfile: async () => {
try {
const res = await instance.get('/users/me');
return res.data.profile;
} catch (error) {
handleApiError(error);
}
},
};

// 위키 목록 페이지 요청 파라미터 타입
Expand Down
Loading