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] 리뷰 작성, 상세 리뷰 보기 페이지에 백엔드 API 연동 및 dotenv-webpack 설치, BASE_URL을 .env로 이동 #78

Merged
merged 8 commits into from
Jul 23, 2024
Merged
1 change: 1 addition & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
dist

yarn-error.log
.env
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@emotion/styled": "^11.11.5",
"@tanstack/react-query": "^5.51.1",
"@tanstack/react-query-devtools": "^5.51.1",
"dotenv-webpack": "^8.1.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router": "^6.24.1",
Expand Down
8 changes: 3 additions & 5 deletions frontend/src/apis/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
const API_BASE_URL = 'http://localhost:8080';

const endPoint = {
postingReview: `${API_BASE_URL}/reviews`,
gettingDetailedReview: (reviewId: number) => `${API_BASE_URL}/reviews/${reviewId}`,
postingReview: `${process.env.API_BASE_URL}/reviews`,
gettingDetailedReview: (reviewId: number) => `${process.env.API_BASE_URL}/reviews/${reviewId}`,
gettingInfoToWriteReview: (reviewerGroupId: number) => `/reviewer-groups/${reviewerGroupId}`,
gettingKeyword: `${API_BASE_URL}/keywords`,
gettingKeyword: `${process.env.API_BASE_URL}/keywords`,
};

export default endPoint;
21 changes: 16 additions & 5 deletions frontend/src/pages/DetailedReviewPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const MOCK_DATA: DetailReviewData = {
name: '올리',
},
createdAt: new Date('2024-07-16'),
reviewGroup: {
reviewerGroup: {
groupId: 123456,
name: 'review-me',
},
Expand All @@ -38,7 +38,7 @@ const DetailedReviewPage = ({}) => {
const fetch = async () => {
try {
setIsLoading(true);
getDetailedReviewApi({ reviewId: 123456 }).then((result) => {
getDetailedReviewApi({ reviewId: 4 }).then((result) => {
setDetailReview(result);
setErrorMessage('');
});
Expand All @@ -52,13 +52,24 @@ const DetailedReviewPage = ({}) => {
};

useEffect(() => {
//fetch();
fetch();
}, []);

if (isLoading) return <div>Loading...</div>;

if (errorMessage) return <div>Error: {errorMessage}</div>;

return (
<>
<ReviewDescription projectName={MOCK_DATA.reviewGroup.name} createdAt={MOCK_DATA.createdAt} isLock={true} />
{MOCK_DATA.contents.map((item, index) => (
<ReviewDescription
projectName={detailReview.reviewerGroup.name}
// NOTE: 프론트에서는 리뷰 작성일을 보여주지만,
// 현재 서버에서 오는 데이터가 deadline인 관계로 (속성 이름, value의 성격 모두 다름)
// 임의의 Date 객체로 하드코딩한 상태임
createdAt={new Date('2024-01-22')}
isLock={true}
/>
{detailReview.contents.map((item, index) => (
<ReviewViewSection question={item.question} answer={item.answer} key={index} />
))}
</>
Expand Down
20 changes: 11 additions & 9 deletions frontend/src/pages/ReviewWriting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ const ReviewWritingPage = () => {
const handleSubmitReview = async (event: React.FormEvent) => {
event.preventDefault();

// NOTE: 모킹 데이터
const reviewData: ReviewData = {
reviewerId: 1,
reviewerGroupId: 1,
reviewerId: 8,
reviewerGroupId: 5,
contents: [
{
order: 1,
Expand All @@ -26,20 +27,21 @@ const ReviewWritingPage = () => {
{
order: 2,
question: '2. 동료의 소프트 스킬의 성장을 위해 피드백을 남겨 주세요.',

answer: (event.target as any).question2.value,
},
{
order: 3,
question: '3. 마지막 질문',

answer: (event.target as any).question2.value,
},
],
selectedKeywordIds: [
(event.target as any).keyword1.checked ? 1 : null,
(event.target as any).keyword2.checked ? 2 : null,
(event.target as any).keyword3.checked ? 3 : null,
].filter(Boolean) as number[],
selectedKeywordIds: [1, 2],
};

//console.log(reviewData);
try {
await postReviewApi({ reviewData });
console.log('Review submitted successfully');
} catch (error) {
console.error('Failed to submit review:', error);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface DetailReviewData {
memberId: number;
name: string;
};
reviewGroup: {
reviewerGroup: {
groupId: number;
name: string;
};
Expand Down
4 changes: 4 additions & 0 deletions frontend/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const Dotenv = require('dotenv-webpack');

module.exports = (env, argv) => {
const isProduction = argv.mode === 'production';
Expand Down Expand Up @@ -49,6 +50,9 @@ module.exports = (env, argv) => {
hash: true,
}),
new CleanWebpackPlugin(),
new Dotenv({
path: './.env',
}),
],
devtool: isProduction ? 'hidden-source-map' : 'eval',
devServer: {
Expand Down
19 changes: 19 additions & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2945,6 +2945,25 @@ dot-case@^3.0.4:
no-case "^3.0.4"
tslib "^2.0.3"

dotenv-defaults@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/dotenv-defaults/-/dotenv-defaults-2.0.2.tgz#6b3ec2e4319aafb70940abda72d3856770ee77ac"
integrity sha512-iOIzovWfsUHU91L5i8bJce3NYK5JXeAwH50Jh6+ARUdLiiGlYWfGw6UkzsYqaXZH/hjE/eCd/PlfM/qqyK0AMg==
dependencies:
dotenv "^8.2.0"

dotenv-webpack@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/dotenv-webpack/-/dotenv-webpack-8.1.0.tgz#4d66abc4a30395b46a030ebcd125320232b54873"
integrity sha512-owK1JcsPkIobeqjVrk6h7jPED/W6ZpdFsMPR+5ursB7/SdgDyO+VzAU+szK8C8u3qUhtENyYnj8eyXMR5kkGag==
dependencies:
dotenv-defaults "^2.0.2"

dotenv@^8.2.0:
version "8.6.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.6.0.tgz#061af664d19f7f4d8fc6e4ff9b584ce237adcb8b"
integrity sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==

eastasianwidth@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/eastasianwidth/-/eastasianwidth-0.2.0.tgz#696ce2ec0aa0e6ea93a397ffcf24aa7840c827cb"
Expand Down