Skip to content

Commit

Permalink
refactor: 변경된 모달 컴포넌트 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
turtle601 committed Jan 14, 2024
1 parent a2ab9ea commit 07c89d6
Show file tree
Hide file tree
Showing 14 changed files with 420 additions and 516 deletions.
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@tanstack/react-query-devtools": "^4.36.1",
"axios": "^1.5.1",
"browser-image-compression": "^2.0.2",
"celuveat-ui-library": "^1.2.8",
"celuveat-ui-library": "^1.4.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.2",
Expand Down Expand Up @@ -58,6 +58,7 @@
"@testing-library/react": "^14.0.0",
"@types/google.maps": "^3.53.5",
"@types/jest": "^29.5.3",
"@types/node": "^20.11.0",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"@types/react-slick": "^0.23.11",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/CelebDropDown/CelebDropDown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function CelebDropDown() {
<StyledDropDownWrapper isMobile={isMobile}>
<StyledSelectContainer>
{[OPTION_FOR_CELEB_ALL, ...celebOptions].map(celeb => (
<DropDown.Option as="li" key={celeb.id} externalClick={selectCeleb(celeb)} isCustom>
<DropDown.Option as="li" key={celeb.id} onClick={selectCeleb(celeb)} isCustom>
<StyledDropDownOption>
<CelebDropDownOption celeb={celeb} />
</StyledDropDownOption>
Expand Down
50 changes: 0 additions & 50 deletions frontend/src/components/FormModal/FormModal.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions frontend/src/components/FormModal/index.tsx

This file was deleted.

29 changes: 17 additions & 12 deletions frontend/src/components/InfoDropDown/InfoDropDown.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { styled } from 'styled-components';
import { useQuery } from '@tanstack/react-query';
import { DropDown } from 'celuveat-ui-library';
import { useNavigate } from 'react-router-dom';
import { styled } from 'styled-components';
import { getProfile } from '~/api/user';
import { DropDown, Modal } from 'celuveat-ui-library';

import InfoButton from '~/components/@common/InfoButton';
import LoginModal from '~/components/LoginModal';

import { ProfileData } from '~/@types/api.types';
import useCeluveatModal from '~/hooks/useCeluveatModal';
import { getProfile } from '~/api/user';

import type { ProfileData } from '~/@types/api.types';

function InfoDropDown() {
const { openLoginModal } = useCeluveatModal();
const { data, isSuccess: isLogin } = useQuery<ProfileData>({
queryKey: ['profile'],
queryFn: getProfile,
Expand Down Expand Up @@ -40,20 +41,22 @@ function InfoDropDown() {
<StyledDropDownWrapper>
{isLogin ? (
<>
<DropDown.Option as="li" isCustom externalClick={goMyPage}>
<DropDown.Option as="li" isCustom onClick={goMyPage}>
<StyledDropDownOption>마이 페이지</StyledDropDownOption>
</DropDown.Option>
<DropDown.Option as="li" isCustom externalClick={goWishList}>
<DropDown.Option as="li" isCustom onClick={goWishList}>
<StyledDropDownOption>위시리스트</StyledDropDownOption>
</DropDown.Option>
<DropDown.Option as="li" isCustom externalClick={goWithdrawal}>
<DropDown.Option as="li" isCustom onClick={goWithdrawal}>
<StyledDropDownOption>회원 탈퇴</StyledDropDownOption>
</DropDown.Option>
</>
) : (
<DropDown.Option isCustom externalClick={openLoginModal}>
<StyledDropDownOption>로그인</StyledDropDownOption>
</DropDown.Option>
<Modal.OpenButton modalTitle="로그인 및 회원가입" isCustom modalContent={<LoginModal />}>
<DropDown.Option isCustom>
<StyledDropDownOption>로그인</StyledDropDownOption>
</DropDown.Option>
</Modal.OpenButton>
)}
</StyledDropDownWrapper>
</DropDown.Options>
Expand Down Expand Up @@ -99,6 +102,8 @@ const StyledDropDownOption = styled.li`
padding: 0 1rem;
border-radius: 10px;
&:hover {
background: var(--gray-1);
}
Expand Down
11 changes: 4 additions & 7 deletions frontend/src/components/LoginModal/LoginModal.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { styled } from 'styled-components';
import LoginButton from '~/components/@common/LoginButton';
import Dialog from '../@common/Dialog';

function LoginModal() {
return (
<Dialog title="로그인 및 회원가입">
<StyledLoginModalContent>
<LoginButton type="kakao" />
<LoginButton type="google" />
</StyledLoginModalContent>
</Dialog>
<StyledLoginModalContent>
<LoginButton type="kakao" />
<LoginButton type="google" />
</StyledLoginModalContent>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { styled, css } from 'styled-components';
import { useQuery } from '@tanstack/react-query';

import { Modal } from 'celuveat-ui-library';
import ThumpUpIcon from '~/assets/icons/etc/thumb-up.svg';
import SpeakerphoneIcon from '~/assets/icons/etc/speakerphone.svg';

Expand All @@ -15,7 +16,7 @@ import { getProfile } from '~/api/user';
import { getReviewImgUrl, lookImage } from '~/utils/image';

import type { ProfileData, RestaurantReview } from '~/@types/api.types';
import useCeluveatModal from '~/hooks/useCeluveatModal';
import { ReviewDeleteForm, ReviewForm, ReviewReportForm } from '~/components/ReviewForm';

interface RestaurantReviewItemProps {
review: RestaurantReview;
Expand All @@ -29,8 +30,6 @@ function RestaurantReviewItem({ review }: RestaurantReviewItemProps) {

const { getReviewIsLiked, toggleRestaurantReviewLike } = useRestaurantReview();

const { openReviewFormModal } = useCeluveatModal();

const isUsersReview = profileData?.memberId === review.memberId;

return (
Expand All @@ -46,23 +45,21 @@ function RestaurantReviewItem({ review }: RestaurantReviewItemProps) {

{isUsersReview && (
<StyledButtonContainer>
<button
type="button"
onClick={() => {
openReviewFormModal({ type: 'update', reviewId: review.id });
}}
<Modal.OpenButton
isCustom
modalTitle="리뷰 수정하기"
modalContent={<ReviewForm type="update" reviewId={review.id} />}
>
수정
</button>
<button type="button">수정</button>
</Modal.OpenButton>
<StyledLine />
<button
type="button"
onClick={() => {
openReviewFormModal({ type: 'delete', reviewId: review.id });
}}
<Modal.OpenButton
isCustom
modalTitle="리뷰 삭제하기"
modalContent={<ReviewDeleteForm reviewId={review.id} />}
>
삭제
</button>
<button type="button">삭제</button>
</Modal.OpenButton>
</StyledButtonContainer>
)}
</StyledProfileAndButton>
Expand Down Expand Up @@ -92,14 +89,16 @@ function RestaurantReviewItem({ review }: RestaurantReviewItemProps) {
<ThumpUpIcon stroke={getReviewIsLiked(review.id) ? '#ff7b54' : '#3a3b3c'} />
<StyledReviewText isLiked={getReviewIsLiked(review.id)}>{review.likeCount}</StyledReviewText>
</StyledReviewButton>
<StyledReviewButton
onClick={() => {
openReviewFormModal({ type: 'report', reviewId: review.id });
}}
<Modal.OpenButton
isCustom
modalTitle="리뷰 신고하기"
modalContent={<ReviewReportForm reviewId={review.id} />}
>
<SpeakerphoneIcon stroke="#3a3b3c" />
<StyledReviewText>신고</StyledReviewText>
</StyledReviewButton>
<StyledReviewButton>
<SpeakerphoneIcon stroke="#3a3b3c" />
<StyledReviewText>신고</StyledReviewText>
</StyledReviewButton>
</Modal.OpenButton>
</>
)}
</StyledReviewButtonsWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { styled } from 'styled-components';

import { Modal } from 'celuveat-ui-library';
import Pencil from '~/assets/icons/pencil.svg';

import RestaurantReviewList from '~/components/RestaurantReviewList';
Expand All @@ -8,34 +9,30 @@ import useRestaurantReview from '~/hooks/server/useRestaurantReview';

import { FONT_SIZE } from '~/styles/common';
import { REVIEW_SHOW_COUNT } from '~/constants/options';
import { ReviewFormType } from '~/@types/review.types';
import useCeluveatModal from '~/hooks/useCeluveatModal';

import { ReviewForm } from '~/components/ReviewForm';

function RestaurantReviewWrapper() {
const { restaurantReviewsData } = useRestaurantReview();
const { openReviewFormModal } = useCeluveatModal();

const { totalElementsCount: reviewCount } = restaurantReviewsData;
const isMoreReviews = reviewCount > REVIEW_SHOW_COUNT;

const onClickOpenModal = (reviewFormType: ReviewFormType) => () => {
openReviewFormModal({ type: reviewFormType });
};

return (
<StyledRestaurantReviewWrapper>
<StyledReviewCountText>리뷰 {reviewCount ? `${reviewCount}개` : '없음'}</StyledReviewCountText>
<RestaurantReviewList isSummary />
<StyledButtonContainer>
<StyledButton type="button" onClick={onClickOpenModal('create')}>
<Pencil width={20} />
리뷰 작성하기
</StyledButton>
<Modal.OpenButton isCustom modalTitle="리뷰 작성하기" modalContent={<ReviewForm type="create" />}>
<StyledButton type="button">
<Pencil width={20} />
리뷰 작성하기
</StyledButton>
</Modal.OpenButton>
{isMoreReviews && (
<StyledButton
type="button"
onClick={onClickOpenModal('all')}
>{`리뷰 ${reviewCount}개 모두 보기`}</StyledButton>
<Modal.OpenButton isCustom modalTitle="리뷰 모두 보기" modalContent={<RestaurantReviewList />}>
<StyledButton type="button">{`리뷰 ${reviewCount}개 모두 보기`}</StyledButton>
</Modal.OpenButton>
)}
</StyledButtonContainer>
</StyledRestaurantReviewWrapper>
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/SuggestionButton/SuggestionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Modal } from 'celuveat-ui-library';
import { styled } from 'styled-components';
import Pencil from '~/assets/icons/pencil.svg';
import useCeluveatModal from '~/hooks/useCeluveatModal';

function SuggestionButton() {
const { openSuggestionModal } = useCeluveatModal();

return (
<StyledButton type="button" onClick={openSuggestionModal}>
<Pencil width={16} />
<div>정보 수정 제안하기</div>
</StyledButton>
<Modal.OpenButton isCustom modalTitle="정보 수정 제안하기" modalContent={<SuggestionButton />}>
<StyledButton type="button">
<Pencil width={16} />
<div>정보 수정 제안하기</div>
</StyledButton>
</Modal.OpenButton>
);
}

Expand Down
5 changes: 3 additions & 2 deletions frontend/src/hooks/server/useRestaurantReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useParams } from 'react-router-dom';
import { shallow } from 'zustand/shallow';

import { useState } from 'react';

import { useModalStore } from 'celuveat-ui-library';
import {
deleteRestaurantReview,
getRestaurantReview,
Expand All @@ -16,7 +18,6 @@ import {
import useToastState from '~/hooks/store/useToastState';

import type { RestaurantReviewData, RestaurantReviewPatchBody } from '~/@types/api.types';
import useCeluveatModal from '../useCeluveatModal';

const useRestaurantReview = () => {
const queryClient = useQueryClient();
Expand All @@ -35,7 +36,7 @@ const useRestaurantReview = () => {
shallow,
);

const { closeModal } = useCeluveatModal();
const { closeModal } = useModalStore();

const errorHandler = (error: AxiosError) => {
switch (error.response.status) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { AxiosError } from 'axios';
import { shallow } from 'zustand/shallow';
import { useModalStore } from 'celuveat-ui-library';
import { Query, useMutation, useQueryClient } from '@tanstack/react-query';
import { AxiosError } from 'axios';
import { Restaurant } from '../../@types/restaurant.types';
import useToastState from '~/hooks/store/useToastState';
import useBooleanState from '~/hooks/useBooleanState';

import { postRestaurantLike } from '~/api/user';
import useCeluveatModal from '../useCeluveatModal';

import useBooleanState from '~/hooks/useBooleanState';
import useToastState from '~/hooks/store/useToastState';

import type { Restaurant } from '~/@types/restaurant.types';

import LoginModal from '~/components/LoginModal';

const useToggleLikeNotUpdate = (restaurant: Restaurant) => {
const { openLoginModal } = useCeluveatModal();
const { openModal } = useModalStore();

const { value: isLiked, toggle: toggleIsLiked } = useBooleanState(restaurant.isLiked ?? true);
const { onSuccess, onFailure, close } = useToastState(
Expand All @@ -28,7 +33,7 @@ const useToggleLikeNotUpdate = (restaurant: Restaurant) => {

onError: (error: AxiosError) => {
if (error.response.status < 500) {
openLoginModal();
openModal({ title: '로그인 하기', content: <LoginModal /> });
toggleIsLiked();
} else {
onFailure(error.response.data as string);
Expand All @@ -46,7 +51,7 @@ const useToggleLikeNotUpdate = (restaurant: Restaurant) => {
query.queryKey[0] === 'restaurants' && query.queryKey[1]?.type !== 'wish-list',
});
},
});
});

const toggleRestaurantLike = () => {
toggleLike.mutate(restaurant.id);
Expand Down
Loading

0 comments on commit 07c89d6

Please sign in to comment.