[QCAST] promisePatch 추가 및 promise 사용 부분(가입, 비밀번호변경, 파일다운로드 등) 적용
This commit is contained in:
parent
b97f372f62
commit
b18280803d
@ -7,7 +7,7 @@ import Cookies from 'js-cookie'
|
||||
|
||||
export default function Join() {
|
||||
const { getMessage } = useMessage()
|
||||
const { post } = useAxios()
|
||||
const { promisePost } = useAxios()
|
||||
const router = useRouter()
|
||||
|
||||
// 가입 신청
|
||||
@ -34,16 +34,20 @@ export default function Join() {
|
||||
},
|
||||
}
|
||||
|
||||
await post({ url: '/api/login/v1.0/user/join', data: param }).then((res) => {
|
||||
if (res) {
|
||||
if (res.result.resultCode == 'S') {
|
||||
Cookies.set('joinEmail', formData.get('email'), { expires: 1 })
|
||||
router.push('/join/complete')
|
||||
} else {
|
||||
alert(res.result.resultMsg)
|
||||
await promisePost({ url: '/api/login/v1.0/user/join', data: param })
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
if (res.result.resultCode == 'S') {
|
||||
Cookies.set('joinEmail', formData.get('email'), { expires: 1 })
|
||||
router.push('/join/complete')
|
||||
} else {
|
||||
alert(res.result.resultMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
alert(error.response.data.message)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@ -34,7 +34,7 @@ export default function Login() {
|
||||
|
||||
const [passwordReset, setPasswordReset] = useState(1)
|
||||
|
||||
const { post, patch } = useAxios(globalLocaleState)
|
||||
const { promisePost, promisePatch } = useAxios(globalLocaleState)
|
||||
|
||||
// login process
|
||||
const loginProcess = async (e) => {
|
||||
@ -88,26 +88,27 @@ export default function Login() {
|
||||
// loginId: formData.get('id'),
|
||||
// pwd: formData.get('password'),
|
||||
// }
|
||||
|
||||
// const res = await post({ url: '/api/login/v1.0/login', data: param })
|
||||
|
||||
// if (res) {
|
||||
// if (res.result.resultCode == 'S') {
|
||||
// setSession(res.data)
|
||||
// setSessionState(res.data)
|
||||
|
||||
// // ID SAVE 체크되어 있는 경우, 쿠키 저장
|
||||
// if (chkLoginId) {
|
||||
// Cookies.set('chkLoginId', formData.get('id'), { expires: 7 })
|
||||
// } else {
|
||||
// Cookies.remove('chkLoginId')
|
||||
// await promisePost({ url: '/api/login/v1.0/login', data: param })
|
||||
// .then((res) => {
|
||||
// if (res) {
|
||||
// if (res.result.resultCode == 'S') {
|
||||
// setSession(res.data)
|
||||
// setSessionState(res.data)
|
||||
// // ID SAVE 체크되어 있는 경우, 쿠키 저장
|
||||
// if (chkLoginId) {
|
||||
// Cookies.set('chkLoginId', formData.get('id'), { expires: 7 })
|
||||
// } else {
|
||||
// Cookies.remove('chkLoginId')
|
||||
// }
|
||||
// router.push('/')
|
||||
// } else {
|
||||
// alert(res.result.resultMsg)
|
||||
// }
|
||||
// }
|
||||
|
||||
// router.push('/')
|
||||
// } else {
|
||||
// alert(res.result.resultMsg)
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// alert(error.response.data.message)
|
||||
// })
|
||||
}
|
||||
|
||||
// 비밀번호 초기화 관련
|
||||
@ -117,21 +118,25 @@ export default function Login() {
|
||||
email: checkEmail,
|
||||
}
|
||||
|
||||
const res = await patch({
|
||||
await promisePatch({
|
||||
url: '/api/login/v1.0/user/init-password',
|
||||
data: param,
|
||||
})
|
||||
|
||||
if (res) {
|
||||
if (res.result.resultCode == 'S') {
|
||||
alert(getMessage('login.init_password.complete_message'))
|
||||
setCheckId('')
|
||||
setCheckEmail('')
|
||||
setPasswordReset(1)
|
||||
} else {
|
||||
alert(res.result.resultMsg)
|
||||
}
|
||||
}
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
if (res.result.resultCode == 'S') {
|
||||
alert(getMessage('login.init_password.complete_message'))
|
||||
setCheckId('')
|
||||
setCheckEmail('')
|
||||
setPasswordReset(1)
|
||||
} else {
|
||||
alert(res.result.resultMsg)
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
alert(error.response.data.message)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@ -8,7 +8,7 @@ export default function UserInfoModal({ userId, userInfoModal, setUserInfoModal
|
||||
const { getMessage } = useMessage()
|
||||
|
||||
// api 조회 관련
|
||||
const { get, patch } = useAxios()
|
||||
const { get, promisePatch } = useAxios()
|
||||
const [info, setInfo] = useState({
|
||||
userId: '',
|
||||
password: '',
|
||||
@ -69,16 +69,20 @@ export default function UserInfoModal({ userId, userInfoModal, setUserInfoModal
|
||||
|
||||
const params = { loginId: info.userId, chgType: 'C', pwd: password, chgPwd: chgPwd }
|
||||
|
||||
await patch({ url: '/api/login/v1.0/user/change-password', data: params }).then((res) => {
|
||||
if (res) {
|
||||
if (res.result.resultCode === 'S') {
|
||||
alert(getMessage('myinfo.message.save'))
|
||||
setChkChgPwd(false)
|
||||
} else {
|
||||
alert(res.result.resultMsg)
|
||||
await promisePatch({ url: '/api/login/v1.0/user/change-password', data: params })
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
if (res.result.resultCode === 'S') {
|
||||
alert(getMessage('myinfo.message.save'))
|
||||
setChkChgPwd(false)
|
||||
} else {
|
||||
alert(res.result.resultMsg)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
alert(error.response.data.message)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@ -80,6 +80,10 @@ export function useAxios(lang = '') {
|
||||
.catch(console.error)
|
||||
}
|
||||
|
||||
const promisePatch = async ({ url, data }) => {
|
||||
return await getInstances(url).patch(url, data)
|
||||
}
|
||||
|
||||
const del = async ({ url }) => {
|
||||
return await getInstances(url)
|
||||
.delete(url)
|
||||
@ -91,5 +95,5 @@ export function useAxios(lang = '') {
|
||||
return await getInstances(url).delete(url)
|
||||
}
|
||||
|
||||
return { get, promiseGet, post, promisePost, put, promisePut, patch, del, promiseDel }
|
||||
return { get, promiseGet, post, promisePost, put, promisePut, patch, promisePatch, del, promiseDel }
|
||||
}
|
||||
|
||||
@ -2,27 +2,31 @@ import { useAxios } from '@/hooks/useAxios'
|
||||
|
||||
// 파일 다운로드
|
||||
export const handleFileDown = async (file) => {
|
||||
const { get } = useAxios()
|
||||
const { promiseGet } = useAxios()
|
||||
|
||||
const url = `/api/board/file/download`
|
||||
const params = new URLSearchParams({
|
||||
encodeFileNo: file.encodeFileNo,
|
||||
})
|
||||
const apiUrl = `${url}?${params.toString()}`
|
||||
const resultData = await get({ url: apiUrl })
|
||||
await promiseGet({ url: apiUrl })
|
||||
.then((resultData) => {
|
||||
if (resultData) {
|
||||
const blob = new Blob([resultData])
|
||||
const fileUrl = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
|
||||
if (resultData) {
|
||||
const blob = new Blob([resultData])
|
||||
const fileUrl = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
|
||||
link.href = fileUrl
|
||||
link.download = file.srcFileNm
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
window.URL.revokeObjectURL(url)
|
||||
}
|
||||
link.href = fileUrl
|
||||
link.download = file.srcFileNm
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
window.URL.revokeObjectURL(url)
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
alert(error.response.data.message)
|
||||
})
|
||||
}
|
||||
|
||||
// 페이지 번호 생성
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user