-
Notifications
You must be signed in to change notification settings - Fork 0
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
[혜택관리] 혜택 문구 추가, 수정 기능 추가 #72
Changes from all commits
1d09800
266b337
3ddf0a6
20e2d64
20badd4
07d0a66
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 |
---|---|---|
|
@@ -4,19 +4,6 @@ export const SearchWrapper = styled.div` | |
position: relative; | ||
`; | ||
|
||
export const SelectContainer = styled.div` | ||
display: grid; | ||
grid-template-columns: 1fr 1fr 1fr; | ||
grid-template-rows: repeat(auto-fill, 50px); | ||
place-items: center; | ||
width: 100%; | ||
height: 600px; | ||
overflow: auto; | ||
padding: 25px; | ||
border: 0.5px solid #eeeeeeff; | ||
background: #eee; | ||
`; | ||
|
||
export const FlexColumn = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
|
@@ -54,12 +41,12 @@ export const ButtonContent = styled.span` | |
`; | ||
|
||
export const ButtonWrapper = styled.div` | ||
display: relative; | ||
position: relative; | ||
`; | ||
|
||
export const DeleteButtonWrapper = styled.button` | ||
position: absolute; | ||
top: -10px; | ||
top: -15px; | ||
left: -10px; | ||
background: none; | ||
border: none; | ||
|
@@ -72,3 +59,10 @@ export const FlexRight = styled.div` | |
justify-content: flex-end; | ||
margin-top: 10px | ||
`; | ||
|
||
export const DetailInput = styled.input` | ||
width: 100%; | ||
height: 100%; | ||
border: none; | ||
outline: none; | ||
`; | ||
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. 코드 리뷰 결과에 따라 몇 가지 개선 사항을 제안합니다.
다음은 개선이 필요한 부분에 대한 diff 형식 제안입니다: @@ -1,6 +1,7 @@
/*
- SelectContainer는 현재 사용되지 않습니다. 필요에 따라 다시 활성화할 수 있습니다.
+ SelectContainer가 주석처리된 이유에 대한 설명이 필요합니다.
*/
-export const SelectContainer = styled.div`
+// export const SelectContainer = styled.div`
@@ -54,12 +55,12 @@ export const ButtonContent = styled.span`
- display: relative;
+ position: relative; // display 속성 대신 position 속성 사용
`;
export const DeleteButtonWrapper = styled.button`
position: absolute;
- top: -10px;
+ top: -15px; // 위치 조정 필요성에 대한 설명 추가
left: -10px;
background: none;
border: none;
@@ -72,3 +73,10 @@ export const FlexRight = styled.div`
margin-top: 10px;
`;
+// DetailInput은 특정 폼에 사용될 입력 필드입니다.
export const DetailInput = styled.input`
width: 100%;
height: 100%;
border: none;
outline: none;
`; 각 수정 사항에 주석을 추가하여 코드의 맥락을 명확히 할 수 있도록 했습니다. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { | ||
Divider, Button, message, | ||
} from 'antd'; | ||
import { MinusCircleOutlined, UploadOutlined } from '@ant-design/icons'; | ||
import * as S from 'pages/Services/Benefit/components/AdditionalModal/index.style'; | ||
import { ShopInfo } from 'model/benefit.model'; | ||
import { useEffect, useState } from 'react'; | ||
import { useModifyBenefitDetailsMutation } from 'store/api/benefit'; | ||
import * as Style from 'pages/Services/Benefit/index.style'; | ||
|
||
interface Props { | ||
closeBenefitModifyModal: () => void; | ||
shops?: ShopInfo[]; | ||
} | ||
|
||
interface ModifyDetails { | ||
shop_id: number; | ||
detail: string; | ||
name: string; | ||
shop_benefit_map_id: number; | ||
} | ||
|
||
export default function BenefitDetailModifyModal({ closeBenefitModifyModal, shops }: Props) { | ||
const [details, setDetails] = useState<ModifyDetails[]>([]); | ||
const [mutation] = useModifyBenefitDetailsMutation(); | ||
|
||
const handleDetail = (e: React.ChangeEvent<HTMLInputElement>, shopId: number) => { | ||
const { value } = e.target; | ||
const shopDetail = details.find((shop) => shop.shop_id === shopId); | ||
if (shopDetail) { | ||
const findItem = details.find((shop) => shop.shop_id === shopId); | ||
if (!findItem) return; | ||
const newDetail = { | ||
Comment on lines
+29
to
+33
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. 좀 더 깔끔하게 어떻게하면 좋을까요? |
||
shop_id: findItem.shop_id, | ||
detail: value, | ||
name: findItem.name, | ||
shop_benefit_map_id: findItem.shop_benefit_map_id, | ||
}; | ||
const filteredDetail = details.filter((shop) => shop.shop_id !== shopId); | ||
setDetails([...filteredDetail, newDetail]); | ||
} else { | ||
setDetails((prev) => [...prev, { | ||
shop_id: shopId, | ||
detail: value, | ||
name: shops?.find((shop) => shop.id === shopId)?.name || '', | ||
shop_benefit_map_id: shops?.find((shop) => shop.id === shopId)?.shop_benefit_map_id || 0, | ||
}]); | ||
} | ||
}; | ||
|
||
const modifyDetails = () => { | ||
const shopDetails = details.map((shop) => ({ | ||
shop_benefit_map_id: shop.shop_benefit_map_id, | ||
detail: shop.detail, | ||
})); | ||
mutation({ modify_details: shopDetails }); | ||
}; | ||
|
||
const confirmModifyDetails = () => { | ||
if (details.some((shop) => shop.detail.trim() === '')) { | ||
message.error('상세정보를 입력해주세요.'); | ||
return; | ||
} | ||
modifyDetails(); | ||
closeBenefitModifyModal(); | ||
}; | ||
|
||
useEffect(() => { | ||
if (shops) { | ||
const shopDetails = shops.map((shop) => ({ | ||
shop_id: shop.id, | ||
detail: shop.detail, | ||
name: shop.name, | ||
shop_benefit_map_id: shop.shop_benefit_map_id, | ||
})); | ||
setDetails(shopDetails); | ||
} | ||
}, [shops]); | ||
|
||
if (!shops) return null; | ||
|
||
return ( | ||
<div> | ||
<Divider orientation="left">선택 상점</Divider> | ||
<Style.ShopList> | ||
<thead> | ||
<Style.HeaderRow> | ||
<Style.HeaderItem>상점명</Style.HeaderItem> | ||
<Style.HeaderItem>상세정보</Style.HeaderItem> | ||
</Style.HeaderRow> | ||
</thead> | ||
<tbody> | ||
{details.map((shop) => ( | ||
<Style.Row key={shop.shop_id} isclicked={false}> | ||
<Style.TitleItem> | ||
<S.ButtonWrapper key={shop.shop_id}> | ||
<S.DeleteButtonWrapper> | ||
<MinusCircleOutlined /> | ||
</S.DeleteButtonWrapper> | ||
{shop.name} | ||
</S.ButtonWrapper> | ||
</Style.TitleItem> | ||
<Style.DetailItem> | ||
<S.DetailInput | ||
onChange={(e) => handleDetail(e, shop.shop_id)} | ||
value={details.find((detail) => detail.shop_id === shop.shop_id)?.detail} | ||
/> | ||
</Style.DetailItem> | ||
</Style.Row> | ||
))} | ||
</tbody> | ||
</Style.ShopList> | ||
<S.FlexRight> | ||
<Button | ||
onClick={confirmModifyDetails} | ||
> | ||
<UploadOutlined /> | ||
완료 | ||
</Button> | ||
</S.FlexRight> | ||
</div> | ||
); | ||
} |
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.
코드 검토 결과, 다음과 같은 주요 사항과 개선점을 확인했습니다:
Shops
와ShopInfo
의 관계를 명확히 하기 위해ShopInfo
가Shops
를 확장하는 형태로 수정되었습니다. 이는 데이터의 의미를 명확히 하고 혼동을 줄일 수 있습니다.AddShopRequest
에서DeleteShopsRequest
를 상속받지 않는 것을 권장합니다. 대신 새로운 필드인shop_details
를 추가하여 이 요청의 목적을 더 분명하게 나타냅니다.아래는 개선이 필요한 부분의 diff 형식입니다:
이와 같은 개선 사항을 통해 코드의 가독성과 유지보수성을 높일 수 있으며, 각 데이터 구조에 대한 명확한 이해를 도울 수 있습니다.