Skip to content

Commit 8fdfc96

Browse files
committed
Merge remote-tracking branch 'origin/develop' into 138-fix-sebin
2 parents 403ecc3 + 90282b6 commit 8fdfc96

File tree

8 files changed

+79
-17
lines changed

8 files changed

+79
-17
lines changed

src/apis/admin.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ const postBadWords = async (badWordsRequest: BadWords) => {
6363
}
6464
};
6565

66-
// 내 상상대로 만든 필터링 단어 취소 버튼
67-
const patchBadWordsUsed = async (badWordId: string) => {
66+
const patchBadWordsUsed = async (badWordId: string, isUsed: string) => {
67+
const reverseIsUsed = isUsed === 'true' ? false : true;
68+
6869
try {
69-
const res = await client.patch(`/api/bad-words/${badWordId}/status`, { isUsed: false });
70-
if (!res) throw new Error('검열 단어 삭제 도중 에러가 발생했습니다.');
70+
const res = await client.patch(`/api/bad-words/${badWordId}/status`, { isUsed: reverseIsUsed });
71+
if (!res) throw new Error('검열 활성화/비활성화 도중 에러가 발생했습니다.');
7172
console.log(res);
7273
return res;
7374
} catch (error) {
@@ -78,7 +79,18 @@ const patchBadWordsUsed = async (badWordId: string) => {
7879
const patchBadWords = async (badWordId: string, word: string) => {
7980
try {
8081
const res = await client.patch(`/api/bad-words/${badWordId}`, { word: word });
81-
if (!res) throw new Error('검열 단어 삭제 도중 에러가 발생했습니다.');
82+
if (!res) throw new Error('금칙어 수정중 에러가 발생했습니다.');
83+
console.log(res);
84+
return res;
85+
} catch (error) {
86+
console.error(error);
87+
}
88+
};
89+
90+
const deleteBadWords = async (id: string) => {
91+
try {
92+
const res = await client.delete(`/api/bad-words/${id}`);
93+
if (!res) throw new Error('금칙어 삭제 도중 에러가 발생했습니다.');
8294
console.log(res);
8395
return res;
8496
} catch (error) {
@@ -94,4 +106,5 @@ export {
94106
postBadWords,
95107
patchBadWordsUsed,
96108
patchBadWords,
109+
deleteBadWords,
97110
};

src/pages/Admin/Filtering.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useState } from 'react';
22

3-
import { getBadWords, patchBadWordsUsed } from '@/apis/admin';
4-
import { AddIcon, AlarmIcon, CancelIcon } from '@/assets/icons';
3+
import { getBadWords } from '@/apis/admin';
4+
import { AddIcon, AlarmIcon } from '@/assets/icons';
55

66
import AddInputButton from './components/AddInputButton';
77
import AdminPageTitle from './components/AdminPageTitle';

src/pages/Admin/components/AddInputButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default function AddInputButton({
2323
if (inputText.word === '') return setAddInputShow(false);
2424
const res = await postBadWords(inputText);
2525
if (res?.status === 200) {
26-
setBadWords((cur) => [...cur, res.data.data]);
26+
setBadWords((cur) => [...cur, { ...res.data.data, isUsed: `${res.data.data.isUsed}` }]);
2727
setAddInputShow(false);
2828
}
2929
};

src/pages/Admin/components/FilterTextItem.tsx

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { patchBadWordsUsed } from '@/apis/admin';
1+
import { deleteBadWords, patchBadWordsUsed } from '@/apis/admin';
22
import { DeleteIcon, PencilIcon, ToggleOff, ToggleOn } from '@/assets/icons';
33
import { useState } from 'react';
44
import PatchInput from './PatchInput';
5+
import { twMerge } from 'tailwind-merge';
56

67
export default function FilterTextItem({
78
badWord,
@@ -12,8 +13,47 @@ export default function FilterTextItem({
1213
}) {
1314
const [patchInputShow, setPatchInputShow] = useState<boolean>(false);
1415

16+
const handleDeleteBadWords = async (id: string) => {
17+
const res = await deleteBadWords(id);
18+
if (res?.status === 200) {
19+
setBadWords((cur) =>
20+
cur.filter((e) => {
21+
if (e.id === id) {
22+
return null;
23+
}
24+
return e;
25+
}),
26+
);
27+
}
28+
};
29+
30+
const handlePatchBadWordsUsed = async (id: string, isUsed: string) => {
31+
const res = await patchBadWordsUsed(id, isUsed);
32+
if (res?.status === 200) {
33+
setBadWords((cur) =>
34+
cur.map((e) => {
35+
if (e.id === id) {
36+
let reverseIsUsed: string;
37+
if (e.isUsed === 'true') {
38+
reverseIsUsed = 'false';
39+
} else {
40+
reverseIsUsed = 'true';
41+
}
42+
return { ...e, isUsed: reverseIsUsed };
43+
}
44+
return e;
45+
}),
46+
);
47+
}
48+
};
49+
50+
const buttonStyle = twMerge(
51+
`flex items-center gap-1.5 rounded-2xl px-4 py-1.5`,
52+
badWord.isUsed === 'true' ? 'bg-primary-3' : 'bg-[#c1c1c1]',
53+
);
54+
1555
return (
16-
<span className="bg-primary-3 flex items-center gap-1.5 rounded-2xl px-4 py-1.5">
56+
<span className={buttonStyle}>
1757
{patchInputShow ? (
1858
<PatchInput
1959
badWordId={badWord.id}
@@ -28,12 +68,20 @@ export default function FilterTextItem({
2868
<PencilIcon className="h-4 w-4" />
2969
</button>
3070

31-
<button onClick={() => {}}>
71+
<button
72+
onClick={() => {
73+
handleDeleteBadWords(badWord.id);
74+
}}
75+
>
3276
<DeleteIcon className="h-5 w-5" />
3377
</button>
3478

35-
<button onClick={() => patchBadWordsUsed(badWord.id)}>
36-
{true ? <ToggleOn className="h-5 w-5" /> : <ToggleOff className="h-5 w-5" />}
79+
<button onClick={() => handlePatchBadWordsUsed(badWord.id, badWord.isUsed)}>
80+
{badWord.isUsed === 'true' ? (
81+
<ToggleOn className="h-5 w-5" />
82+
) : (
83+
<ToggleOff className="h-5 w-5" />
84+
)}
3785
</button>
3886
</span>
3987
);

src/pages/Admin/components/Sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export default function Sidebar() {
5656
</section>
5757
<button className="mt-auto flex w-full items-center gap-3 px-5 py-3 hover:bg-amber-100">
5858
<AlarmIcon className="text-gray-80 h-5 w-5" />
59-
<span className="text-gray-80 body-l-m" onClick={logout}>
59+
<span className="text-gray-80 body-l-m" onClick={() => logout()}>
6060
로그아웃
6161
</span>
6262
</button>

src/pages/Home/components/GoToLetterBoard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import goToLetterBoard from '@/assets/images/go-to-letter-board.png';
44

55
const GoToLetterBoard = () => {
66
return (
7-
<div className="absolute right-[-56%] bottom-[28%] z-9 flex w-full md:right-[-42%]">
7+
<div className="absolute right-[-56%] bottom-[28%] z-9 flex w-full md:right-[-42%] lg:right-[-20%]">
88
<div className="text-left">
9-
<p className="text-gray-60 body-r mb-1 ml-2 dark:text-white">게시판</p>
9+
<p className="text-gray-60 body-r mb-1 ml-2">게시판</p>
1010
<Link to="/board/letter">
1111
<img
1212
src={goToLetterBoard}

src/pages/Share/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const ShareApprovalPage = () => {
2626
if (action === 'approve') {
2727
setToastActive({
2828
toastType: 'Success',
29-
title: '편지를 성공적으로 공유하였습니다. 게시판에서 확인해보세요!',
29+
title: '편지가 공유되었습니다. 게시판에서 확인해보세요!',
3030
time: 5,
3131
});
3232
} else {

src/types/admin.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ interface BadWords {
7575

7676
interface BadWordsData extends BadWords {
7777
id: string;
78+
isUsed: string;
7879
}
7980

8081
//

0 commit comments

Comments
 (0)