bordใฎๅคๆด๐ฅ
2438 ใฏใผใ
ไปฅๅใฎใณใผใใฏใในใฆใฎใใผใฟใๅคๆดใใฆ่ช่ญใใๅฟ ่ฆใใใใพใ
//๋ฐ์ดํฐ๋ฅผ ๋ชจ๋ ๋ฐ๊ฟ์ผ ์ธ์ํ๋ ์์ ์ฝ๋
const editSubmit = async() => {
if (myWriter && myPassword && myTitle && myContents) {
try {
await updateBoard({
variables: {
updateBoardInput:{title: myTitle, contents: myContents},
password: myPassword,
boardId: String(router.query.aaa)}
})
console.log(router.query.aaa)
router.push(`/boards/${router.query.aaa}`)
alert ("๊ฒ์๋ฌผ์ด ์์ ๋์์ต๋๋ค")
} catch(error) {
console.log("์๋ฌ์
๋๋ค")
// try~catch ; try์์์ ์๋ฌ๋๋ฉด ๋ฉ์ถ๊ณ catch ์คํ, ์๋ฌ ์๋๋ฉด catch ์คํต
}
} if (!myWriter) {
setMyWriterError ("์
๋ ฅ๋์ง ์์์ต๋๋ค")
alert ("์์ฑ์๊ฐ ์
๋ ฅ๋์ง ์์์ต๋๋ค")
router.push(`/boards/${router.query.aaa}`)
} if (!myPassword) {
setMyPasswordError ("์
๋ ฅ๋์ง ์์์ต๋๋ค")
alert ("๋น๋ฐ๋ฒํธ๊ฐ ์
๋ ฅ๋์ง ์์์ต๋๋ค")
} if (!myTitle) {
setMyTitleError ("์
๋ ฅ๋์ง ์์์ต๋๋ค")
alert ("์ ๋ชฉ์ด ์
๋ ฅ๋์ง ์์์ต๋๋ค")
} if (!myContents) {
setMyContentsError ("์
๋ ฅ๋์ง ์์์ต๋๋ค")
alert ("๋ด์ฉ์ด ์
๋ ฅ๋์ง ์์์ต๋๋ค")
}
}
ๆชๅคๆดใฎใใผใฟใใใฃใฆใๆญฃๅธธใซๅไฝใใใณใผใ
// ๊ฐ์ ์์ ํ์ง ์์๋ ์ด์ ์ ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ฌ ์ ์๋ค~!
const editSubmit = async() => {
if (!myTitle && !myContents) {
alert("์ ๋ชฉ์ด๋ ๋ด์ฉ์ด ์์ ๋์ง ์์์ต๋๋ค")
return // ์ฌ๊ธฐ์ ๋! break ๊ธฐ๋ฅ
}
if (!myPassword) {
alert("๋น๋ฐ๋ฒํธ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์")
return
}
const myUpdateBoardInput = { } // ๋น๊ฐ์ผ๋ก ์ค์
if (myTitle) myUpdateBoardInput.title = myTitle // ๋ฐ๋ ๋ด์ฉ์ ๋ฃ์ด์ฃผ๊ธฐ
if (myContents) myUpdateBoardInput.contents = myContents // ๋ฐ๋ ๋ด์ฉ ๋ฃ์ด์ฃผ๊ธฐ
try {
updateBoard({
variables: { password : myPassword,
boardId : String(router.query.aaa),
updateBoardInput : myUpdateBoardInput}
})
alert("๊ฒ์๋ฌผ์ด ์์ ๋์์ต๋๋ค")
router.push(`/boards/${router.query.aaa}`)
} catch(error) {
console.log(error.message)
}
}
Reference
ใใฎๅ้กใซใคใใฆ(bordใฎๅคๆด๐ฅ), ๆใ ใฏใใใๅคใใฎๆ ๅ ฑใใใใง่ฆใคใใพใใ https://velog.io/@wisdoom03/board-์์ ํ๊ธฐใใญในใใฏ่ช็ฑใซๅ ฑๆใพใใฏใณใใผใงใใพใใใใ ใใใใฎใใญใฅใกใณใใฎURLใฏๅ่URLใจใใฆๆฎใใฆใใใฆใใ ใใใ
Collection and Share based on the CC Protocol