diff --git a/src/apis/Admin.js b/src/apis/Admin.js index dec3e1a..26a8b65 100644 --- a/src/apis/Admin.js +++ b/src/apis/Admin.js @@ -85,10 +85,10 @@ export const AdminDeleteUser = async (token, params) => { } }; -export const AdminChangePw = async (token, params) => { +export const AdminChangePw = async ( params) => { try { const res = await Axios.post('/api/v1/admin/init-password', params, { - headers: { Authorization: `Bearer ${token}` }, + headers: { }, }); return res.data; diff --git a/src/components/login/LoginForm.js b/src/components/login/LoginForm.js index f3bdec3..b8b3025 100644 --- a/src/components/login/LoginForm.js +++ b/src/components/login/LoginForm.js @@ -1,5 +1,5 @@ import styled from 'styled-components'; -import { useState } from 'react'; +import React, { useState } from 'react'; import LoginModal from './LoginModal'; 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 { TextInput } from '../../styles/Components'; -import { AuthLogin } from '../../apis'; +import { AdminChangePw, AuthLogin } from '../../apis'; import { useForm } from 'react-hook-form'; 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 { t } = useTranslation(); + const navigate = useNavigate(); const [stateModal, setStateModal] = useState('hidden'); const [errorText, setErrorText] = useState(''); - const navigate = useNavigate(); + const [toast, setToast] = useState(null) + const [isLoading, setIsLoading] = useState(false); const handleModal = () => { if (stateModal === 'hidden') { @@ -28,6 +36,25 @@ const LoginForm = () => { 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 result = await AuthLogin(data); 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 ( <> @@ -93,15 +138,37 @@ const LoginForm = () => { text="확인" theme="line" size="large" - width="100%" + width="50%" handleClick={e => { e.preventDefault(); handleModal('hidden'); }} /> +