Skip to content

Commit 4fc867e

Browse files
committed
fix: 옵션 form 상태 초기화를 감추기 위해 fold를 접도록 임시 대응
1 parent 773b2f5 commit 4fc867e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/common/src/components/mdx_components/one_details_opener.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ import * as React from "react";
33

44
type PHOpenOneFoldMgrPropType = {
55
children: React.ReactElement<AccordionProps>[];
6+
resetKey?: string;
67
};
78

89
export const OneDetailsOpener: React.FC<PHOpenOneFoldMgrPropType> = (props) => {
910
const childrenCount = React.Children.count(props.children);
1011
const initialFoldState = new Array(childrenCount).fill(false);
1112
const [oneFoldOpener, setOneFoldOpener] = React.useState(initialFoldState);
13+
const foldAll = () => setOneFoldOpener([...initialFoldState]);
14+
15+
// eslint-disable-next-line react-hooks/exhaustive-deps
16+
React.useEffect(foldAll, [props.resetKey]);
17+
1218
const foldStateSwitcher =
1319
(index: number): ((event: React.SyntheticEvent<Element, Event>, expanded: boolean) => void) =>
1420
(event, expanded) => {

packages/shop/src/components/features/product.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ const ProductImageCard: React.FC<ProductImageCardPropType> = ({ language, produc
409409
type ProductListStateType = {
410410
openDialog: boolean;
411411
openBackdrop: boolean;
412+
resetKey: string;
412413
product?: ShopSchemas.Product;
413414
oneItemOrderData?: ShopSchemas.CartItemAppendRequest;
414415
};
@@ -425,13 +426,18 @@ export const ProductList: React.FC<ShopSchemas.ProductListQueryParams> = (qs) =>
425426
const [state, setState] = React.useState<ProductListStateType>({
426427
openDialog: false,
427428
openBackdrop: false,
429+
resetKey: Math.random().toString(36).substring(2),
428430
});
429431

432+
const foldAll = () => setState((ps) => ({ ...ps, resetKey: Math.random().toString(36).substring(2) }));
430433
const openDialog = () => setState((ps) => ({ ...ps, openDialog: true }));
431434
const closeDialog = () => setState((ps) => ({ ...ps, openDialog: false }));
432435
const openBackdrop = () => setState((ps) => ({ ...ps, openBackdrop: true }));
433436
const closeBackdrop = () => setState((ps) => ({ ...ps, openBackdrop: false }));
434437
const setProductDataAndOpenDialog = (oneItemOrderData: ShopSchemas.CartItemAppendRequest) => {
438+
// 부모 리렌더링에 따른 form 상태 초기화를 숨기기 위해 accordion을 닫습니다.
439+
// TODO: FIXME: form 상태가 애초에 초기화되면 안됩니다. form 내부 값을 초기화되지 않도록 막고, 접히지 않도록 하세요.
440+
foldAll();
435441
setState((ps) => ({ ...ps, oneItemOrderData }));
436442
openDialog();
437443
};
@@ -470,7 +476,7 @@ export const ProductList: React.FC<ShopSchemas.ProductListQueryParams> = (qs) =>
470476
return (
471477
<>
472478
<CommonComponents.CustomerInfoFormDialog open={state.openDialog} closeFunc={closeDialog} onSubmit={onFormSubmit} />
473-
<Common.Components.MDX.OneDetailsOpener>
479+
<Common.Components.MDX.OneDetailsOpener resetKey={state.resetKey}>
474480
{data.map((p) => (
475481
<FoldableProductItem
476482
disabled={oneItemOrderStartMutation.isPending}

0 commit comments

Comments
 (0)