로그인 비밀번호 초기화 추가
This commit is contained in:
@@ -85,10 +85,10 @@ export const AdminDeleteUser = async (token, params) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const AdminChangePw = async (token, params) => {
|
export const AdminChangePw = async ( params) => {
|
||||||
try {
|
try {
|
||||||
const res = await Axios.post('/api/v1/admin/init-password', params, {
|
const res = await Axios.post('/api/v1/admin/init-password', params, {
|
||||||
headers: { Authorization: `Bearer ${token}` },
|
headers: { },
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.data;
|
return res.data;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
import LoginModal from './LoginModal';
|
import LoginModal from './LoginModal';
|
||||||
import Button from '../../components/common/button/Button';
|
import Button from '../../components/common/button/Button';
|
||||||
@@ -7,14 +7,22 @@ import Modal from '../common/modal/Modal';
|
|||||||
|
|
||||||
import { Title, BtnWrapper, ButtonClose } from '../../styles/Components';
|
import { Title, BtnWrapper, ButtonClose } from '../../styles/Components';
|
||||||
import { TextInput } from '../../styles/Components';
|
import { TextInput } from '../../styles/Components';
|
||||||
import { AuthLogin } from '../../apis';
|
import { AdminChangePw, AuthLogin } from '../../apis';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { authList } from '../../store/authList';
|
||||||
|
import { alertTypes } from '../../assets/data/types';
|
||||||
|
import ToastAlert from '../common/alert/ToastAlert';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import Loading from '../common/Loading';
|
||||||
|
|
||||||
const LoginForm = () => {
|
const LoginForm = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const navigate = useNavigate();
|
||||||
const [stateModal, setStateModal] = useState('hidden');
|
const [stateModal, setStateModal] = useState('hidden');
|
||||||
const [errorText, setErrorText] = useState('');
|
const [errorText, setErrorText] = useState('');
|
||||||
const navigate = useNavigate();
|
const [toast, setToast] = useState(null)
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
const handleModal = () => {
|
const handleModal = () => {
|
||||||
if (stateModal === 'hidden') {
|
if (stateModal === 'hidden') {
|
||||||
@@ -28,6 +36,25 @@ const LoginForm = () => {
|
|||||||
|
|
||||||
const values = watch();
|
const values = watch();
|
||||||
|
|
||||||
|
const showToast = (message, type = alertTypes.info) => {
|
||||||
|
const toastData = {
|
||||||
|
id: Date.now(),
|
||||||
|
message,
|
||||||
|
type,
|
||||||
|
position: 'top-center'
|
||||||
|
};
|
||||||
|
setToast(toastData);
|
||||||
|
|
||||||
|
// 5초 후 자동으로 토스트 제거
|
||||||
|
setTimeout(() => {
|
||||||
|
setToast(null);
|
||||||
|
}, 5000);
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeToast = () => {
|
||||||
|
setToast(null);
|
||||||
|
};
|
||||||
|
|
||||||
const onSubmit = async data => {
|
const onSubmit = async data => {
|
||||||
const result = await AuthLogin(data);
|
const result = await AuthLogin(data);
|
||||||
setErrorText(result.data.message);
|
setErrorText(result.data.message);
|
||||||
@@ -45,6 +72,24 @@ const LoginForm = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handlePasswordInit = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
await AdminChangePw({ email: values.email })
|
||||||
|
.then(res => {
|
||||||
|
if (res.status === 200) {
|
||||||
|
showToast(t('PASSWORD_INIT_COMPLETE'), alertTypes.success);
|
||||||
|
} else {
|
||||||
|
showToast(t('PASSWORD_INIT_ERROR'), alertTypes.error);
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
showToast(t('API_FAIL'), alertTypes.error);
|
||||||
|
}).finally(() => {
|
||||||
|
setIsLoading(false);
|
||||||
|
handleModal('hidden');
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FormWrapper action="" $flow="column" onSubmit={handleSubmit(onSubmit)}>
|
<FormWrapper action="" $flow="column" onSubmit={handleSubmit(onSubmit)}>
|
||||||
@@ -93,15 +138,37 @@ const LoginForm = () => {
|
|||||||
text="확인"
|
text="확인"
|
||||||
theme="line"
|
theme="line"
|
||||||
size="large"
|
size="large"
|
||||||
width="100%"
|
width="50%"
|
||||||
handleClick={e => {
|
handleClick={e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
handleModal('hidden');
|
handleModal('hidden');
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
<Button
|
||||||
|
text="비밀번호 초기화"
|
||||||
|
theme="line"
|
||||||
|
size="large"
|
||||||
|
width="50%"
|
||||||
|
handleClick={e => {
|
||||||
|
e.preventDefault();
|
||||||
|
handlePasswordInit();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</BtnWrapper>
|
</BtnWrapper>
|
||||||
</Modal>
|
</Modal>
|
||||||
)}
|
)}
|
||||||
|
{toast && (
|
||||||
|
<ToastAlert
|
||||||
|
key={toast.id}
|
||||||
|
id={toast.id}
|
||||||
|
message={toast.message}
|
||||||
|
type={toast.type}
|
||||||
|
position={toast.position}
|
||||||
|
onClose={closeToast}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{isLoading && <Loading />}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user