Skip to content

Commit

Permalink
Merge pull request #247 from ppochaco/fix/221-profile-question
Browse files Browse the repository at this point in the history
Week11/issue#221 프로필 질문 답장하기 401 에러 추가
  • Loading branch information
ppochaco authored Nov 14, 2024
2 parents 7e60da4 + ee27948 commit bdde6ce
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/pages/GroupPage/Management/CreateQuestion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const GroupQuestionCreateModal = ({
groupId,
}: GroupQuestionCreateModalProps) => {
const errorAlert = useDisclosure()

const [errorMessage, setErrorMessage] = useState('')

const form = useForm<CreateQuestionFields>({
Expand Down
12 changes: 9 additions & 3 deletions src/pages/MyPage/UserProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface UserProfileProps {

export const UserProfile = ({ profile }: UserProfileProps) => {
return (
<Flex flexDirection="column" padding="0 30px">
<Flex flexDirection="column">
<Box
height="144px"
backgroundImage={`url('${profile.backgroundImageUrl}')`}
Expand All @@ -22,12 +22,18 @@ export const UserProfile = ({ profile }: UserProfileProps) => {
size="lg"
position="absolute"
bottom="-30px"
left="30px"
/>
</Box>
<Text fontSize="xl" fontWeight="400">
<Text fontSize="xl" fontWeight="400" padding="0 30px">
{profile.name}
</Text>
<Flex justifyContent="space-between" alignItems="end" gap={4}>
<Flex
justifyContent="space-between"
alignItems="end"
gap={4}
padding="0 30px"
>
<Text color="text_secondary" fontSize="md">
{profile.description}
</Text>
Expand Down
36 changes: 36 additions & 0 deletions src/pages/ProfileQuestionPage/WriteReply/LoginModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { BiError } from 'react-icons/bi'
import { useNavigate } from 'react-router-dom'

import {
ConfirmModal,
ConfirmModalButton,
} from '@/components/Modal/ConfirmModal'
import { Modal } from '@/types'

interface LoginModalProps {
modal: Modal
}

export const LoginModal = ({ modal }: LoginModalProps) => {
const navigate = useNavigate()

return (
<ConfirmModal
isOpen={modal.isOpen}
onClose={modal.onClose}
icon={<BiError />}
title="로그인 후 이용해주세요"
description=""
confirmButton={
<ConfirmModalButton
onClick={() => {
navigate('/login')
modal.onClose()
}}
>
확인
</ConfirmModalButton>
}
/>
)
}
14 changes: 13 additions & 1 deletion src/pages/ProfileQuestionPage/WriteReply/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ import {
AnswerProfileQuestionField,
AnswerProfileQuestionSchema,
} from '@/schema/profile'
import { useAuthTokenStore } from '@/stores/auth-token'

import { LoginModal } from './LoginModal'

interface WriteReplyProps {
userId: number
questionId: number
}

export default function WriteReply({ userId, questionId }: WriteReplyProps) {
const isLoggedIn = useAuthTokenStore((state) => state.isLoggedIn())
const [errorMessage, setErrorMessage] = useState('')

const errorAlert = useDisclosure()
const successAlert = useDisclosure()
const loginModal = useDisclosure()

const form = useForm<AnswerProfileQuestionField>({
resolver: zodResolver(AnswerProfileQuestionSchema),
Expand Down Expand Up @@ -55,7 +60,13 @@ export default function WriteReply({ userId, questionId }: WriteReplyProps) {
})

const handleSend = form.handleSubmit(
() => submitReply(form.getValues()),
() => {
if (!isLoggedIn) {
loginModal.onOpen()
return
}
submitReply(form.getValues())
},
(errors) => {
const errorMessages =
Object.values(errors).flatMap((error) => error.message)[0] || ''
Expand Down Expand Up @@ -135,6 +146,7 @@ export default function WriteReply({ userId, questionId }: WriteReplyProps) {
title="답변을 성공적으로 보냈습니다!"
description="친구들의 다른 프로필 질문에 답변을 보내보세요"
/>
<LoginModal modal={loginModal} />
</Flex>
)
}

0 comments on commit bdde6ce

Please sign in to comment.