Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
20 changes: 20 additions & 0 deletions src/_apis/review/review-apis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { fetchApi } from '@/src/utils/api';

export interface PostReviewParams {
gatheringId?: number;
point: number;
reviewText: string;
}
Comment on lines +3 to +7
Copy link

Choose a reason for hiding this comment

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

โš ๏ธ Potential issue

gatheringId๋ฅผ ํ•„์ˆ˜ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ณ€๊ฒฝํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค

gatheringId๊ฐ€ ์„ ํƒ์  ๋งค๊ฐœ๋ณ€์ˆ˜(optional)๋กœ ์ •์˜๋˜์–ด ์žˆ์ง€๋งŒ, API ์—”๋“œํฌ์ธํŠธ URL์—์„œ๋Š” ํ•„์ˆ˜๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ด๋Š” ๋Ÿฐํƒ€์ž„ ์˜ค๋ฅ˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์„ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค:

export interface PostReviewParams {
-  gatheringId?: number;
+  gatheringId: number;
  point: number;
  reviewText: string;
}
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export interface PostReviewParams {
gatheringId?: number;
point: number;
reviewText: string;
}
export interface PostReviewParams {
gatheringId: number;
point: number;
reviewText: string;
}


export async function postReview(params: PostReviewParams): Promise<ResponseType> {
const { gatheringId, point, reviewText } = params;

const response = await fetchApi<ResponseType>(`/api/review/${gatheringId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ rate: point, comment: reviewText }),
});
return response;
}
Comment on lines +9 to +20
Copy link

Choose a reason for hiding this comment

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

๐Ÿ› ๏ธ Refactor suggestion

API ์š”์ฒญ ๋ณธ๋ฌธ์˜ ํ•„๋“œ๋ช… ๋ถˆ์ผ์น˜ ๋ฐ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ ๊ฐœ์„  ํ•„์š”

  1. ์ธํ„ฐํŽ˜์ด์Šค์™€ API ์š”์ฒญ ๋ณธ๋ฌธ์˜ ํ•„๋“œ๋ช…์ด ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค:

    • point โ†’ rate
    • reviewText โ†’ comment
  2. API ํ˜ธ์ถœ ์‹คํŒจ์— ๋Œ€ํ•œ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์„ ์ œ์•ˆํ•ฉ๋‹ˆ๋‹ค:

export async function postReview(params: PostReviewParams): Promise<ResponseType> {
  const { gatheringId, point, reviewText } = params;

+ try {
    const response = await fetchApi<ResponseType>(`/api/review/${gatheringId}`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
-     body: JSON.stringify({ rate: point, comment: reviewText }),
+     body: JSON.stringify({ point, reviewText }),
    });
    return response;
+ } catch (error) {
+   console.error('๋ฆฌ๋ทฐ ๋“ฑ๋ก ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:', error);
+   throw new Error('๋ฆฌ๋ทฐ๋ฅผ ๋“ฑ๋กํ•˜๋Š” ์ค‘ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.');
+ }
}

๋˜ํ•œ, API ์‘๋‹ต ํƒ€์ž…์„ ๋ช…์‹œ์ ์œผ๋กœ ์ •์˜ํ•˜๊ณ  ResponseType์„ ๊ตฌ์ฒด์ ์ธ ํƒ€์ž…์œผ๋กœ ๋Œ€์ฒดํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function postReview(params: PostReviewParams): Promise<ResponseType> {
const { gatheringId, point, reviewText } = params;
const response = await fetchApi<ResponseType>(`/api/review/${gatheringId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ rate: point, comment: reviewText }),
});
return response;
}
export async function postReview(params: PostReviewParams): Promise<ResponseType> {
const { gatheringId, point, reviewText } = params;
try {
const response = await fetchApi<ResponseType>(`/api/review/${gatheringId}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ point, reviewText }),
});
return response;
} catch (error) {
console.error('๋ฆฌ๋ทฐ ๋“ฑ๋ก ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:', error);
throw new Error('๋ฆฌ๋ทฐ๋ฅผ ๋“ฑ๋กํ•˜๋Š” ์ค‘ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.');
}
}

2 changes: 2 additions & 0 deletions src/app/(crew)/my-page/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ReactNode } from 'react';
import ProfileCardContainer from '@/src/app/(crew)/my-page/_components/profile-card/container';
import ReviewTabs from './_components/review-tabs';

Expand All @@ -10,6 +11,7 @@ export default function MyPage({ children }: { children: React.ReactNode }) {
<ReviewTabs />
<div>{children}</div>
<div />
<div>{children}</div>
</div>
);
}
65 changes: 50 additions & 15 deletions src/components/my-page/reviewing-modal/review-form.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { useState } from 'react';
import { useForm } from 'react-hook-form';
import { useController, useForm } from 'react-hook-form';
import { Button } from '@mantine/core';
import { useMutation } from '@tanstack/react-query';
import { PostReviewParams, postReview } from '@/src/_apis/review/review-apis';
import { ApiError } from '@/src/utils/api';
import Textarea from '@/src/components/common/input/textarea';
import ButtonHearts from './button-hearts';

Expand All @@ -9,32 +12,61 @@ type FormValues = {
score: number;
};

interface ReviewProps {
interface ReviewFormProps {
gatheringId?: number;
Copy link

Choose a reason for hiding this comment

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

โš ๏ธ Potential issue

gatheringId๋ฅผ ํ•„์ˆ˜ ํ”„๋กœํผํ‹ฐ๋กœ ์ง€์ •ํ•˜์‹ญ์‹œ์˜ค

ํ˜„์žฌ gatheringId๊ฐ€ ์„ ํƒ์ (?)์œผ๋กœ ์ •์˜๋˜์–ด ์žˆ์ง€๋งŒ, ๋ฆฌ๋ทฐ ์ž‘์„ฑ์— ํ•„์ˆ˜์ ์ธ ๊ฐ’์ด๋ฏ€๋กœ ํ•„์ˆ˜ ํ”„๋กœํผํ‹ฐ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•˜์‹ญ์‹œ์˜ค:

interface ReviewFormProps {
-  gatheringId?: number;
+  gatheringId: number;
  onCancel: () => void;
}

Committable suggestion skipped: line range outside the PR's diff.

onCancel: () => void;
}

export default function ReviewForm({ onCancel }: ReviewProps) {
const { register, handleSubmit } = useForm<FormValues>();
export default function ReviewForm({ gatheringId, onCancel }: ReviewFormProps) {
const { register, handleSubmit, control } = useForm<FormValues>();
const [textReview, setTextReview] = useState<string>('');
const [point, setPoint] = useState<number>(0);

// TODO : ์ฃผ์„ ๋ถ€๋ถ„(api ์—ฐ๊ฒฐ) ์ˆ˜์ •
// TODO : form์— ๋„ฃ๊ธฐ: onSubmit={handleSubmit(clickSubmit)}
const {
field: { value: scoreValue, onChange: setScore },
} = useController({ name: 'score', control, defaultValue: 0 });
Comment on lines +24 to +26
Copy link

Choose a reason for hiding this comment

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

โš ๏ธ Potential issue

์ ์ˆ˜(score) ํ•„๋“œ๊ฐ€ ํผ์— ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๋“ฑ๋ก๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค

ํ˜„์žฌ useController ํ›…์—์„œ field๋ฅผ ๊ตฌ์กฐ ๋ถ„ํ•ดํ•˜์—ฌ value์™€ onChange๋งŒ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ <input> ์š”์†Œ์—์„œ field ์ „์ฒด๋ฅผ spreadํ•˜์—ฌ ํผ์— ํ•„๋“œ๋ฅผ ๋“ฑ๋กํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด score ๊ฐ’์ด ํผ ์ œ์ถœ ์‹œ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค.

์ˆ˜์ •์„ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณ€๊ฒฝํ•˜์‹ญ์‹œ์˜ค:

- const {
-   field: { value: scoreValue, onChange: setScore },
- } = useController({ name: 'score', control, defaultValue: 0 });

- <input type="hidden" value={scoreValue} />
+ const { field } = useController({ name: 'score', control, defaultValue: 0 });

+ <input type="hidden" {...field} />

Also applies to: 88-88


const handleTextChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
setTextReview(e.target.value);
if (e.target.value.length <= 300) {
setTextReview(e.target.value);
}
};

const handleScoreChange = (newScore: number) => {
setPoint(newScore);
setScore(newScore);
};

const mutation = useMutation<ResponseType, ApiError, PostReviewParams>({
mutationFn: (params: PostReviewParams) =>
postReview({
gatheringId: params.gatheringId,
point: params.point,
reviewText: params.reviewText,
}),

onSuccess: () => {
onCancel();
},
onError: (error: ApiError) => {
// eslint-disable-next-line no-console
console.error(error);
},
Comment on lines +49 to +52
Copy link

Choose a reason for hiding this comment

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

๐Ÿ› ๏ธ Refactor suggestion

์—๋Ÿฌ ๋ฐœ์ƒ ์‹œ ์‚ฌ์šฉ์ž์—๊ฒŒ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๋ฅผ ํ‘œ์‹œํ•˜์‹ญ์‹œ์˜ค

ํ˜„์žฌ ์—๋Ÿฌ ๋ฐœ์ƒ ์‹œ console.error(error);๋กœ๋งŒ ์ฒ˜๋ฆฌํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž์—๊ฒŒ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Œ์„ ์•Œ๋ฆด ์ˆ˜ ์žˆ๋„๋ก UI ์ƒ์— ์ ์ ˆํ•œ ์˜ค๋ฅ˜ ๋ฉ”์‹œ์ง€๋ฅผ ํ‘œ์‹œํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์‚ฌ์šฉ์ž์—๊ฒŒ ํ‘œ์‹œํ•˜๊ธฐ ์œ„ํ•ด ์•Œ๋ฆผ ๋˜๋Š” ์—๋Ÿฌ ํ‘œ์‹œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์„ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

});

const clickSubmit = (data: FormValues) => {
// eslint-disable-next-line no-console
console.log(data);
mutation.mutate({ gatheringId, point: data.score, reviewText: data.reviewText });
};

return (
<form className="flex h-[308px] w-[472px] flex-col justify-between gap-[24px]">
<form
onSubmit={handleSubmit(clickSubmit)}
className="flex h-auto w-[288px] flex-col justify-between gap-[20px] md:h-[302px] md:w-[472px]"
>
<ButtonHearts onChange={handleScoreChange} />
<Textarea
placeholder="๋‚จ๊ฒจ์ฃผ์‹  ๋ฆฌ๋ทฐ๋Š” ํ”„๋กœ๊ทธ๋žจ ์šด์˜ ๋ฐ ๋‹ค๋ฅธ ํšŒ์› ๋ถ„๋“ค๊ป˜ ํฐ ๋„์›€์ด ๋ฉ๋‹ˆ๋‹ค."
inputClassNames="w-[471px] h-[120px] bg-gray-50 text-gray-400"
inputClassNames="md:w-[472px] md:h-[120px] bg-gray-50 text-gray-900 w-[288px] h-[240px] rounded-[12px]"
value={textReview}
onChange={handleTextChange}
register={register('reviewText')}
Expand All @@ -53,15 +85,18 @@ export default function ReviewForm({ onCancel }: ReviewProps) {
},
}}
/>
<input type="hidden" value={point} {...register('score')} />
<div className="font-base flex justify-between gap-[16px] font-semibold">
<input type="hidden" value={scoreValue} />
<div className="font-base flex w-full justify-between gap-[8px] font-semibold md:gap-[16px]">
<Button
onClick={onCancel}
className="h-[44px] w-[228px] border border-blue-500 bg-white text-blue-500"
className="h-[44px] w-full rounded-[12px] border border-blue-500 bg-white text-blue-500"
>
์ทจ์†Œ
</Button>
<Button type="submit" className="h-[44px] w-[228px] border-none bg-blue-500 text-white">
<Button
type="submit"
className="h-[44px] w-full rounded-[12px] border-none bg-blue-500 text-white"
>
๋ฆฌ๋ทฐ ๋“ฑ๋ก
</Button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/my-page/reviewing-modal/reviewing-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function ReviewingModal({ gatheringId, opened, close }: Reviewing
},
}}
>
<ReviewForm onCancel={close} />
<ReviewForm gatheringId={gatheringId} onCancel={close} />
</Modal>
);
}
Loading