Skip to content

Commit

Permalink
fix: show toast on vote my topic
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinho1011 committed Feb 19, 2024
1 parent 496252f commit d9368dd
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/routes/A/ATopics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import ATopicCard from '@components/A/ATopicCard';
import { Col, Row } from '@components/commons/Flex/Flex';
import Layout from '@components/commons/Layout/Layout';
import Text from '@components/commons/Text/Text';
import { Toast } from '@components/commons/Toast/Toast';
import ToggleSwitch from '@components/commons/ToggleSwitch/ToggleSwitch';

import { colors } from '@styles/theme';

import { ALogoIcon, UpDownChevronIcon } from '@icons/index';

import { ResponseError } from '@apis/fetch';

import { Container } from './ATopics.styles';

const ATopics = () => {
Expand All @@ -27,12 +30,18 @@ const ATopics = () => {
setTopicFilter(e.target.value);
};

const handleVote = (topicId: number, side: 'CHOICE_A' | 'CHOICE_B') => {
voteMutation.mutate({
topicId: topicId,
choiceOption: side,
votedAt: new Date().getTime() / 1000,
});
const handleVote = async (topicId: number, side: 'CHOICE_A' | 'CHOICE_B') => {
try {
await voteMutation.mutateAsync({
topicId: topicId,
choiceOption: side,
votedAt: new Date().getTime() / 1000,
});
} catch (error) {
if (error instanceof ResponseError && error.errorData.abCode === 'VOTED_BY_AUTHOR') {
Toast.error('토픽을 작성한 사람은 투표할 수 없어요');
}
}
};

return (
Expand Down

0 comments on commit d9368dd

Please sign in to comment.