Skip to content

Commit

Permalink
feat: 디자인시스템에서의 토스트 컴포넌트 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
xodms0309 committed Jul 28, 2024
1 parent ef94b1d commit 0e4c1d5
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/components/Common/ImageUploader/ImageUploader.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useToastActionContext } from '@fun-eat/design-system';
import type { ChangeEventHandler } from 'react';

import { container, deleteButton, image, imageWrapper, uploadInput, uploadLabel } from './imageUploader.css';
import SvgIcon from '../Svg/SvgIcon';
import { useToastActionContext } from '../Toast/context';
import Text from '../Typography/Text/Text';

import { IMAGE_MAX_SIZE } from '@/constants';
Expand Down
4 changes: 2 additions & 2 deletions src/components/Members/MemberReviewItem/MemberReviewItem.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useToastActionContext } from '@fun-eat/design-system';
import type { MouseEventHandler } from 'react';
import { Link } from 'react-router-dom';

import { titleWrapper } from './memberReviewItem.css';

import { SvgIcon, Text } from '@/components/Common';
import { useToastActionContext } from '@/components/Common/Toast/context';
import { ReviewItemInfo } from '@/components/Review';
import { PATH } from '@/constants/path';
import { useDeleteReview } from '@/hooks/queries/members';
Expand Down Expand Up @@ -40,7 +40,7 @@ const MemberReviewItem = ({ review }: MemberReviewItemProps) => {
return;
}

toast.error('리뷰 좋아요를 다시 시도해주세요.');
toast.error('리뷰 삭제를 다시 시도해주세요.');
},
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Recipe/CommentForm/CommentForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useToastActionContext } from '@fun-eat/design-system';
import type { ChangeEventHandler, FormEventHandler, RefObject } from 'react';
import { useRef, useState } from 'react';

import { commentForm, commentTextarea, container, sendButton } from './commentForm.css';

import { SvgIcon, Text } from '@/components/Common';
import { useToastActionContext } from '@/components/Common/Toast/context';
import { MemberImage } from '@/components/Members';
import { useScroll } from '@/hooks/common';
import { useMemberQuery } from '@/hooks/queries/members';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { container, countWrapper } from './recipeFavoriteButton.css';

import HeartEmpty from '@/assets/heart-empty.png';
import { SvgIcon, Text } from '@/components/Common';
import { useToastActionContext } from '@/components/Common/Toast/context';
import { useTimeout } from '@/hooks/common';
import { useMemberQuery } from '@/hooks/queries/members';
import { useRecipeBookmarkMutation, useRecipeFavoriteMutation } from '@/hooks/queries/recipe';
Expand All @@ -17,9 +18,37 @@ const RecipeFavoriteButton = ({ recipeId, favorite, favoriteCount }: RecipeFavor
const { mutate: bookmarkMutate } = useRecipeBookmarkMutation(Number(recipeId));
const { data: member } = useMemberQuery();

const { toast } = useToastActionContext();

const handleToggleFavorite = async () => {
favoriteMutate({ favorite: !favorite });
bookmarkMutate({ bookmark: !favorite });
favoriteMutate(
{ favorite: !favorite },
{
onError: (error) => {
console.log(error);
if (error instanceof Error) {
toast.error(error.message);
return;
}

toast.error('좋아요를 다시 시도해주세요.');
},
}
);
bookmarkMutate(
{ bookmark: !favorite },
{
onError: (error) => {
console.log(error);
if (error instanceof Error) {
toast.error(error.message);
return;
}

toast.error('북마크를 다시 시도해주세요.');
},
}
);
};

const [debouncedToggleFavorite] = useTimeout(handleToggleFavorite, 200);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useToastActionContext } from '@fun-eat/design-system';
import type { FormEventHandler } from 'react';

import RecipeNameInput from '../RecipeNameInput/RecipeNameInput';
import RecipeUsedProducts from '../RecipeUsedProducts/RecipeUsedProducts';

import { FormTextarea, ImageUploader } from '@/components/Common';
import { useToastActionContext } from '@/components/Common/Toast/context';
import { useImageUploader, useFormData } from '@/hooks/common';
import { useRecipeFormValueContext, useRecipeFormActionContext } from '@/hooks/context';
import { useRecipeRegisterFormMutation } from '@/hooks/queries/recipe';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState } from 'react';
import { favoriteButton } from './reviewFavoriteButton.css';

import { SvgIcon, Text } from '@/components/Common';
import { useToastActionContext } from '@/components/Common/Toast/context';
import { useTimeout } from '@/hooks/common';
import { useReviewFavoriteMutation } from '@/hooks/queries/review';
import { vars } from '@/styles/theme.css';
Expand All @@ -23,6 +24,7 @@ const ReviewFavoriteButton = ({ productId, reviewId, favorite, favoriteCount }:
const [favoriteInfo, setFavoriteInfo] = useState(initialFavoriteState);
const { isFavorite, currentFavoriteCount } = favoriteInfo;

const { toast } = useToastActionContext();
const { mutate } = useReviewFavoriteMutation(productId, reviewId);

const handleToggleFavorite = async () => {
Expand All @@ -34,8 +36,14 @@ const ReviewFavoriteButton = ({ productId, reviewId, favorite, favoriteCount }:
mutate(
{ favorite: !isFavorite },
{
onError: () => {
onError: (error) => {
setFavoriteInfo(initialFavoriteState);
if (error instanceof Error) {
toast.error(error.message);
return;
}

toast.error('좋아요를 다시 시도해주세요.');
},
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Spacing, useToastActionContext } from '@fun-eat/design-system';
import { Spacing } from '@fun-eat/design-system';
import type { FormEventHandler } from 'react';
import { useNavigate } from 'react-router-dom';

Expand All @@ -7,6 +7,7 @@ import StarRate from './StarRate/StarRate';
import RebuyCheckbox from '../RebuyCheckbox/RebuyCheckbox';

import { FormTextarea, ImageUploader, SvgIcon, Text } from '@/components/Common';
import { useToastActionContext } from '@/components/Common/Toast/context';
import type { TagValue } from '@/contexts/ReviewFormContext';
import { useFormData, useImageUploader } from '@/hooks/common';
import { useReviewFormActionContext, useReviewFormValueContext } from '@/hooks/context';
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/ReviewFormContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useToastActionContext } from '@fun-eat/design-system';
import type { PropsWithChildren } from 'react';
import { createContext, useState } from 'react';

import { useToastActionContext } from '@/components/Common/Toast/context';
import { MAX_DISPLAYED_TAGS_LENGTH, MIN_DISPLAYED_TAGS_LENGTH } from '@/constants';
import type { ReviewRequest } from '@/types/review';

Expand Down
3 changes: 2 additions & 1 deletion src/hooks/common/useImageUploader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useToastActionContext } from '@fun-eat/design-system';
import imageCompression from 'browser-image-compression';
import { useState } from 'react';

import { useToastActionContext } from '@/components/Common/Toast/context';

const isImageFile = (file: File) => file.type !== 'image/png' && file.type !== 'image/jpeg';

const options = {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/queries/members/useLogoutMutation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useToastActionContext } from '@fun-eat/design-system';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useNavigate } from 'react-router-dom';

import { logoutApi } from '@/apis';
import { useToastActionContext } from '@/components/Common/Toast/context';
import { PATH } from '@/constants/path';

const useLogoutMutation = () => {
Expand Down
7 changes: 0 additions & 7 deletions src/hooks/queries/recipe/useRecipeFavoriteMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ const useRecipeFavoriteMutation = (recipeId: number) => {
},
onError: (error, _, context) => {
queryClient.setQueryData(queryKey, context?.previousRequest);

if (error instanceof Error) {
toast.error(error.message);
return;
}

toast.error('좋아요를 다시 시도해주세요.');
},
onSettled: () => {
queryClient.invalidateQueries({ queryKey: queryKey });
Expand Down
10 changes: 0 additions & 10 deletions src/hooks/queries/review/useReviewFavoriteMutation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useToastActionContext } from '@fun-eat/design-system';
import { useMutation, useQueryClient } from '@tanstack/react-query';

import { productApi } from '@/apis';
Expand All @@ -12,20 +11,11 @@ const patchReviewFavorite = (productId: number, reviewId: number, body: ReviewFa

const useReviewFavoriteMutation = (productId: number, reviewId: number) => {
const queryClient = useQueryClient();
const { toast } = useToastActionContext();

const queryKey = ['product', productId, 'review'];

return useMutation({
mutationFn: (body: ReviewFavoriteRequestBody) => patchReviewFavorite(productId, reviewId, body),
onError: (error) => {
if (error instanceof Error) {
toast.error(error.message);
return;
}

toast.error('좋아요를 다시 시도해주세요.');
},
onSuccess: () => queryClient.invalidateQueries({ queryKey: queryKey }),
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/search/useSearch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useToastActionContext } from '@fun-eat/design-system';
import type { ChangeEventHandler, FormEventHandler, MouseEventHandler } from 'react';
import { useRef, useState } from 'react';
import { useNavigate, useSearchParams } from 'react-router-dom';

import { useGA } from '../common';

import { useToastActionContext } from '@/components/Common/Toast/context';
import { PATH } from '@/constants/path';
import { getLocalStorage, setLocalStorage } from '@/utils/localStorage';

Expand Down
2 changes: 1 addition & 1 deletion src/pages/MemberModifyPage/MemberModifyPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useToastActionContext } from '@fun-eat/design-system';
import type { ChangeEventHandler, FormEventHandler } from 'react';
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
Expand All @@ -17,6 +16,7 @@ import {
} from './memberModifyPage.css';

import { SvgIcon, TopBar } from '@/components/Common';
import { useToastActionContext } from '@/components/Common/Toast/context';
import { MemberModifyInput } from '@/components/Members';
import { IMAGE_MAX_SIZE } from '@/constants';
import { useFormData, useImageUploader } from '@/hooks/common';
Expand Down

0 comments on commit 0e4c1d5

Please sign in to comment.