Skip to content

Commit d246483

Browse files
committed
[#50] 경매 완료 과정 수정 및 구현 완료
1 parent 6d44a88 commit d246483

File tree

6 files changed

+119
-128
lines changed

6 files changed

+119
-128
lines changed

src/components/Nfting/index.js

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,35 @@ import {
1010
import useInterval from 'hooks/useInterval';
1111
import { Nfting, Images, Detail, Border } from './styles';
1212

13-
function auctionNft({ props }) {
13+
function auctionNft({ props, status }) {
1414
const userInfo = JSON.parse(localStorage.getItem('userInfo'));
1515
const dispatch = useDispatch();
1616
console.log('=======props', props);
17+
console.log('=======props', props.auction);
18+
19+
useInterval(
20+
() => {
21+
dispatch(checkAuction(props.id, props.email));
22+
console.log('확인 중');
23+
},
24+
status === 'START' ? 3000 : null,
25+
);
1726

1827
const auctionStat = () => {
19-
if (props.auction === 'READY') {
28+
if (status === 'READY') {
2029
if (userInfo.email === props.email) {
2130
// 판매자 => 경매시작
2231
return 0;
2332
}
2433
// 구매자 => "아직 경매 전 입니다"
2534
return 1;
2635
}
27-
if (props.auction === 'START') {
36+
if (status === 'START') {
2837
// 경매 중
2938
// 입찰
3039
return 2;
3140
}
32-
if (props.auction === 'FINISH') {
41+
if (status === 'FINISH') {
3342
// 경매 완료
3443
// "경매가 완료된 작품입니다."
3544
return 3;
@@ -48,23 +57,33 @@ function auctionNft({ props }) {
4857
}
4958
break;
5059
case 2:
51-
if (userInfo.email === props.email) {
52-
window.confirm('본인작품에 입찰 하실 수 없습니다');
53-
} else if (window.confirm('경매에 참여하시겠습니까?')) {
54-
dispatch(participateAuction(props.price + 1, props.email, props.id));
60+
// if (userInfo.email === props.email) {
61+
// window.confirm('본인작품에 입찰 하실 수 없습니다');
62+
// } else
63+
if (window.confirm('경매에 참여하시겠습니까?')) {
64+
if (props.curStatus?.auction_price) {
65+
dispatch(
66+
participateAuction(
67+
parseInt(props.curStatus?.auction_price + 1, 10),
68+
props.email,
69+
props.id,
70+
),
71+
);
72+
} else {
73+
dispatch(
74+
participateAuction(
75+
parseInt(props.price + 1, 10),
76+
props.email,
77+
props.id,
78+
),
79+
);
80+
}
5581
}
5682
break;
5783
default:
5884
}
5985
};
6086

61-
if (props.auction === 'START') {
62-
useInterval(() => {
63-
dispatch(checkAuction(props.id, props.email));
64-
console.log('확인 중');
65-
}, 3000);
66-
}
67-
6887
return (
6988
<>
7089
<Nfting>
@@ -100,14 +119,16 @@ function auctionNft({ props }) {
100119

101120
<h3>💰 현입찰 가격</h3>
102121
<div className="price">
103-
{props.curStatus ? (
122+
{props.curStatus?.auction_price ? (
104123
<p>{props.curStatus?.auction_price} KLAY</p>
105-
) : <p />}
124+
) : (
125+
<p />
126+
)}
106127
</div>
107128

108129
<h3 className="current">👤 현재 매수왕</h3>
109130
<div className="email">
110-
{props.curStatus ? <p>{props.curStatus?.email}</p> : <p />}
131+
{props.curStatus?.email ? <p>{props.curStatus?.email}</p> : <p />}
111132
</div>
112133
{/* 상태 구별 */}
113134
{/* 판매자일 때 */}
@@ -172,15 +193,4 @@ function auctionNft({ props }) {
172193
);
173194
}
174195

175-
auctionNft.propTypes = {
176-
props: PropTypes.shape({
177-
id: PropTypes.string,
178-
no: PropTypes.string,
179-
name: PropTypes.string,
180-
description: PropTypes.string,
181-
image: PropTypes.string,
182-
owner: PropTypes.string,
183-
}).isRequired,
184-
};
185-
186196
export default auctionNft;

src/pages/auction/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useCallback, useEffect } from 'react';
22
import Header from 'components/Common/Header';
3-
import { useSelector, useDispatch } from 'react-redux';
3+
import { useSelector, useDispatch, shallowEqual } from 'react-redux';
44
import Nfting from 'components/Nfting';
55
import { LOAD_ONE_AUCTION_REQUEST, clearAuction } from 'reducers/auction';
66

@@ -13,9 +13,6 @@ function auctionPost({ match }) {
1313
type: LOAD_ONE_AUCTION_REQUEST,
1414
data: match.params.id,
1515
});
16-
if (singleAuction.auction === 'START') {
17-
console.log('경매시작했어');
18-
}
1916
return () => {
2017
dispatch(clearAuction());
2118
};
@@ -24,7 +21,7 @@ function auctionPost({ match }) {
2421
return (
2522
<>
2623
<Header />
27-
<Nfting props={singleAuction} />
24+
<Nfting props={singleAuction} status={singleAuction.auction} />
2825
</>
2926
);
3027
}

src/pages/home/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function home() {
2121
const { mainAuctions, likeAuctions } = useSelector(
2222
stateRedux => stateRedux.auctionReducer,
2323
);
24+
const userInfo = JSON.parse(localStorage.getItem('userInfo'));
2425

2526
useEffect(() => {
2627
AOS.init({
@@ -32,16 +33,18 @@ function home() {
3233
dispatch({
3334
type: LOAD_AUCTION_REQUEST,
3435
});
35-
if (localStorage.getItem('userInfo')) {
36+
if (localStorage.getItem('token')) {
3637
dispatch({
3738
type: LOAD_LIKE_AUCTION_REQUEST,
38-
data: JSON.parse(localStorage.getItem('userInfo')).id,
39+
data: userInfo.id,
3940
});
41+
console.log('-----------', mainAuctions, likeAuctions);
4042
}
41-
}, []);
43+
}, [localStorage]);
4244
console.log('-----------', mainAuctions, likeAuctions);
4345

44-
const likeAuctionsId = likeAuctions?.map(like => like.id);
46+
// const likeAuctionsId = likeAuctions ?.map(like => like.id) || [];
47+
const likeAuctionsId = likeAuctions ? likeAuctions.map(like => like.id) : [];
4548

4649
// PagingNation
4750
// 현재 페이지

src/reducers/auction.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ const auctionReducer = (state = initialState, action) =>
426426
case PARTICIPATE_AUCTION_SUCCESS:
427427
draft.participateAuctionLoading = false;
428428
draft.participateAuctionDone = true;
429+
draft.singleAuction.curStatus.auction_price = action.data.price;
430+
draft.singleAuction.curStatus.email = action.data.email;
429431
break;
430432
case PARTICIPATE_AUCTION_FAILURE:
431433
draft.participateAuctionLoading = false;

0 commit comments

Comments
 (0)