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

회원이 마감 완료된 게시글에 투표할 때 failed to Fetch가 나타나요, 마감된 게시글 투표 통계 보이도록 수정 #401

Merged
merged 2 commits into from
Aug 14, 2023
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
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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍위에 비회원 케이스랑 통일성 있어서 좋네요!


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