-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from SOPT-all/develop
merge to main
- Loading branch information
Showing
19 changed files
with
244 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import instance from '@apis/instance'; | ||
|
||
const fetchOrderProduct = async (productId: number) => { | ||
const response = await instance.post(`/api/order`, { | ||
productId, | ||
}); | ||
|
||
return response.data; | ||
}; | ||
|
||
export default fetchOrderProduct; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import fetchOrderProduct from '@apis/productPage/order/orderProduct'; | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
const useOrderProduct = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
const mutation = useMutation({ | ||
mutationFn: (productId: number) => fetchOrderProduct(productId), | ||
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['order'] }), | ||
}); | ||
|
||
return { mutate: mutation.mutate }; | ||
}; | ||
|
||
export default useOrderProduct; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import instance from '@apis/instance'; | ||
import { AxiosError } from 'axios'; | ||
|
||
export interface Review { | ||
reviewId: number; | ||
username: string; | ||
rating: number; | ||
isMonth: boolean; | ||
contentKorean: string; | ||
contentOriginal: string; | ||
reviewImage: string; | ||
usefulCount: number; | ||
recommendCount: number; | ||
likeCount: number; | ||
} | ||
|
||
export interface GetReviewResponse { | ||
success: boolean; | ||
data: { | ||
goodReviews: Review[]; | ||
badReviews: Review[]; | ||
}; | ||
error: null | string; | ||
} | ||
|
||
export const getReview = async (productId: number): Promise<GetReviewResponse> => { | ||
try { | ||
const response = await instance.get<GetReviewResponse>(`/api/products/${productId}/reviews`); | ||
return response.data; | ||
} catch (error) { | ||
if (error instanceof AxiosError) { | ||
throw error.response?.data || new Error('An error occurred'); | ||
} | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { getReview, GetReviewResponse } from './getReview'; | ||
|
||
const useReviewQueries = ({ productId }: { productId: number }) => { | ||
const QUERY_KEY = { | ||
PRODUCT_REVIEW: 'review', | ||
}; | ||
|
||
const { data, error } = useQuery<GetReviewResponse>({ | ||
queryKey: [QUERY_KEY.PRODUCT_REVIEW, productId], | ||
queryFn: () => getReview(productId), | ||
}); | ||
|
||
return { data, error }; | ||
}; | ||
|
||
export default useReviewQueries; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.