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