Skip to content

Commit

Permalink
회원이 마감 완료된 게시글에 투표할 때 failed to Fetch가 나타나요, 마감된 게시글 투표 통계 보이도록 수정 (#401
Browse files Browse the repository at this point in the history
)

* fix: (#399) 마감된 게시글에 투표했을 때 사용자에게 투표할 수 없다는 문구 출력

* fix: (#399) 마감된 게시글은 투표 통계가 보이도록 수정
isWriter라는 변수명을 더 넓은 범위를 뜻하는 isStatisticsVisible로 변경
  • Loading branch information
Gilpop8663 authored and tjdtls690 committed Sep 12, 2023
1 parent 88f998c commit 14806c1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
10 changes: 9 additions & 1 deletion frontend/src/components/common/Post/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@ export default function Post({ postInfo, isPreview }: PostProps) {

const isActive = !checkClosedPost(deadline);

const isStatisticsVisible =
writer.id === loggedInfo.id || !isActive || voteInfo.selectedOptionId !== POST.NOT_VOTE;

const handleVoteClick = (newOptionId: number) => {
if (!loggedInfo.isLoggedIn) {
openToast('투표를 하려면 로그인 후에 이용하실 수 있습니다.');
return;
}

if (!isActive) {
openToast('마감된 게시글에는 투표를 할 수 없습니다.');
return;
}

if (writer.nickname === loggedInfo.userInfo?.nickname) return;

if (voteInfo.selectedOptionId === newOptionId) return;
Expand Down Expand Up @@ -130,7 +138,7 @@ export default function Post({ postInfo, isPreview }: PostProps) {
)}
</S.DetailLink>
<WrittenVoteOptionList
isWriter={writer.id === loggedInfo.id}
isStatisticsVisible={isStatisticsVisible}
selectedOptionId={voteInfo.selectedOptionId}
handleVoteClick={handleVoteClick}
isPreview={isPreview}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const Select: Story = {
peopleCount={2}
percent={70.9}
isSelected={true}
isVoted={true}
isStatisticsVisible={true}
imageUrl=""
/>
</WrittenVoteWrapper>
Expand All @@ -44,7 +44,7 @@ export const NotSelectAndLongText: Story = {
percent={80}
peopleCount={6}
isSelected={false}
isVoted={true}
isStatisticsVisible={true}
imageUrl=""
/>
</WrittenVoteWrapper>
Expand All @@ -63,7 +63,7 @@ export const ImageAndSelect: Story = {
percent={80}
peopleCount={6}
isSelected={true}
isVoted={true}
isStatisticsVisible={true}
/>
</WrittenVoteWrapper>
),
Expand All @@ -80,7 +80,7 @@ export const NotVote: Story = {
percent={0}
peopleCount={0}
isSelected={false}
isVoted={false}
isStatisticsVisible={false}
imageUrl=""
/>
</WrittenVoteWrapper>
Expand All @@ -99,7 +99,7 @@ export const ImageAndNotVote: Story = {
percent={0}
peopleCount={0}
isSelected={false}
isVoted={false}
isStatisticsVisible={false}
/>
</WrittenVoteWrapper>
),
Expand All @@ -117,7 +117,7 @@ export const PreviewContent: Story = {
percent={0}
peopleCount={0}
isSelected={false}
isVoted={false}
isStatisticsVisible={false}
/>
</WrittenVoteWrapper>
),
Expand All @@ -135,7 +135,7 @@ export const DetailContent: Story = {
percent={0}
peopleCount={0}
isSelected={false}
isVoted={false}
isStatisticsVisible={false}
/>
</WrittenVoteWrapper>
),
Expand All @@ -152,7 +152,7 @@ export const NoImageAndDetailContent: Story = {
percent={60}
peopleCount={8}
isSelected={true}
isVoted={true}
isStatisticsVisible={true}
imageUrl=""
/>
</WrittenVoteWrapper>
Expand All @@ -171,7 +171,7 @@ export const ImageAndSelectAndDetailContent: Story = {
percent={60}
peopleCount={8}
isSelected={true}
isVoted={true}
isStatisticsVisible={true}
/>
</WrittenVoteWrapper>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as S from './style';
interface WrittenVoteOptionProps {
handleVoteClick: () => void;
text: string;
isVoted: boolean;
isStatisticsVisible: boolean;
peopleCount: number;
percent: number;
isSelected: boolean;
Expand All @@ -16,7 +16,7 @@ interface WrittenVoteOptionProps {
export default function WrittenVoteOption({
handleVoteClick,
text,
isVoted,
isStatisticsVisible,
peopleCount,
percent,
isSelected,
Expand All @@ -40,7 +40,7 @@ export default function WrittenVoteOption({
) : (
<S.DetailContent aria-label="선택지 내용">{text}</S.DetailContent>
)}
{isVoted && (
{isStatisticsVisible && (
<>
<S.ProgressContainer aria-label={''}>
<ProgressBar percent={percent} isSelected={isSelected} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const PreviewNotVoted: Story = {
render: () => (
<WrittenVoteWrapper>
<WrittenVoteOptionList
isWriter={true}
isStatisticsVisible={true}
selectedOptionId={MOCK_NOT_VOTED_DATA.selectedOptionId}
handleVoteClick={() => {}}
isPreview={true}
Expand All @@ -103,7 +103,7 @@ export const PreviewVoted: Story = {
render: () => (
<WrittenVoteWrapper>
<WrittenVoteOptionList
isWriter={true}
isStatisticsVisible={true}
selectedOptionId={MOCK_VOTED_DATA.selectedOptionId}
handleVoteClick={() => {}}
isPreview={true}
Expand All @@ -117,7 +117,7 @@ export const DetailNotVoted: Story = {
render: () => (
<WrittenVoteWrapper>
<WrittenVoteOptionList
isWriter={true}
isStatisticsVisible={true}
selectedOptionId={MOCK_NOT_VOTED_DATA.selectedOptionId}
handleVoteClick={() => {}}
isPreview={false}
Expand All @@ -131,7 +131,7 @@ export const DetailVoted: Story = {
render: () => (
<WrittenVoteWrapper>
<WrittenVoteOptionList
isWriter={true}
isStatisticsVisible={true}
selectedOptionId={MOCK_VOTED_DATA.selectedOptionId}
handleVoteClick={() => {}}
isPreview={false}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { WrittenVoteOptionType } from '@type/post';

import { POST } from '@constants/vote';

import * as S from './style';
import WrittenVoteOption from './WrittenVoteOption';

interface WrittenVoteOptionListProps {
isPreview: boolean;
isWriter: boolean;
isStatisticsVisible: boolean;
selectedOptionId: number;
voteOptionList: WrittenVoteOptionType[];
handleVoteClick: (newOptionId: number) => void;
}

export default function WrittenVoteOptionList({
isPreview,
isWriter,
isStatisticsVisible,
voteOptionList,
selectedOptionId,
handleVoteClick,
Expand All @@ -28,7 +26,7 @@ export default function WrittenVoteOptionList({
key={voteOption.id}
{...voteOption}
isPreview={isPreview}
isVoted={selectedOptionId !== POST.NOT_VOTE || isWriter}
isStatisticsVisible={isStatisticsVisible}
isSelected={selectedOptionId === voteOption.id}
handleVoteClick={() => handleVoteClick(voteOption.id)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function OptionStatistics({
key={voteOption.id}
{...voteOption}
isPreview={false}
isVoted={true}
isStatisticsVisible={true}
isSelected={isSelectedOption}
handleVoteClick={toggleOptionStatistics}
/>
Expand Down

0 comments on commit 14806c1

Please sign in to comment.