-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/CR-63/ReviewingModal #68
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useState } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Image from 'next/image'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import activeHeart from '@/public/assets/icons/active-heart.svg'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import defaultHeart from '@/public/assets/icons/default-heart.svg'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| interface ButtonHeartsProps { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onChange: (score: number) => void; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default function ButtonHearts({ onChange }: ButtonHeartsProps) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [clickedArray, setClickedArray] = useState<boolean[]>(Array(5).fill(false)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const handleClick = (index: number) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setClickedArray((prev) => prev.map((_, i) => i <= index)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onChange(index + 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div className="flex w-full flex-col items-start justify-between gap-[12px]"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <p className="font-base font-semibold">๋ง์กฑ์ค๋ฌ์ด ๊ฒฝํ์ด์๋์?</p> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {Array.from({ length: 5 }).map((_, index) => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <button type="button" onClick={() => handleClick(index)} key={`btn ${index + 1}`}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <Image | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| src={clickedArray[index] ? activeHeart : defaultHeart} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| width={24} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| height={24} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| alt="heartbtn" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </button> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ))} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ ๏ธ Refactor suggestion ์ ๊ทผ์ฑ ๊ฐ์ ํ์ ์น ์ ๊ทผ์ฑ ํฅ์์ ์ํ ๊ฐ์ ์ฌํญ์ ์ ์ํฉ๋๋ค:
<div className="flex w-full flex-col items-start justify-between gap-[12px]">
- <p className="font-base font-semibold">๋ง์กฑ์ค๋ฌ์ด ๊ฒฝํ์ด์๋์?</p>
+ <p className="font-base font-semibold" id="rating-description">๋ง์กฑ์ค๋ฌ์ด ๊ฒฝํ์ด์๋์?</p>
<div>
{Array.from({ length: 5 }).map((_, index) => (
<button
type="button"
onClick={() => handleClick(index)}
key={`btn ${index + 1}`}
+ aria-label={`${index + 1}์ ์ ํ`}
+ aria-pressed={clickedArray[index]}
+ aria-describedby="rating-description"
>
<Image
src={clickedArray[index] ? activeHeart : defaultHeart}
width={24}
height={24}
- alt="heartbtn"
+ alt={clickedArray[index] ? '์ฑ์์ง ํํธ' : '๋น ํํธ'}
/>
</button>
))}
</div>
</div>๐ Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { useState } from 'react'; | ||
| import { useForm } from 'react-hook-form'; | ||
| import Button from '@/src/components/common/button'; | ||
| import Textarea from '@/src/components/common/input/textarea'; | ||
| import ButtonHearts from './button-hearts'; | ||
|
|
||
| type FormValues = { | ||
| reviewText: string; | ||
| score: number; | ||
| }; | ||
|
|
||
| interface ReviewProps { | ||
| onCancel: () => void; | ||
| } | ||
|
|
||
| export default function ReviewForm({ onCancel }: ReviewProps) { | ||
| const { register, handleSubmit } = useForm<FormValues>(); | ||
| const [textReview, setTextReview] = useState<string>(''); | ||
| const [point, setPoint] = useState<number>(0); | ||
|
|
||
|
Comment on lines
+16
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ ๏ธ Refactor suggestion ํผ ์ด๊ธฐํ ๋ฐ ์ ํจ์ฑ ๊ฒ์ฌ ์ค์ ๊ฐ์ ํ์ useForm ํ ์ ๊ธฐ๋ณธ ์ต์ ์ด ์ค์ ๋์ด ์์ง ์์ต๋๋ค. ๋ค์ ์ฌํญ๋ค์ ์ถ๊ฐํ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค:
- const { register, handleSubmit } = useForm<FormValues>();
+ const { register, handleSubmit } = useForm<FormValues>({
+ defaultValues: {
+ reviewText: '',
+ score: 0
+ },
+ mode: 'onChange'
+ });
|
||
| // TODO : ์ฃผ์ ๋ถ๋ถ(api ์ฐ๊ฒฐ) ์์ | ||
| // TODO : form์ ๋ฃ๊ธฐ: onSubmit={handleSubmit(clickSubmit)} | ||
|
|
||
| const handleTextChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => { | ||
| setTextReview(e.target.value); | ||
| }; | ||
|
|
||
| const handleScoreChange = (newScore: number) => { | ||
| setPoint(newScore); | ||
| }; | ||
|
|
||
| return ( | ||
| <form className="flex h-[308px] w-[472px] flex-col justify-between gap-[24px]"> | ||
| <ButtonHearts onChange={handleScoreChange} /> | ||
| <Textarea | ||
| placeholder="๋จ๊ฒจ์ฃผ์ ๋ฆฌ๋ทฐ๋ ํ๋ก๊ทธ๋จ ์ด์ ๋ฐ ๋ค๋ฅธ ํ์ ๋ถ๋ค๊ป ํฐ ๋์์ด ๋ฉ๋๋ค." | ||
| inputClassNames="w-[471px] h-[120px] bg-gray-50 text-gray-400" | ||
| value={textReview} | ||
| onChange={handleTextChange} | ||
| register={register('reviewText')} | ||
| label="๊ฒฝํ์ ๋ํด ๋จ๊ฒจ์ฃผ์ธ์" | ||
| styles={{ | ||
| input: { | ||
| '::placeholder': { | ||
| color: 'gray - 400', | ||
| fontWeight: 500, | ||
| fontSize: '1rem', | ||
| }, | ||
| }, | ||
| label: { | ||
| fontWeight: 600, | ||
| fontSize: '1rem', | ||
| }, | ||
| }} | ||
| /> | ||
| <input type="hidden" value={point} {...register('score')} /> | ||
| <div className="font-base flex justify-between gap-[16px] font-semibold"> | ||
| <Button | ||
| onClick={onCancel} | ||
| className="h-[44px] w-[228px] border border-blue-500 text-blue-500" | ||
| > | ||
| ์ทจ์ | ||
| </Button> | ||
| <Button type="submit" className="h-[44px] w-[228px] border-none bg-blue-500 text-white"> | ||
| ๋ฆฌ๋ทฐ ๋ฑ๋ก | ||
| </Button> | ||
| </div> | ||
| </form> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { useEffect, useState } from 'react'; | ||
| import { Button } from '@mantine/core'; | ||
| import { action } from '@storybook/addon-actions'; | ||
| import { Meta, StoryFn } from '@storybook/react'; | ||
| import ReviewingModal, { ReviewingModalProps } from './reviewing-modal'; | ||
|
|
||
| const meta: Meta<typeof ReviewingModal> = { | ||
| title: 'Modal/ReviewingModal', | ||
| component: ReviewingModal, | ||
| argTypes: { opened: { control: 'boolean' } }, | ||
| }; | ||
|
|
||
| export default meta; | ||
| const Template: StoryFn<ReviewingModalProps> = function GatheringDetailModalStory({ | ||
| opened, | ||
| }: ReviewingModalProps) { | ||
| const [isOpened, setIsOpened] = useState(opened); | ||
|
|
||
| const handleOpen = () => { | ||
| action('Modal Opened')(); | ||
| setIsOpened(true); | ||
| }; | ||
|
|
||
| const handleClose = () => { | ||
| action('Modal Closed')(); | ||
| setIsOpened(false); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| setIsOpened(opened); | ||
| }, [opened]); | ||
|
|
||
| return ( | ||
| <> | ||
| <Button onClick={handleOpen}>Open Modal</Button> | ||
| <ReviewingModal opened={isOpened} close={handleClose} /> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export const Default = Template.bind({}); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| 'use client'; | ||
|
|
||
| import React from 'react'; | ||
| import { Modal } from '@mantine/core'; | ||
| import ReviewForm from './review-form'; | ||
|
|
||
| export interface ReviewingModalProps { | ||
| opened: boolean; | ||
| close: () => void; | ||
| } | ||
|
|
||
| export default function ReviewingModal({ opened, close }: ReviewingModalProps) { | ||
| return ( | ||
| <Modal | ||
| opened={opened} | ||
| centered | ||
| title="๋ฆฌ๋ทฐ ์ฐ๊ธฐ" | ||
| onClose={close} | ||
| size="auto" | ||
| padding={24} | ||
| radius={12} | ||
| overlayProps={{ backgroundOpacity: 0.5 }} | ||
| styles={{ | ||
| title: { | ||
| fontWeight: 600, | ||
| fontSize: '1.125rem', | ||
| }, | ||
| body: { | ||
| fontFamily: 'var(--font-pretendard)', | ||
| }, | ||
| }} | ||
| > | ||
| <ReviewForm onCancel={close} /> | ||
| </Modal> | ||
| ); | ||
| } |
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.
๐ ๏ธ Refactor suggestion
์ด๋ฒคํธ ํธ๋ค๋ฌ ๊ฐ์ ํ์
์ด๋ฒคํธ ํธ๋ค๋ฌ์ ์์ ์ฑ๊ณผ ๊ฐ๋ ์ฑ์ ๋์ด๊ธฐ ์ํ ๊ฐ์ ์ฌํญ์ ์ ์ํฉ๋๋ค:
๐ Committable suggestion