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

[FE] refactor: alert를 toast로 변경 #789

Merged
merged 1 commit into from
Oct 18, 2023
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 @@ -4,6 +4,7 @@ import styled from 'styled-components';

import { SvgIcon } from '@/components/Common';
import { useTimeout } from '@/hooks/common';
import { useToastActionContext } from '@/hooks/context';
import { useRecipeFavoriteMutation } from '@/hooks/queries/recipe';

interface RecipeFavoriteProps {
Expand All @@ -15,6 +16,8 @@ interface RecipeFavoriteProps {
const RecipeFavorite = ({ recipeId, favorite, favoriteCount }: RecipeFavoriteProps) => {
const [isFavorite, setIsFavorite] = useState(favorite);
const [currentFavoriteCount, setCurrentFavoriteCount] = useState(favoriteCount);
const { toast } = useToastActionContext();

const { mutate } = useRecipeFavoriteMutation(Number(recipeId));

const handleToggleFavorite = async () => {
Expand All @@ -24,9 +27,10 @@ const RecipeFavorite = ({ recipeId, favorite, favoriteCount }: RecipeFavoritePro
onSuccess: () => {
setIsFavorite((prev) => !prev);
setCurrentFavoriteCount((prev) => (isFavorite ? prev - 1 : prev + 1));
toast.success('🍯 꿀조합이 등록 됐어요');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

등록 토스트 좋네요

},
onError: () => {
alert('꿀조합 좋아요를 다시 시도해주세요.');
toast.error('꿀조합 좋아요를 다시 시도해주세요.');
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import RecipeUsedProducts from '../RecipeUsedProducts/RecipeUsedProducts';

import { ImageUploader, SvgIcon } from '@/components/Common';
import { useImageUploader, useFormData } from '@/hooks/common';
import { useRecipeFormValueContext, useRecipeFormActionContext } from '@/hooks/context';
import { useRecipeFormValueContext, useRecipeFormActionContext, useToastActionContext } from '@/hooks/context';
import { useRecipeRegisterFormMutation } from '@/hooks/queries/recipe';
import type { RecipeRequest } from '@/types/recipe';

Expand All @@ -23,6 +23,7 @@ const RecipeRegisterForm = ({ closeRecipeDialog }: RecipeRegisterFormProps) => {

const recipeFormValue = useRecipeFormValueContext();
const { resetRecipeFormValue } = useRecipeFormActionContext();
const { toast } = useToastActionContext();

const formData = useFormData<RecipeRequest>({
imageKey: 'images',
Expand Down Expand Up @@ -52,11 +53,11 @@ const RecipeRegisterForm = ({ closeRecipeDialog }: RecipeRegisterFormProps) => {
onError: (error) => {
resetAndCloseForm();
if (error instanceof Error) {
alert(error.message);
toast.error(error.message);
return;
}

alert('꿀조합 등록을 다시 시도해주세요');
toast.error('꿀조합 등록을 다시 시도해주세요');
},
});
};
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/components/Review/ReviewItem/ReviewItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import styled from 'styled-components';

import { SvgIcon, TagList } from '@/components/Common';
import { useTimeout } from '@/hooks/common';
import { useToastActionContext } from '@/hooks/context';
import { useReviewFavoriteMutation } from '@/hooks/queries/review';
import type { Review } from '@/types/review';
import { getRelativeDate } from '@/utils/date';
Expand All @@ -18,6 +19,8 @@ const ReviewItem = ({ productId, review }: ReviewItemProps) => {
review;
const [isFavorite, setIsFavorite] = useState(favorite);
const [currentFavoriteCount, setCurrentFavoriteCount] = useState(favoriteCount);

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

const theme = useTheme();
Expand All @@ -32,11 +35,11 @@ const ReviewItem = ({ productId, review }: ReviewItemProps) => {
},
onError: (error) => {
if (error instanceof Error) {
alert(error.message);
toast.error(error.message);
return;
}

alert('리뷰 좋아요를 다시 시도해주세요.');
toast.error('리뷰 좋아요를 다시 시도해주세요.');
},
}
);
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/hooks/queries/members/useLogoutMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { useNavigate } from 'react-router-dom';

import { logoutApi } from '@/apis';
import { PATH } from '@/constants/path';
import { useToastActionContext } from '@/hooks/context';

const useLogoutMutation = () => {
const navigate = useNavigate();
const queryClient = useQueryClient();

const { toast } = useToastActionContext();

return useMutation({
mutationFn: () => logoutApi.post({ credentials: true }),
onSuccess: () => {
Expand All @@ -16,10 +19,10 @@ const useLogoutMutation = () => {
},
onError: (error) => {
if (error instanceof Error) {
alert(error.message);
toast.error(error.message);
return;
}
alert('로그아웃을 다시 시도해주세요.');
toast.error('로그아웃을 다시 시도해주세요.');
},
});
};
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/hooks/search/useSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useRef, useState } from 'react';
import { useSearchParams } from 'react-router-dom';

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

const useSearch = () => {
const inputRef = useRef<HTMLInputElement>(null);
Expand All @@ -14,6 +15,8 @@ const useSearch = () => {
const [isSubmitted, setIsSubmitted] = useState(!!currentSearchQuery);
const [isAutocompleteOpen, setIsAutocompleteOpen] = useState(searchQuery.length > 0);

const { toast } = useToastActionContext();

const { gaEvent } = useGA();

const focusInput = () => {
Expand All @@ -35,7 +38,7 @@ const useSearch = () => {
const trimmedSearchQuery = searchQuery.trim();

if (!trimmedSearchQuery) {
alert('검색어를 입력해주세요');
toast.error('검색어를 입력해주세요');
focusInput();
resetSearchQuery();
return;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/MemberModifyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ export const MemberModifyPage = () => {
},
onError: (error) => {
if (error instanceof Error) {
alert(error.message);
toast.error(error.message);
return;
}

alert('회원정보 수정을 다시 시도해주세요.');
toast.error('회원정보 수정을 다시 시도해주세요.');
},
});
};
Expand Down
Loading