-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/editreview modal #80
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
Merged
llmojoll
merged 7 commits into
codeit-part3-7:dev
from
llmojoll:feature/editreview-modal
Jul 29, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8302d38
Feat : ๋ฆฌ๋ทฐ ๋ฑ๋ก ๋ชจ๋ฌ ๊ธ์ด์ค๋์ค
llmojoll daca2ae
Feat : addreview ๋ธ๋์น์์ ํด๋,ํ์ผ,์ด๋ฏธ์ง ๊ฐ์ง๊ณ ์ด
llmojoll 0bc46d0
Feat : patch api ์ฐ๊ฒฐ ํ
์คํธ๋ ๋ฆฌ๋ทฐ๋ฐ์ดํฐ๊ฐ์์...
llmojoll d450c5e
Fix : ํ
์คํธ์ฝ๋ ์ถ๊ฐ , ์์ ํ๊ธฐ ๋ฒํผ ๋๋ฅผ์ reset ์ญ์
llmojoll e3d0a85
Feat : editapi ํ
์คํธ ์๋ฃ , ํ
์คํธ ์ฝ๋ ์ญ์
llmojoll bd413b5
Refactor : TanStack-Query Mutation๋ฐฉ์์ผ๋ก ์์
llmojoll 1f3f557
Merge branch 'dev' into feature/editreview-modal
llmojoll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,28 @@ | ||
| import apiClient from '@/api/apiClient'; | ||
|
|
||
| interface UpdateReviewRequest { | ||
| reviewId: number; | ||
| rating: number; | ||
| lightBold: number; | ||
| smoothTannic: number; | ||
| drySweet: number; | ||
| softAcidic: number; | ||
| aroma: string[]; | ||
| content: string; | ||
| } | ||
|
|
||
| interface UpdateReviewResponse { | ||
| success: boolean; | ||
| message?: string; | ||
| } | ||
|
|
||
| export const updateReview = async ({ | ||
| reviewId, | ||
| ...body | ||
| }: UpdateReviewRequest): Promise<UpdateReviewResponse> => { | ||
| const response = await apiClient.patch<UpdateReviewResponse>( | ||
| `/${process.env.NEXT_PUBLIC_TEAM}/reviews/${reviewId}`, | ||
| body, | ||
| ); | ||
| return response.data; | ||
| }; |
This file contains hidden or 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,305 @@ | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
| import Image from 'next/image'; | ||
| import { useForm } from 'react-hook-form'; | ||
|
|
||
| import { updateReview } from '@/api/editreview'; | ||
| import BasicModal from '@/components/common/Modal/BasicModal'; | ||
| import StarRating from '@/components/Modal/ReviewModal/StarRating'; | ||
| import { cn } from '@/lib/utils'; | ||
|
|
||
| import FlavorSlider from '../../common/slider/FlavorSlider'; | ||
| import { Badge } from '../../ui/badge'; | ||
| import { Button } from '../../ui/button'; | ||
|
|
||
| interface ReviewForm { | ||
| rating: number; | ||
| sliderLightBold: number; | ||
| sliderSmoothTanic: number; | ||
| sliderdrySweet: number; | ||
| slidersoftAcidic: number; | ||
| aroma: Array<string>; | ||
| content: string; | ||
| } | ||
|
|
||
| interface ReviewData { | ||
| reviewId: number; | ||
| rating: number; | ||
| sliderLightBold: number; | ||
| sliderSmoothTanic: number; | ||
| sliderdrySweet: number; | ||
| slidersoftAcidic: number; | ||
| aroma: string[]; | ||
| content: string; | ||
| } | ||
|
|
||
| const aromaOptions = [ | ||
| '์ฒด๋ฆฌ', | ||
| '๋ฒ ๋ฆฌ', | ||
| '์คํฌ', | ||
| '๋ฐ๋๋ผ', | ||
| 'ํ์ถ', | ||
| '์ ๋นต', | ||
| 'ํ', | ||
| '์ฌ๊ณผ', | ||
| '๋ณต์ญ์', | ||
| '์ํธ๋ฌ์ค', | ||
| 'ํธ๋กํผ์ปฌ', | ||
| '๋ฏธ๋ค๋', | ||
| '๊ฝ', | ||
| '๋ด๋ฑ์', | ||
| 'ํ', | ||
| '์ด์ฝ๋ฆฟ', | ||
| '์คํ์ด์ค', | ||
| '์นด๋ผ๋ฉ', | ||
| '๊ฐ์ฃฝ', | ||
| ]; | ||
|
|
||
| const aromaMap: Record<string, string> = { | ||
| ์ฒด๋ฆฌ: 'CHERRY', | ||
| ๋ฒ ๋ฆฌ: 'BERRY', | ||
| ์คํฌ: 'OAK', | ||
| ๋ฐ๋๋ผ: 'VANILLA', | ||
| ํ์ถ: 'PEPPER', | ||
| ์ ๋นต: 'BAKERY', | ||
| ํ: 'GRASS', | ||
| ์ฌ๊ณผ: 'APPLE', | ||
| ๋ณต์ญ์: 'PEACH', | ||
| ์ํธ๋ฌ์ค: 'CITRUS', | ||
| ํธ๋กํผ์ปฌ: 'TROPICAL', | ||
| ๋ฏธ๋ค๋: 'MINERAL', | ||
| ๊ฝ: 'FLOWER', | ||
| ๋ด๋ฑ์: 'TOBACCO', | ||
| ํ: 'EARTH', | ||
| ์ด์ฝ๋ฆฟ: 'CHOCOLATE', | ||
| ์คํ์ด์ค: 'SPICE', | ||
| ์นด๋ผ๋ฉ: 'CARAMEL', | ||
| ๊ฐ์ฃฝ: 'LEATHER', | ||
| }; | ||
|
|
||
| const EditReviewModal = ({ | ||
| wineName, | ||
| reviewData, | ||
| }: { | ||
| wineName: string; | ||
| reviewData: ReviewData; | ||
| }) => { | ||
| const [showEditModal, setShowEditModal] = useState(false); | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| const updateReviewMutation = useMutation({ | ||
| mutationFn: updateReview, | ||
| onSuccess: () => { | ||
| console.log('๋ฆฌ๋ทฐ ์์ ์๋ฃ'); | ||
| queryClient.invalidateQueries({ queryKey: ['reviews'] }); | ||
| setShowEditModal(false); | ||
| }, | ||
| onError: (error) => { | ||
| console.log('๋ฆฌ๋ทฐ ์์ ์คํจ', error); | ||
| }, | ||
| }); | ||
|
|
||
| const { | ||
| register, | ||
| handleSubmit, | ||
| formState: { errors }, | ||
| clearErrors, | ||
| reset, | ||
| watch, | ||
| setValue, | ||
| setError, | ||
| } = useForm<ReviewForm>({ | ||
| defaultValues: { | ||
| rating: reviewData.rating, | ||
| sliderLightBold: reviewData.sliderLightBold, | ||
| sliderSmoothTanic: reviewData.sliderSmoothTanic, | ||
| sliderdrySweet: reviewData.sliderdrySweet, | ||
| slidersoftAcidic: reviewData.slidersoftAcidic, | ||
| content: reviewData.content, | ||
| aroma: reviewData.aroma.map((eng) => { | ||
| const kor = Object.keys(aromaMap).find((key) => aromaMap[key] === eng); | ||
| return kor || eng; | ||
| }), | ||
| }, | ||
| }); | ||
|
|
||
| const aroma = watch('aroma'); | ||
| const isSelected = (item: string) => aroma?.includes(item); | ||
|
|
||
| const toggleAroma = (item: string) => { | ||
| if (!aroma) return; | ||
| if (aroma.includes(item)) { | ||
| setValue( | ||
| 'aroma', | ||
| aroma.filter((a) => a !== item), | ||
| ); | ||
| } else { | ||
| setValue('aroma', [...aroma, item]); | ||
| } | ||
| clearErrors('aroma'); | ||
| }; | ||
|
|
||
| const onSubmit = async (data: ReviewForm) => { | ||
| if (!data.aroma || data.aroma.length === 0) { | ||
| setError('aroma', { type: 'errmsg', message: '์ต์ ํ๋์ ํฅ์ ์ ํํด์ฃผ์ธ์.' }); | ||
| return; | ||
| } | ||
| const fullData = { | ||
| reviewId: reviewData.reviewId, | ||
| rating: data.rating, | ||
| lightBold: data.sliderLightBold, | ||
| smoothTannic: data.sliderSmoothTanic, | ||
| drySweet: data.sliderdrySweet, | ||
| softAcidic: data.slidersoftAcidic, | ||
| aroma: data.aroma.map((a) => aromaMap[a]).filter(Boolean), | ||
| content: data.content, | ||
| }; | ||
| updateReviewMutation.mutate(fullData); | ||
| }; | ||
|
|
||
| const closeModalReset = (isOpen: boolean) => { | ||
| setShowEditModal(isOpen); | ||
| if (!isOpen) { | ||
| reset(); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <Button variant='purpleDark' size='xs' width='sm' onClick={() => setShowEditModal(true)}> | ||
| ๋ฆฌ๋ทฐ ์์ ํ๊ธฐ | ||
| </Button> | ||
| <BasicModal | ||
| type='review' | ||
| title='๋ฆฌ๋ทฐ ์์ ' | ||
| open={showEditModal} | ||
| onOpenChange={closeModalReset} | ||
| buttons={ | ||
| <Button | ||
| onClick={handleSubmit(onSubmit)} | ||
| type='button' | ||
| variant='purpleDark' | ||
| size='xl' | ||
| width='full' | ||
| fontSize='lg' | ||
| > | ||
| ์์ ์๋ฃ | ||
| </Button> | ||
| } | ||
| > | ||
| <form | ||
| onSubmit={handleSubmit(onSubmit)} | ||
| encType='multipart/form-data' | ||
| className='my-[32px] md:my-[40px]' | ||
| > | ||
| <div className='w-[274px] md:w-[384px] h-[84px] md:h-[68px] mb-6 flex items-center'> | ||
| <Image | ||
| src='/assets/reviewicon.png' | ||
| alt='๋ฆฌ๋ทฐ ์์ด์ฝ' | ||
| width={68} | ||
| height={68} | ||
| className='bg-gray-100 rounded-lg p-[7px] object-contain' | ||
| /> | ||
| <div className='ml-4'> | ||
| <span className='custom-text-lg-bold md:custom-text-2lg-semibold'>{wineName}</span> | ||
| <div className='mt-2'> | ||
| <StarRating value={watch('rating')} onChange={(val) => setValue('rating', val)} /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <textarea | ||
| id='content' | ||
| {...register('content', { | ||
| required: '๋ฆฌ๋ทฐ ๋ด์ฉ์ ์ ๋ ฅํด ์ฃผ์ธ์.', | ||
| onChange: () => clearErrors('content'), | ||
| })} | ||
| placeholder='ํ๊ธฐ๋ฅผ ์์ฑํด ์ฃผ์ธ์' | ||
| className={cn( | ||
| 'h-[100px] md:h-[120px] w-full px-[20px] py-[14px] rounded-[16px] bg-white border border-gray-300 outline-none font-sans resize-none', | ||
| errors.content && 'border-red-500', | ||
| )} | ||
| rows={5} | ||
| /> | ||
| {errors.content && ( | ||
| <div role='alert' className='text-red-500 mt-1'> | ||
| {errors.content.message} | ||
| </div> | ||
| )} | ||
|
|
||
| <p className='custom-text-2lg-bold md:custom-text-xl-bold mb-[24px] mt-[35px]'> | ||
| ์์ธ์ ๋ง์ ์ด๋ ๋์? | ||
| </p> | ||
|
|
||
| <div className='mb-[40px] space-y-[18px]'> | ||
| <FlavorSlider | ||
| value={watch('sliderLightBold')} | ||
| min={0} | ||
| max={10} | ||
| step={1} | ||
| onChange={(val) => setValue('sliderLightBold', val)} | ||
| labelLeft='๊ฐ๋ฒผ์์' | ||
| labelRight='์งํด์' | ||
| badgeLabel='๋ฐ๋๊ฐ' | ||
| /> | ||
| <FlavorSlider | ||
| value={watch('sliderSmoothTanic')} | ||
| min={0} | ||
| max={10} | ||
| step={1} | ||
| onChange={(val) => setValue('sliderSmoothTanic', val)} | ||
| labelLeft='๋ถ๋๋ฌ์์' | ||
| labelRight='๋ซ์ด์' | ||
| badgeLabel='ํ๋' | ||
| /> | ||
| <FlavorSlider | ||
| value={watch('sliderdrySweet')} | ||
| min={0} | ||
| max={10} | ||
| step={1} | ||
| onChange={(val) => setValue('sliderdrySweet', val)} | ||
| labelLeft='๋๋ผ์ดํด์' | ||
| labelRight='๋ฌ์์' | ||
| badgeLabel='๋น๋' | ||
| /> | ||
| <FlavorSlider | ||
| value={watch('slidersoftAcidic')} | ||
| min={0} | ||
| max={10} | ||
| step={1} | ||
| onChange={(val) => setValue('slidersoftAcidic', val)} | ||
| labelLeft='์ ์ ์' | ||
| labelRight='๋ง์ด ์ ์' | ||
| badgeLabel='์ฐ๋ฏธ' | ||
| /> | ||
| </div> | ||
|
|
||
| <p className='custom-text-2lg-bold md:custom-text-xl-bold'>๊ธฐ์ต์ ๋จ๋ ํฅ์ด ์๋์?</p> | ||
| {errors.aroma && ( | ||
| <div role='alert' className='text-red-500 mt-1'> | ||
| {errors.aroma.message} | ||
| </div> | ||
| )} | ||
| <div className='relative flex flex-wrap gap-[10px] mt-6'> | ||
| {aromaOptions.map((item) => ( | ||
| <Badge | ||
| key={item} | ||
| variant='chooseFlavor' | ||
| onClick={() => toggleAroma(item)} | ||
| className={cn( | ||
| 'cursor-pointer px-2.5 md:px-[18px] py-1.5 md:py-2.5 hover:bg-primary-100 hover:text-primary hover:border-primary-100', | ||
| isSelected(item) && 'bg-primary text-white', | ||
| )} | ||
| > | ||
| {item} | ||
| </Badge> | ||
| ))} | ||
| </div> | ||
| </form> | ||
| </BasicModal> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default EditReviewModal; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as const๋ฅผ ์ฐ๊ณ ๋ค๋ฅธ ๋ถ๋ถ๋ค๋ typeof aromaOptions์ ์ฐ๋ฉด ๋ ์๊ฒฉํ๊ฒ ์ฌ์ฉํ ์ ์์ ๊ฒ ๊ฐ์๋ฐ
ํฌ๋ฆฌํฐ์ปฌ ํ์ง ์์ผ๋ ๋ค์์ ์๊ฐํด๋ณด์ ๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค :)