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

[Feat] 셰어 편지 종료 시 리뷰 작성하기 버튼 추가 #322

Merged
merged 1 commit into from
Jun 29, 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
90 changes: 57 additions & 33 deletions src/components/Buyer/BuyerConsult/BuyerConsultLetterSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,30 @@ import { ReactComponent as Empty } from 'assets/icons/graphic-noting.svg';
import { Heading } from 'styles/font';
import { Space } from 'components/Common/Space';

//
//
//

interface BuyerConsultLetterSectionProps {
sortType: number;
isChecked: boolean;
}

//
//
//

export const BuyerConsultLetterSection = ({
sortType,
isChecked,
}: BuyerConsultLetterSectionProps) => {
const [cardData, setCardData] = useState<consultApiObject[]>([]); //card에 넘길 데이터

const [isLoading, setIsLoading] = useState<boolean>(true);

//
//
//
useLayoutEffect(() => {
const fetchData = async () => {
setIsLoading(true);
Expand All @@ -47,8 +59,14 @@ export const BuyerConsultLetterSection = ({
setIsLoading(false);
}
};

fetchData();
}, [sortType, isChecked, setIsLoading]);

//
//
//

if (isLoading) {
return (
<>
Expand All @@ -64,41 +82,46 @@ export const BuyerConsultLetterSection = ({
</div>
</>
);
} else {
return (
<>
{cardData.length !== 0 ? (
<BuyerConsultLetterSectionWrapper>
{cardData.map((value) => {
return (
<ConsultCard
key={value.id}
consultStyle={value.consultStyle}
id={value.id}
latestMessageContent={value.latestMessageContent}
latestMessageIsCustomer={value.latestMessageIsCustomer}
latestMessageUpdatedAt={value.latestMessageUpdatedAt}
opponentNickname={value.opponentNickname}
status={value.status}
unreadMessageCount={value.unreadMessageCount}
reviewCompleted={value.reviewCompleted}
consultId={value.consultId}
isLetter={true}
/>
);
})}
<Space height="4rem" />
</BuyerConsultLetterSectionWrapper>
) : (
<EmptyWrapper>
<EmptyIcon />
<Heading>아직 진행한 상담이 없어요</Heading>
</EmptyWrapper>
)}{' '}
</>
);
}

return (
<>
{cardData.length !== 0 ? (
<BuyerConsultLetterSectionWrapper>
{cardData.map((value) => {
return (
<ConsultCard
key={value.id}
consultStyle={value.consultStyle}
id={value.id}
latestMessageContent={value.latestMessageContent}
latestMessageIsCustomer={value.latestMessageIsCustomer}
latestMessageUpdatedAt={value.latestMessageUpdatedAt}
opponentNickname={value.opponentNickname}
status={value.status}
unreadMessageCount={value.unreadMessageCount}
reviewCompleted={value.reviewCompleted}
consultId={value.consultId}
isLetter={true}
/>
);
})}
<Space height="4rem" />
</BuyerConsultLetterSectionWrapper>
) : (
<EmptyWrapper>
<EmptyIcon />
<Heading>아직 진행한 상담이 없어요</Heading>
</EmptyWrapper>
)}
</>
);
};

//
//
//

const BuyerConsultLetterSectionWrapper = styled.section`
margin-bottom: 2rem;
display: flex;
Expand All @@ -110,6 +133,7 @@ const BuyerConsultLetterSectionWrapper = styled.section`
const EmptyIcon = styled(Empty)`
padding: 4.7rem 4.41rem 4.603rem 4.5rem;
`;

const EmptyWrapper = styled.div`
margin-top: 10vh;
display: flex;
Expand Down
22 changes: 21 additions & 1 deletion src/components/Buyer/BuyerLetter/LetterMainSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Body1, Body2, Body3 } from 'styles/font';
import { Grey1, Grey3, Grey6 } from 'styles/color';
import { Button } from 'components/Common/Button';
import { Space } from 'components/Common/Space';
import { useNavigate } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { GetMessagesType } from 'utils/type';
import { APP_WIDTH } from 'styles/AppStyle';

Expand All @@ -20,6 +20,10 @@ interface LetterMainSectionProps {
deadline: string;
}

interface locationStateType {
isReviewCompleted: boolean | null;
}

//
//
//
Expand All @@ -31,6 +35,10 @@ export const LetterMainSection = ({
deadline,
}: LetterMainSectionProps) => {
const navigate = useNavigate();
const location = useLocation();
const { isReviewCompleted } = location.state as locationStateType;

const isReviewButtonVisible = tagStatus === 3 && isReviewCompleted === false;

const formattedMessage = (message: string | null): JSX.Element[] | null => {
return message
Expand Down Expand Up @@ -145,6 +153,18 @@ export const LetterMainSection = ({
{formattedMessage(messageResponse.content)}
</Body2>
</ContentBox>
{isReviewButtonVisible ? (
<ButtonWrapper>
<Button
text="리뷰 작성하기"
width="100%"
height="5.2rem"
onClick={() => {
navigate(`/reviewManage`);
}}
/>
</ButtonWrapper>
) : null}
</SectionWrapper>
);
}
Expand Down
16 changes: 15 additions & 1 deletion src/components/Buyer/Common/ConsultCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { ConsultState } from 'utils/type';
import { consultStyleToCharNum } from 'utils/convertStringToCharNum';
import { Button } from 'components/Common/Button';

//
//
//

interface ConsultCardProps {
consultStyle: string;
id: number;
Expand All @@ -30,6 +34,11 @@ interface ConsultCardProps {
consultId: number | null;
isLetter: boolean;
}

//
//
//

export const ConsultCard = ({
consultStyle,
id,
Expand All @@ -50,6 +59,9 @@ export const ConsultCard = ({

const filterdUnreadMessageCount = unreadMessageCount ?? 0;

/**
*
*/
const handleReviewClick = (e?: React.MouseEvent<HTMLElement>) => {
e?.stopPropagation();
navigate('/reviewManage');
Expand All @@ -63,7 +75,9 @@ export const ConsultCard = ({
<Wrapper
onClick={() => {
if (isLetter) {
navigate(`/letter/${id}`);
navigate(`/letter/${id}`, {
state: { isReviewCompleted: reviewCompleted },
});
} else {
navigate(`/chat/${id}`);
}
Expand Down
Loading