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

[GGFE-199] 관리자 상점관리 - 아이템 조회 수정 api 연결 #978

Merged
merged 18 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
bb5779c
[Feat] [GGFE-199] 관리자 - 아이템 수정, 삭제, 이력 조회 api 연결
PHJoon Aug 23, 2023
09fc470
[Chore] [GGFE-199] 안쓰는 변수 삭제
PHJoon Aug 23, 2023
43ac72c
[Feat] [GGFE-199] put->post 변경 + 요청 바디 폼 키 수정
PHJoon Aug 25, 2023
c127893
[Feat] [GGFE-199] 관리자 - 아이템 수정 에러코드 메세지 추가
PHJoon Aug 28, 2023
2a6ab69
[Feat] [GGFE-199] 관리자 - 아이템 관리 주, 부설명 추가
PHJoon Aug 28, 2023
72ab825
[Feat] [GGFE-199] 관리자 - 아이템, 아이템 변경 내역 속성 변경
PHJoon Aug 29, 2023
adfcd88
[Test] [GGFE-199] 아이템 수정, 변경내역 mockapi 수정
PHJoon Aug 29, 2023
ffd8bd4
[Feat] [GGFE-199] 아이템 수정 모달 주설명, 부설명 추가
PHJoon Aug 30, 2023
11efb57
[Feat] [GGFE-199] 아이템 삭제 모달 주설명, 부설명 수정
PHJoon Aug 30, 2023
c4fb55a
[Feat] [GGFE-199] 관리자 - 아이템 목록 api 수정
PHJoon Aug 30, 2023
65a1e84
[Style] [GGFE-199] 아이템 수정, 삭제 textarea padding 추가
PHJoon Aug 31, 2023
4f4b459
[Fix] [GGFE-199] 아이템 수정 모달 주,부설명 수정
PHJoon Sep 5, 2023
04ca05c
[Fix] [GGFE-199] 관리자 아이템 조회 수정 테이블 오류 수정
PHJoon Sep 5, 2023
229e171
Merge branch 'main' into GGFE-199-관리자-아이템-조회-수정-api-연결
PHJoon Sep 5, 2023
c796da2
[Chore] [GGFE-199] 안쓰는 import 삭제
PHJoon Sep 5, 2023
d9ce845
[Feat] [GGFE-199] useUpload 이미지 사이즈 인자로 수정
PHJoon Sep 6, 2023
469ade1
[Feat] [GGFE-199] 설명 더보기 개행 추가
PHJoon Sep 6, 2023
7d83e4c
Merge branch 'main' into GGFE-199-관리자-아이템-조회-수정-api-연결
PHJoon Sep 6, 2023
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
35 changes: 22 additions & 13 deletions components/admin/store/ItemList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import {
TableRow,
} from '@mui/material';
import { Item, ItemList } from 'types/itemTypes';
import { mockInstance } from 'utils/mockAxios';
import { instance } from 'utils/axios';
import { modalState } from 'utils/recoil/modal';
import { toastState } from 'utils/recoil/toast';
import { tableFormat } from 'constants/admin/table';
import {
AdminContent,
AdminEmptyItem,
AdminTableHead,
} from 'components/admin/common/AdminTable';
Expand All @@ -34,19 +33,16 @@ const tableTitle: { [key: string]: string } = {
delete: '삭제',
};

const MAX_CONTENT_LENGTH = 15;

function ItemList() {
const [itemListData, setItemListData] = useState<ItemList>({
itemList: [],
});
const setModal = useSetRecoilState(modalState);
const setSnackBar = useSetRecoilState(toastState);

// api 연결 시 instanceInManage로 변경
const getItemListHandler = useCallback(async () => {
try {
const res = await mockInstance.get(`items/store`);
const res = await instance.get(`/pingpong/items/store`);
setItemListData(res.data);
} catch (e: unknown) {
setSnackBar({
Expand All @@ -72,6 +68,14 @@ function ItemList() {
});
};

const openDetailModal = (item: Item) => {
setModal({
modalName: 'ADMIN-DETAIL_CONTENT',
detailTitle: item.mainContent,
detailContent: item.subContent,
});
};

useEffect(() => {
getItemListHandler();
}, []);
Expand All @@ -90,11 +94,21 @@ function ItemList() {
<TableCell className={styles.tableBodyItem} key={index}>
{columnName === 'imageUri' ? (
<Image
src={item[columnName]}
src={item.imageUri ? item[columnName] : ''}
Copy link
Member

Choose a reason for hiding this comment

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

이 부분에도 item.imageUri이 잘못된 값일 경우에 빈 문자열 대신 fallback image를 넣어주면 좋을 것 같아요!

Screen_Shot 2023-09-06 10 59 56

Copy link
Contributor Author

Choose a reason for hiding this comment

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

수정했습니다!

alt='Item Iamge'
width={30}
height={30}
/>
) : columnName === 'content' ? (
<div>
{item.mainContent}
<span
style={{ cursor: 'pointer', color: 'grey' }}
onClick={() => openDetailModal(item)}
>
...더보기
</span>
</div>
) : columnName === 'edit' ? (
<button
className={styles.editBtn}
Expand All @@ -110,12 +124,7 @@ function ItemList() {
삭제
</button>
) : (
<AdminContent
content={item[columnName as keyof Item].toString()}
maxLen={MAX_CONTENT_LENGTH}
detailTitle={item.itemName}
detailContent={item.mainContent}
/>
item[columnName as keyof Item]?.toString()
)}
</TableCell>
);
Expand Down
51 changes: 34 additions & 17 deletions components/admin/store/itemHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
TableRow,
} from '@mui/material';
import { IitemHistory, IitemHistoryList } from 'types/admin/adminStoreTypes';
import { instanceInManage } from 'utils/axios';
import { dateToStringShort } from 'utils/handleTime';
import { mockInstance } from 'utils/mockAxios';
import { modalState } from 'utils/recoil/modal';
import { toastState } from 'utils/recoil/toast';
import { tableFormat } from 'constants/admin/table';
import {
AdminContent,
AdminEmptyItem,
AdminTableHead,
} from 'components/admin/common/AdminTable';
Expand All @@ -24,8 +24,8 @@ import styles from 'styles/admin/store/ItemHistory.module.scss';

const tableTitle: { [key: string]: string } = {
itemId: 'ID',
createdAt: '변경 시간',
itemName: '이름',
createdAt: '변경일',
name: '이름',
content: '설명',
imageUri: '이미지',
price: '원가',
Expand All @@ -45,15 +45,15 @@ function ItemHistory() {
});
const [currentPage, setCurrentPage] = useState<number>(1);
const setSnackBar = useSetRecoilState(toastState);
const setModal = useSetRecoilState(modalState);

// instanceInManage로 변경
const getItemHistoryListHandler = useCallback(async () => {
try {
const res = await mockInstance.get(
`/admin/items/history?page=${currentPage}&size=5`
const res = await instanceInManage.get(
`/items/history?page=${currentPage}&size=5`
);
setItemHistoryData({
itemHistoryList: res.data.itemHistoryList.map(
itemHistoryList: res.data.historyList.map(
(itemHistory: IitemHistory) => {
return {
...itemHistory,
Expand All @@ -74,6 +74,14 @@ function ItemHistory() {
}
}, [currentPage]);

const openDetailModal = (itemHistory: IitemHistory) => {
setModal({
modalName: 'ADMIN-DETAIL_CONTENT',
detailTitle: itemHistory.mainContent,
detailContent: itemHistory.subContent,
});
};

useEffect(() => {
getItemHistoryListHandler();
}, [currentPage]);
Expand All @@ -100,20 +108,29 @@ function ItemHistory() {
>
{columnName === 'imageUri' ? (
<Image
src={itemHistory[columnName]}
src={
itemHistory.imageUri
? itemHistory[columnName]
: ''
}
width={30}
height={30}
alt='no'
/>
) : columnName === 'content' ? (
<div>
{itemHistory.mainContent}
<span
style={{ cursor: 'pointer', color: 'grey' }}
onClick={() => openDetailModal(itemHistory)}
>
...더보기
</span>
</div>
) : (
<AdminContent
content={itemHistory[
columnName as keyof IitemHistory
].toString()}
maxLen={MAX_CONTENT_LENGTH}
detailTitle={itemHistory.itemName}
detailContent={itemHistory.content}
/>
itemHistory[
columnName as keyof IitemHistory
]?.toString()
)}
</TableCell>
);
Expand Down
57 changes: 37 additions & 20 deletions components/modal/admin/AdminDeleteItem.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { useSetRecoilState } from 'recoil';
import { Item } from 'types/itemTypes';
import { mockInstance } from 'utils/mockAxios';
import { userState } from 'utils/recoil/layout';
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 } = props;
const { itemId, itemName, mainContent, subContent } = props;
const setModal = useSetRecoilState(modalState);
const setSnackBar = useSetRecoilState(toastState);
const user = useRecoilValue(userState).intraId;

// instanceInManage로 변경
// delete에 body 담기
const deleteItemHandler = async (itemId: number) => {
try {
await mockInstance.delete(`/admin/items/${itemId}`, {
data: { deleterIntraId: user },
});
await instanceInManage.delete(`/items/${itemId}`);
setSnackBar({
toastName: 'delete item',
severity: 'success',
message: `${itemId}${name}이 삭제되었습니다!`,
message: `${itemId}${itemName}이 삭제되었습니다!`,
clicked: true,
});
} catch (e: unknown) {
Expand All @@ -44,18 +38,41 @@ export default function AdminDeleteItemModal(props: Item) {
</div>
<div className={styles.body}>
<div className={styles.bodyWrap}>
<div className={styles.intraWrap}>
<div className={styles.bodyText}>아이템명 :</div>
<input className={styles.intraBlank} value={itemName} readOnly />
</div>
<div className={styles.contentWrap}>
<div className={styles.bodyText}>설명 :</div>
<textarea
className={styles.contentBlank}
value={mainContent}
<div className={styles.itemWrap}>
<label htmlFor='itemName' className={styles.bodyText}>
아이템명 :
</label>
<input
id='itemName'
className={styles.itemBlank}
value={itemName}
readOnly
/>
</div>
<div className={styles.contentWrap}>
<div className={styles.mainContentWrap}>
<label htmlFor='itemMainContent' className={styles.bodyText}>
주설명 :
</label>
<input
id='itemMainContent'
className={styles.mainContentBlank}
value={mainContent}
readOnly
/>
</div>
<div className={styles.subContentWrap}>
<label htmlFor='itemSubContent' className={styles.bodyText}>
부설명 :
</label>
<textarea
id='itemSubContent'
className={styles.subContentBlank}
value={subContent}
readOnly
/>
</div>
</div>
<div className={styles.checkWrap}>
{itemId} 번 아이템을 삭제하시겠습니까?
</div>
Expand Down
Loading