-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from softeerbootcamp4th/feature/32-admincomment
[feat] 어드민 기대평 페이지 구현
- Loading branch information
Showing
7 changed files
with
160 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { useMutation } from "@common/dataFetch/getQuery.js"; | ||
import openModal from "@common/modal/openModal.js"; | ||
import { fetchServer } from "@common/dataFetch/fetchServer.js"; | ||
import ConfirmModal from "@admin/modals/ConfirmModal.jsx"; | ||
import AlertModal from "@admin/modals/AlertModal.jsx"; | ||
|
||
export default function DeleteButton({ | ||
eventId, | ||
checkedComments, | ||
setCheckedComments, | ||
}) { | ||
const num = checkedComments.size; | ||
const mutation = useMutation(eventId, () => | ||
fetchServer("/api/v1/admin/comments", { | ||
method: "DELETE", | ||
body: { | ||
commentIds: [...checkedComments], | ||
}, | ||
}) | ||
.then(() => { | ||
openModal( | ||
<AlertModal title="삭제" description="기대평이 삭제되었습니다." />, | ||
); | ||
setCheckedComments(new Set()); | ||
}) | ||
.catch((e) => { | ||
alert("삭제 실패"); | ||
console.log(e); | ||
}), | ||
); | ||
|
||
const deleteConfirmModal = ( | ||
<ConfirmModal | ||
title="삭제" | ||
description={ | ||
<> | ||
<span>이 동작은 다시 돌이킬 수 없습니다.</span> | ||
<br /> | ||
<span>{num}개의 기대평을 삭제하시겠습니까?</span> | ||
</> | ||
} | ||
onConfirm={mutation} | ||
/> | ||
); | ||
|
||
function deleteComments() { | ||
if (!num) return; | ||
openModal(deleteConfirmModal); | ||
} | ||
|
||
return ( | ||
<button | ||
onClick={deleteComments} | ||
className="self-end px-5 py-1 bg-red-300 text-white hover:bg-red-500 rounded-lg" | ||
> | ||
삭제 | ||
</button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default function getRandomString(len) { | ||
/* 한글 | ||
const startCode = 0xac00; | ||
const endCode = 0xd7a3; | ||
*/ | ||
const startCode = 0x0750; | ||
const endCode = 0x077f; | ||
|
||
let str = ""; | ||
for (let i = 0; i < len; i++) { | ||
const randomCode = | ||
Math.floor(Math.random() * (endCode - startCode + 1)) + startCode; | ||
str += String.fromCharCode(randomCode); | ||
} | ||
|
||
return str; | ||
} |