From 0732d8c8914407a0f9ad411fe72ef8af87f21aea Mon Sep 17 00:00:00 2001 From: PHJoon Date: Thu, 7 Sep 2023 14:01:27 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[Feat]=20[GGFE-237]=20=EC=95=84=EC=9D=B4?= =?UTF-8?q?=ED=85=9C=20=EC=88=98=EC=A0=95,=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EC=9D=B4=ED=9B=84=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/admin/store/ItemList.tsx | 11 ++++++++++- components/admin/store/StoreMain.tsx | 7 +++++-- components/admin/store/itemHistory.tsx | 10 +++++++--- components/modal/admin/AdminDeleteItem.tsx | 13 +++++++++++-- components/modal/admin/AdminEditItem.tsx | 13 +++++++++++-- components/modal/modalType/AdminModal.tsx | 11 +++++++++-- types/modalTypes.ts | 7 +++++++ 7 files changed, 60 insertions(+), 12 deletions(-) diff --git a/components/admin/store/ItemList.tsx b/components/admin/store/ItemList.tsx index 991ed162c..600c7d2ba 100644 --- a/components/admin/store/ItemList.tsx +++ b/components/admin/store/ItemList.tsx @@ -10,6 +10,7 @@ import { TableRow, } from '@mui/material'; import { Item, ItemList } from 'types/itemTypes'; +import { Irefresh } from 'types/modalTypes'; import { instance } from 'utils/axios'; import { modalState } from 'utils/recoil/modal'; import { toastState } from 'utils/recoil/toast'; @@ -33,7 +34,7 @@ const tableTitle: { [key: string]: string } = { delete: '삭제', }; -function ItemList() { +function ItemList({ refresh, setRefresh }: Irefresh) { const [itemListData, setItemListData] = useState({ itemList: [], }); @@ -58,6 +59,7 @@ function ItemList() { setModal({ modalName: 'ADMIN-ITEM_EDIT', item: item, + refresh: { refresh: refresh, setRefresh: setRefresh }, }); }; @@ -80,6 +82,13 @@ function ItemList() { getItemListHandler(); }, []); + useEffect(() => { + if (refresh) { + getItemListHandler(); + setRefresh(false); + } + }, [refresh, getItemListHandler]); + return ( diff --git a/components/admin/store/StoreMain.tsx b/components/admin/store/StoreMain.tsx index 3a1f8d662..3169b5e94 100644 --- a/components/admin/store/StoreMain.tsx +++ b/components/admin/store/StoreMain.tsx @@ -1,17 +1,20 @@ +import { useState } from 'react'; import ChangeHistory from 'components/admin/store/itemHistory'; import ItemList from 'components/admin/store/ItemList'; import styles from 'styles/admin/store/StoreMain.module.scss'; function StoreMain() { + const [refresh, setRefresh] = useState(false); + return (
아이템 목록
- +
변경 이력
- +
); diff --git a/components/admin/store/itemHistory.tsx b/components/admin/store/itemHistory.tsx index 8881589f5..bab03258d 100644 --- a/components/admin/store/itemHistory.tsx +++ b/components/admin/store/itemHistory.tsx @@ -10,6 +10,7 @@ import { TableRow, } from '@mui/material'; import { IitemHistory, IitemHistoryList } from 'types/admin/adminStoreTypes'; +import { Irefresh } from 'types/modalTypes'; import { instanceInManage } from 'utils/axios'; import { dateToStringShort } from 'utils/handleTime'; import { modalState } from 'utils/recoil/modal'; @@ -35,7 +36,7 @@ const tableTitle: { [key: string]: string } = { visible: '상점 노출', }; -function ItemHistory() { +function ItemHistory({ refresh, setRefresh }: Irefresh) { const [itemHistoryData, setItemHistoryData] = useState({ itemHistoryList: [], totalPage: 0, @@ -81,8 +82,11 @@ function ItemHistory() { }; useEffect(() => { - getItemHistoryListHandler(); - }, [currentPage]); + if (refresh) { + getItemHistoryListHandler(); + setRefresh(false); + } + }, [currentPage, refresh]); return ( <> diff --git a/components/modal/admin/AdminDeleteItem.tsx b/components/modal/admin/AdminDeleteItem.tsx index 6349e57a3..14e32e405 100644 --- a/components/modal/admin/AdminDeleteItem.tsx +++ b/components/modal/admin/AdminDeleteItem.tsx @@ -1,12 +1,20 @@ import { useSetRecoilState } from 'recoil'; import { Item } from 'types/itemTypes'; +import { Irefresh } from 'types/modalTypes'; import { instanceInManage } from 'utils/axios'; import { modalState } from 'utils/recoil/modal'; import { toastState } from 'utils/recoil/toast'; import styles from 'styles/admin/modal/AdminDeleteItem.module.scss'; -export default function AdminDeleteItemModal(props: Item) { - const { itemId, itemName, mainContent, subContent } = props; +export default function AdminDeleteItemModal({ + item, + state, +}: { + item: Item; + state: Irefresh; +}) { + const { itemId, itemName, mainContent, subContent } = item; + const { setRefresh } = state; const setModal = useSetRecoilState(modalState); const setSnackBar = useSetRecoilState(toastState); @@ -27,6 +35,7 @@ export default function AdminDeleteItemModal(props: Item) { clicked: true, }); } + setRefresh(true); setModal({ modalName: null }); }; diff --git a/components/modal/admin/AdminEditItem.tsx b/components/modal/admin/AdminEditItem.tsx index aaf7c34e5..5a562b766 100644 --- a/components/modal/admin/AdminEditItem.tsx +++ b/components/modal/admin/AdminEditItem.tsx @@ -1,13 +1,20 @@ import Image from 'next/image'; import { useSetRecoilState } from 'recoil'; import { Item } from 'types/itemTypes'; +import { Irefresh } from 'types/modalTypes'; import { instanceInManage } from 'utils/axios'; import { modalState } from 'utils/recoil/modal'; import { toastState } from 'utils/recoil/toast'; import useUploadImg from 'hooks/useUploadImg'; import styles from 'styles/admin/modal/AdminEditItem.module.scss'; -export default function AdminEditItemModal(props: Item) { +export default function AdminEditItemModal({ + item, + state, +}: { + item: Item; + state: Irefresh; +}) { const { itemId, itemName, @@ -17,7 +24,8 @@ export default function AdminEditItemModal(props: Item) { originalPrice, discount, itemType, - } = props; + } = item; + const { refresh, setRefresh } = state; const setModal = useSetRecoilState(modalState); const setSnackBar = useSetRecoilState(toastState); const { imgData, imgPreview, uploadImg } = useUploadImg({ @@ -94,6 +102,7 @@ export default function AdminEditItemModal(props: Item) { }); } } + setRefresh(true); setModal({ modalName: null }); }; diff --git a/components/modal/modalType/AdminModal.tsx b/components/modal/modalType/AdminModal.tsx index e8c0c5558..afeb96ab9 100644 --- a/components/modal/modalType/AdminModal.tsx +++ b/components/modal/modalType/AdminModal.tsx @@ -29,6 +29,7 @@ export default function AdminModal() { profile, item, coinPolicy, + refresh, } = useRecoilValue(modalState); const content: { [key: string]: JSX.Element | null } = { @@ -67,8 +68,14 @@ export default function AdminModal() { 'ADMIN-PROFILE_DELETE': profile ? ( ) : null, - 'ADMIN-ITEM_EDIT': item ? : null, - 'ADMIN-ITEM_DELETE': item ? : null, + 'ADMIN-ITEM_EDIT': + item && refresh ? ( + + ) : null, + 'ADMIN-ITEM_DELETE': + item && refresh ? ( + + ) : null, 'ADMIN-COINPOLICY_EDIT': coinPolicy ? ( ) : null, diff --git a/types/modalTypes.ts b/types/modalTypes.ts index 4b1444519..242a61793 100644 --- a/types/modalTypes.ts +++ b/types/modalTypes.ts @@ -1,3 +1,4 @@ +import { Dispatch, SetStateAction } from 'react'; import { Value } from 'react-quill'; import { IcoinPolicy } from 'types/admin/adminCoinTypes'; import { IFeedback } from 'types/admin/adminFeedbackTypes'; @@ -101,6 +102,11 @@ export interface IRandomItem { color: string; } +export interface Irefresh { + refresh: boolean; + setRefresh: Dispatch>; +} + export interface Modal { modalName: ModalName; manual?: Manual; @@ -127,4 +133,5 @@ export interface Modal { isAttended?: boolean; totalCoin?: ICoin; randomItem?: IRandomItem; + refresh?: Irefresh; } From 8c317e78278a19d1de229f459e8c89e7ea374c9d Mon Sep 17 00:00:00 2001 From: PHJoon Date: Thu, 7 Sep 2023 15:01:53 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[Feat]=20[GGFE-237]=20=EC=95=84=EC=9D=B4?= =?UTF-8?q?=ED=85=9C=20=EC=88=98=EC=A0=95=20=EC=97=90=EB=9F=AC=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/modal/admin/AdminEditItem.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/modal/admin/AdminEditItem.tsx b/components/modal/admin/AdminEditItem.tsx index 5a562b766..bb67ab5b8 100644 --- a/components/modal/admin/AdminEditItem.tsx +++ b/components/modal/admin/AdminEditItem.tsx @@ -25,16 +25,17 @@ export default function AdminEditItemModal({ discount, itemType, } = item; - const { refresh, setRefresh } = state; + const { setRefresh } = state; const setModal = useSetRecoilState(modalState); const setSnackBar = useSetRecoilState(toastState); const { imgData, imgPreview, uploadImg } = useUploadImg({ maxSizeMB: 0.03, - maxWidthOrHeight: 250, + maxWidthOrHeight: 300, }); const editErrorResponse: { [key: string]: string } = { IT200: '아이템 타입이 일치하지 않습니다.', + IT205: '해당 아이템에 접근할 수 없습니다.', IT413: '아이템 이미지가 너무 큽니다.', IT415: '아이템 이미지 타입이 jpeg가 아닙니다.', }; From 03600c924f3f121e0f01b10bd4c7df6b05306aef Mon Sep 17 00:00:00 2001 From: PHJoon Date: Thu, 7 Sep 2023 16:10:59 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[Fix]=20[GGFE-237]=20=EC=8A=A4=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=20=EB=B9=8C=EB=93=9C=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stories/admin/AdminEditItem.stories.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/stories/admin/AdminEditItem.stories.tsx b/stories/admin/AdminEditItem.stories.tsx index 57965a3a3..dedd47f90 100644 --- a/stories/admin/AdminEditItem.stories.tsx +++ b/stories/admin/AdminEditItem.stories.tsx @@ -6,12 +6,18 @@ const meta: Meta = { component: AdminEditItemModal, tags: ['autodocs'], argTypes: { - itemId: Number, - itemName: String, - mainContent: String, - imageUri: String, - originalPrice: Number, - discount: Number, + item: { + itemId: Number, + itemName: String, + mainContent: String, + imageUri: String, + originalPrice: Number, + discount: Number, + }, + state: { + refresh: Boolean, + setRefresh: undefined, + }, }, }; From cb98db15c5e3c93dcef3704eb9090ccd44b97dd4 Mon Sep 17 00:00:00 2001 From: PHJoon Date: Thu, 7 Sep 2023 18:40:14 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[Chore]=20[GGFE-237]=20Irefresh=20->=20Iupd?= =?UTF-8?q?ate=EB=A1=9C=20interface=20=EC=9D=B4=EB=A6=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/admin/store/ItemList.tsx | 12 ++--- components/admin/store/StoreMain.tsx | 6 +-- components/admin/store/itemHistory.tsx | 10 ++-- components/modal/admin/AdminDeleteItem.tsx | 8 +-- components/modal/admin/AdminEditItem.tsx | 8 +-- components/modal/modalType/AdminModal.tsx | 10 ++-- stories/admin/AdminEditItem.stories.tsx | 57 ---------------------- types/modalTypes.ts | 8 +-- 8 files changed, 30 insertions(+), 89 deletions(-) delete mode 100644 stories/admin/AdminEditItem.stories.tsx diff --git a/components/admin/store/ItemList.tsx b/components/admin/store/ItemList.tsx index 600c7d2ba..f8225113e 100644 --- a/components/admin/store/ItemList.tsx +++ b/components/admin/store/ItemList.tsx @@ -10,7 +10,7 @@ import { TableRow, } from '@mui/material'; import { Item, ItemList } from 'types/itemTypes'; -import { Irefresh } from 'types/modalTypes'; +import { IUpdate } from 'types/modalTypes'; import { instance } from 'utils/axios'; import { modalState } from 'utils/recoil/modal'; import { toastState } from 'utils/recoil/toast'; @@ -34,7 +34,7 @@ const tableTitle: { [key: string]: string } = { delete: '삭제', }; -function ItemList({ refresh, setRefresh }: Irefresh) { +function ItemList({ update, setUpdate }: IUpdate) { const [itemListData, setItemListData] = useState({ itemList: [], }); @@ -59,7 +59,7 @@ function ItemList({ refresh, setRefresh }: Irefresh) { setModal({ modalName: 'ADMIN-ITEM_EDIT', item: item, - refresh: { refresh: refresh, setRefresh: setRefresh }, + update: { update: update, setUpdate: setUpdate }, }); }; @@ -83,11 +83,11 @@ function ItemList({ refresh, setRefresh }: Irefresh) { }, []); useEffect(() => { - if (refresh) { + if (update) { getItemListHandler(); - setRefresh(false); + setUpdate(false); } - }, [refresh, getItemListHandler]); + }, [update, getItemListHandler]); return ( diff --git a/components/admin/store/StoreMain.tsx b/components/admin/store/StoreMain.tsx index 3169b5e94..cf34c9d00 100644 --- a/components/admin/store/StoreMain.tsx +++ b/components/admin/store/StoreMain.tsx @@ -4,17 +4,17 @@ import ItemList from 'components/admin/store/ItemList'; import styles from 'styles/admin/store/StoreMain.module.scss'; function StoreMain() { - const [refresh, setRefresh] = useState(false); + const [update, setUpdate] = useState(false); return (
아이템 목록
- +
변경 이력
- +
); diff --git a/components/admin/store/itemHistory.tsx b/components/admin/store/itemHistory.tsx index bab03258d..51b8a5518 100644 --- a/components/admin/store/itemHistory.tsx +++ b/components/admin/store/itemHistory.tsx @@ -10,7 +10,7 @@ import { TableRow, } from '@mui/material'; import { IitemHistory, IitemHistoryList } from 'types/admin/adminStoreTypes'; -import { Irefresh } from 'types/modalTypes'; +import { IUpdate } from 'types/modalTypes'; import { instanceInManage } from 'utils/axios'; import { dateToStringShort } from 'utils/handleTime'; import { modalState } from 'utils/recoil/modal'; @@ -36,7 +36,7 @@ const tableTitle: { [key: string]: string } = { visible: '상점 노출', }; -function ItemHistory({ refresh, setRefresh }: Irefresh) { +function ItemHistory({ update, setUpdate }: IUpdate) { const [itemHistoryData, setItemHistoryData] = useState({ itemHistoryList: [], totalPage: 0, @@ -82,11 +82,11 @@ function ItemHistory({ refresh, setRefresh }: Irefresh) { }; useEffect(() => { - if (refresh) { + if (update) { getItemHistoryListHandler(); - setRefresh(false); + setUpdate(false); } - }, [currentPage, refresh]); + }, [currentPage, update]); return ( <> diff --git a/components/modal/admin/AdminDeleteItem.tsx b/components/modal/admin/AdminDeleteItem.tsx index 14e32e405..58a759f5c 100644 --- a/components/modal/admin/AdminDeleteItem.tsx +++ b/components/modal/admin/AdminDeleteItem.tsx @@ -1,6 +1,6 @@ import { useSetRecoilState } from 'recoil'; import { Item } from 'types/itemTypes'; -import { Irefresh } from 'types/modalTypes'; +import { IUpdate } from 'types/modalTypes'; import { instanceInManage } from 'utils/axios'; import { modalState } from 'utils/recoil/modal'; import { toastState } from 'utils/recoil/toast'; @@ -11,10 +11,10 @@ export default function AdminDeleteItemModal({ state, }: { item: Item; - state: Irefresh; + state: IUpdate; }) { const { itemId, itemName, mainContent, subContent } = item; - const { setRefresh } = state; + const { setUpdate } = state; const setModal = useSetRecoilState(modalState); const setSnackBar = useSetRecoilState(toastState); @@ -35,7 +35,7 @@ export default function AdminDeleteItemModal({ clicked: true, }); } - setRefresh(true); + setUpdate(true); setModal({ modalName: null }); }; diff --git a/components/modal/admin/AdminEditItem.tsx b/components/modal/admin/AdminEditItem.tsx index bb67ab5b8..804cf373c 100644 --- a/components/modal/admin/AdminEditItem.tsx +++ b/components/modal/admin/AdminEditItem.tsx @@ -1,7 +1,7 @@ import Image from 'next/image'; import { useSetRecoilState } from 'recoil'; import { Item } from 'types/itemTypes'; -import { Irefresh } from 'types/modalTypes'; +import { IUpdate } from 'types/modalTypes'; import { instanceInManage } from 'utils/axios'; import { modalState } from 'utils/recoil/modal'; import { toastState } from 'utils/recoil/toast'; @@ -13,7 +13,7 @@ export default function AdminEditItemModal({ state, }: { item: Item; - state: Irefresh; + state: IUpdate; }) { const { itemId, @@ -25,7 +25,7 @@ export default function AdminEditItemModal({ discount, itemType, } = item; - const { setRefresh } = state; + const { setUpdate } = state; const setModal = useSetRecoilState(modalState); const setSnackBar = useSetRecoilState(toastState); const { imgData, imgPreview, uploadImg } = useUploadImg({ @@ -103,7 +103,7 @@ export default function AdminEditItemModal({ }); } } - setRefresh(true); + setUpdate(true); setModal({ modalName: null }); }; diff --git a/components/modal/modalType/AdminModal.tsx b/components/modal/modalType/AdminModal.tsx index afeb96ab9..9aa9b59b6 100644 --- a/components/modal/modalType/AdminModal.tsx +++ b/components/modal/modalType/AdminModal.tsx @@ -29,7 +29,7 @@ export default function AdminModal() { profile, item, coinPolicy, - refresh, + update, } = useRecoilValue(modalState); const content: { [key: string]: JSX.Element | null } = { @@ -69,12 +69,10 @@ export default function AdminModal() { ) : null, 'ADMIN-ITEM_EDIT': - item && refresh ? ( - - ) : null, + item && update ? : null, 'ADMIN-ITEM_DELETE': - item && refresh ? ( - + item && update ? ( + ) : null, 'ADMIN-COINPOLICY_EDIT': coinPolicy ? ( diff --git a/stories/admin/AdminEditItem.stories.tsx b/stories/admin/AdminEditItem.stories.tsx deleted file mode 100644 index dedd47f90..000000000 --- a/stories/admin/AdminEditItem.stories.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import type { Meta, StoryObj } from '@storybook/react'; -import AdminEditItemModal from 'components/modal/admin/AdminEditItem'; - -const meta: Meta = { - title: 'admin/AdminEditItemModal', - component: AdminEditItemModal, - tags: ['autodocs'], - argTypes: { - item: { - itemId: Number, - itemName: String, - mainContent: String, - imageUri: String, - originalPrice: Number, - discount: Number, - }, - state: { - refresh: Boolean, - setRefresh: undefined, - }, - }, -}; - -export default meta; -type Story = StoryObj; - -export const Megaphone: Story = { - args: { - itemId: 1, - itemName: '확성기', - mainContent: '확성기입니다', - imageUri: 'https://picsum.photos/200/300?grayscale', - originalPrice: 42, - discount: 50, - }, -}; - -export const ProfileChange: Story = { - args: { - itemId: 2, - itemName: '프로필 변경권', - mainContent: '프로필 변경권입니다', - imageUri: 'https://picsum.photos/200/300?grayscale', - originalPrice: 42, - discount: 50, - }, -}; -export const ProfileBackgroundChange: Story = { - args: { - itemId: 3, - itemName: '프로필 배경 변경권', - mainContent: '프로필 배경 변경권입니다', - imageUri: 'https://picsum.photos/200/300?grayscale', - originalPrice: 100, - discount: 40, - }, -}; diff --git a/types/modalTypes.ts b/types/modalTypes.ts index 242a61793..0261957b3 100644 --- a/types/modalTypes.ts +++ b/types/modalTypes.ts @@ -102,9 +102,9 @@ export interface IRandomItem { color: string; } -export interface Irefresh { - refresh: boolean; - setRefresh: Dispatch>; +export interface IUpdate { + update: boolean; + setUpdate: Dispatch>; } export interface Modal { @@ -133,5 +133,5 @@ export interface Modal { isAttended?: boolean; totalCoin?: ICoin; randomItem?: IRandomItem; - refresh?: Irefresh; + update?: IUpdate; }