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

fix(web-domains): 질문 답변 완료, 코멘트 답변 완료, 질문인 선택 post 요청 시 버튼 로딩 처리 #181

Merged
merged 2 commits into from
Aug 30, 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Comment } from '../components/Comment';
import { useCommentService } from '../services/useCommentService';

export const CommentContainer = () => {
const { comment, handleChangeComment, handleSubmit } = useCommentService();
const { comment, handleChangeComment, handleSubmit, isSendCommentPending, isAnswerQuestionPending } =
useCommentService();

return (
<section
Expand All @@ -16,7 +17,7 @@ export const CommentContainer = () => {
}}
>
<Comment comment={comment} onChangeComment={handleChangeComment} />
<CommentButton onClick={handleSubmit} />
<CommentButton onClick={handleSubmit} loading={isSendCommentPending || isAnswerQuestionPending} />
</section>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const useCommentService = () => {
const [comment, setComment] = useState<string>('');
const answerList = useAtomValue(answerAtoms.answerList);
const { meetingId, questionId } = useParams<{ meetingId: string; questionId: string }>();
const { mutateAsync: sendCommentMutate } = useCommentMutation({});
const { mutateAsync: sendAnswerMutate } = useAnswerQuestionMutation({});
const { mutateAsync: sendCommentMutate, isPending: isSendCommentPending } = useCommentMutation({});
const { mutateAsync: sendAnswerMutate, isPending: isAnswerQuestionPending } = useAnswerQuestionMutation({});

const setIsProgressingQuestion = useSetAtom(HomeAtoms.isProgessingQuestionAtom);
const setHomeGlobalTime = useSetAtom(HomeAtoms.homeGlobalTimeAtom);
Expand Down Expand Up @@ -87,5 +87,7 @@ export const useCommentService = () => {
comment,
handleSubmit,
handleChangeComment,
isAnswerQuestionPending,
isSendCommentPending,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { Attributes, HTMLAttributes } from 'react';
interface CommentButtonProps extends Omit<HTMLAttributes<HTMLButtonElement>, 'onClick'> {
disabled?: boolean;
onClick?: () => void;
loading?: boolean;
}

export const CommentButton = ({ disabled, onClick, ...rest }: CommentButtonProps) => {
export const CommentButton = ({ disabled, onClick, loading = false, ...rest }: CommentButtonProps) => {
const buttonStyles: Attributes['css'] = {
backgroundColor: disabled ? colors.grey600 : colors.black,
cursor: disabled ? 'none' : 'pointer',
Expand All @@ -24,7 +25,7 @@ export const CommentButton = ({ disabled, onClick, ...rest }: CommentButtonProps

return (
<div css={{ position: 'absolute', bottom: '40px', width: '100%', maxWidth: '600px', padding: '0 20px' }}>
<Button size="large" {...rest} css={buttonStyles} onClick={handleAnswer}>
<Button size="large" {...rest} css={buttonStyles} onClick={handleAnswer} loading={loading}>
답변 보내기
</Button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ interface QuestionerProps {

export const Questioner = ({ meetingId, meetingMemberId, imageUrl, name }: QuestionerProps) => {
const openModal = useModal();
const { postRelayQuestionInfo } = usePostRelayQuestionInfo(meetingId);
const { postRelayQuestionInfo, isPending } = usePostRelayQuestionInfo(meetingId);

const router = useRouter();
const searchParams = useSearchParams();

const handleOpenModal = async () => {
const isConfirm = await openModal({
component: QuestionerDetail,
componentProps: { imageUrl, name, isRandom: false },
componentProps: { imageUrl, name, isRandom: false, isPending },
});

if (isConfirm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface QuestionerDetailProps {
onClose: () => void;
onConfirm: () => void;
onRefetch?: () => void;
isPending?: boolean;
}

export const QuestionerDetail = ({
Expand All @@ -25,6 +26,7 @@ export const QuestionerDetail = ({
onClose,
onConfirm,
onRefetch,
isPending = false,
}: QuestionerDetailProps) => {
return (
<div css={wrapperCss}>
Expand All @@ -38,7 +40,9 @@ export const QuestionerDetail = ({
<Button variant="sub" onClick={onClose}>
닫기
</Button>
<Button onClick={onConfirm}>질문인 선택</Button>
<Button onClick={onConfirm} loading={isPending}>
질문인 선택
</Button>
</div>
{isRandom && (
<RePick onClick={onRefetch}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const QuestionerRandomPick = ({ meetingId }: Props) => {
excludeMemberIds: [memberMe?.meetingMemberId!],
});

const { postRelayQuestionInfo } = usePostRelayQuestionInfo(meetingId);
const { postRelayQuestionInfo, isPending } = usePostRelayQuestionInfo(meetingId);

const handleOpenModal = () => {
setIsOpen(true);
Expand Down Expand Up @@ -142,6 +142,7 @@ const QuestionerRandomPick = ({ meetingId }: Props) => {
onConfirm={handleConfirmModal}
onRefetch={refetchQuestioner}
isRandom
isPending={isPending}
/>
)}
</Modal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const usePostRelayQuestionInfo = (meetingId: number) => {
const { mutate: postRelayQuestionInfo, ...rest } = useMutation({
mutationFn: (payload: Payload) => _postRelayQuestionInfo({ meetingId, payload }),
onError: (error: AxiosError<{ message: string }>) => {
alert(error.response?.data.message ?? '댓글 수정에 실패했습니다.');
alert(error.response?.data.message ?? '릴레이 질문 생성에 실패했습니다.');
},
});

Expand Down
Loading