Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

질문 상세, 질문 작성 페이지 수정 #307

Merged
merged 4 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 86 additions & 3 deletions src/asset/sass/etc/header/userInfoHeader.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,65 @@ img.loginuser {

border-radius: 10px;
border-color: #d9d9d9;
margin-left: 92%;
margin-top: -12%;
left: 93%;
bottom: 14px;
letter-spacing: -1px;
font-family: 'Pretendard-Medium';
}
}

.dropdown-question-detail-menu-answer {
position: relative;
z-index: 500;

cursor: pointer;
ul {
position: absolute;
list-style: none;
padding: 0;
margin: 0;
background: #fff;
border: 1px solid rgba(0, 0, 0, 0.3);
width: 88px;
height: 72px;
display: flex;
justify-content: space-evenly;
flex-direction: column;
align-items: center;
margin: 0 6px 0 0;
border-radius: 10px;
border-color: #d9d9d9;
left: 78%;
top: -22px;
letter-spacing: -1px;
font-family: 'Pretendard-Medium';
}
}

.dropdown-question-detail-report-menu-answer {
position: relative;
z-index: 500;
right: 6rem;
top: 6rem;
cursor: pointer;
ul {
position: absolute;
list-style: none;
padding: 0;
margin: 0;
background: #fff;
border: 1px solid rgba(0, 0, 0, 0.3);
width: 88px;
height: 36px;
display: flex;
justify-content: space-evenly;
flex-direction: column;
align-items: center;

border-radius: 10px;
border-color: #d9d9d9;
left: 93%;
bottom: 14px;
letter-spacing: -1px;
font-family: 'Pretendard-Medium';
}
Expand Down Expand Up @@ -102,7 +159,9 @@ img.loginuser {
border-color: #d9d9d9;
// margin-left: 82%;
// margin-top: -3%;
left: 78%;
// left: 78%;
left: 82%;
top: 17px;
}

.dropdown-item {
Expand Down Expand Up @@ -159,6 +218,30 @@ img.loginuser {
}
}

.dropdown-question-detail-report-menu-answer {
position: relative;
right: 6rem;
top: 6rem;
ul {
position: absolute;
list-style: none;
padding: 0;
margin: 0;
background: #fff;
border: 1px solid rgba(0, 0, 0, 0.3);
width: 88px;
height: 36px;
display: flex;
justify-content: space-evenly;
flex-direction: column;
align-items: center;
border-radius: 10px;
border-color: #d9d9d9;
right: -11%;
bottom: 45px;
}
}

.dropdown-menu {
position: relative;
z-index: 500;
Expand Down
2 changes: 1 addition & 1 deletion src/asset/sass/pages/postPage/questionWritePage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ select {
overflow-wrap: break-word;
font-family: 'Pretendard-Light';
font-weight: 600;
font-size: 2rem;
font-size: 1.6rem;
cursor: pointer;
letter-spacing: -0.1rem;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/postPage/questionWritePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,14 @@ function QuestionWritePage() {

if (questionId) {
await fetchAPI(`/api/question/${questionId}`, 'PATCH', editBody);
showSuccessToast('질문이 수정되었습니다');
} else {
await fetchAPI('/api/question', 'POST', body);
showSuccessToast('질문이 등록되었습니다');
}

// 질문 데이터가 수정되었다면 POST가 아니라 같은 엔드포인트로 PATCH 요청을 보낼 것

showSuccessToast('질문이 등록되었습니다');
navigate(`/company-info/${companyId}`);
} catch (error) {
if (error instanceof Error) {
Expand Down
39 changes: 27 additions & 12 deletions src/components/ui/question/answer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,27 @@ function AnswerModule({

const [isShowReport, setIsShowReport] = useState(false);
const [isShowReportModal, setIsShowReportModal] = useState(false);
const [selectedAnswerId, setSelectAnswerId] = useState<string | undefined>(
'',
);

const handleEdit = async () => {
const handleEdit = async (id: string | undefined) => {
const res = await fetchAPI('/api/member/me', 'GET');
if (res.data.nickname === answererNickname) {
setIsShowEdit((isShow) => !isShow);
} else if (res.data.nickname !== answererNickname) {
setIsShowReport((showReport) => !showReport);
if (selectedAnswerId === id) {
setIsShowReport((show) => !show);
} else {
setIsShowReport(true);
setSelectAnswerId(id);
}
}
};

console.log(answerId);

const handleClickEdit = async () => {
try {
await fetchAPI(`/api/question/${answerId}`, 'PATCH');
Expand All @@ -154,22 +165,26 @@ function AnswerModule({

const handleClickDelete = async () => {
try {
if (confirm('삭제하시겠습니까?')){
if (confirm('삭제하시겠습니까?')) {
const response = await fetchAPI(`/api/question/${answerId}`, 'DELETE');
if (response.error) {
showErrorToast('답변 삭제가 불가능합니다.')
}else{
showSuccessToast('답변이 삭제되었습니다.');}

showErrorToast('답변 삭제가 불가능합니다.');
} else {
showSuccessToast('답변이 삭제되었습니다.');
}
}
} catch (error) {
if (error instanceof Error) showErrorToast(error.message);
}
};

const handleReportSubmit = async () => {
toggleReportPopup();
await fetchAPI(`/api/report`, 'POST', {});
await fetchAPI(`/api/report`, 'POST', {
content: answerContent,
type: 'ANSWER',
id: answerId,
});

showSuccessToast('신고 접수가 되었습니다.');
};
Expand Down Expand Up @@ -217,13 +232,13 @@ function AnswerModule({
/>
<AnswerName>{answererNickname}</AnswerName>
</NameContainer>
<img src={Dot} alt="dot" onClick={handleEdit} />
<img src={Dot} alt="dot" onClick={() => handleEdit(answerId)} />
</div>
<AnswerContent className="user-contents">
{answerContent}
</AnswerContent>
{isShowEdit && (
<div className="dropdown-question-detail-menu">
{isShowEdit && selectedAnswerId !== answerId && (
<div className="dropdown-question-detail-menu-answer">
<ul>
<li onClick={handleClickEdit} className="dropdown-item-edit">
수정
Expand All @@ -238,11 +253,11 @@ function AnswerModule({
</div>
)}
{isShowReport ? (
<div className="dropdown-question-detail-report-menu">
<div className="dropdown-question-detail-report-menu-answer">
<ul>
<li
onClick={toggleReportPopup}
className="dropdown-item-report"
className="dropdown-item-report-answer"
>
신고
</li>
Expand Down
Loading