Skip to content

Commit d4cde64

Browse files
committed
[fix] ๐ŸŽ Data Type ๋ณ€๊ฒฝ
1 parent 7c66aa5 commit d4cde64

File tree

13 files changed

+121
-90
lines changed

13 files changed

+121
-90
lines changed

Diff for: โ€Žapp/(head)/cart/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Checkbox } from '@/components/ui/checkbox';
1010
import { QUERY_KEYS } from '@/constants/queryKey';
1111
import { useGenericMutation, useGenericQuery } from '@/hooks/query/globalQuery';
1212
import { purchaseAtom, shopCartAtom } from '@/stores/atom';
13-
import { ApiResponse, Cart, shopCartItem } from '@/types';
13+
import { ApiResponse, Cart, ShopCartItem } from '@/types';
1414
import { useQueryClient } from '@tanstack/react-query';
1515
import { useAtom } from 'jotai';
1616
import Image from 'next/image';
@@ -182,7 +182,7 @@ export default function CartPage() {
182182
{
183183
coupang: [],
184184
'11st': [],
185-
} as shopCartItem
185+
} as ShopCartItem
186186
);
187187

188188
setShopCart(groupedItems);

Diff for: โ€Žapp/(head)/mypage/membership/[shop]/page.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export default function MembershipDetail({
4848

4949
const { mutate: mutatePaymentDetails } = useGenericMutation(
5050
[QUERY_KEYS.PAYMENT_DETAILS],
51-
({ payment_list }: { payment_list: TransformedOrder[] }) =>
52-
postPaymentDetail({ payment_list })
51+
({ paymentList }: { paymentList: TransformedOrder[] }) =>
52+
postPaymentDetail({ paymentList })
5353
);
5454

5555
const getUrlByPlatform = () =>
@@ -97,7 +97,7 @@ export default function MembershipDetail({
9797

9898
const { result } = await response.json();
9999

100-
mutatePaymentDetails({ payment_list: result });
100+
mutatePaymentDetails({ paymentList: result });
101101
} catch (error) {
102102
console.error('Error fetching data:', error);
103103
}

Diff for: โ€Žapp/(head)/payments/page.tsx

+76-43
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default function PaymentMembership() {
3939
const router = useRouter();
4040

4141
const cartItems = useAtomValue(shopCartAtom);
42+
console.log('๐Ÿš€ ~ PaymentMembership ~ cartItems:', cartItems);
4243
const purcahse = useAtomValue(purchaseAtom);
4344

4445
const [isClicked, setIsClicked] = useState(false);
@@ -90,24 +91,56 @@ export default function PaymentMembership() {
9091
// // quantity: 1,
9192
// // },
9293
// ];
93-
const coupangItemList: Item[] = cartItems['coupang'];
9494

9595
// const elevenStreetItemList: Item[] = [
9696
// {
9797
// productId: '7864138029',
9898
// quantity: 1,
9999
// },
100100
// ];
101-
const elevenStreetItemList: Item[] = cartItems['11st'];
101+
102+
const PLATFORM_LIST: Platform[] = ['COUPANG', '11ST'];
103+
104+
const itemList = {
105+
COUPANG: cartItems['coupang'],
106+
'11ST': cartItems['11st'],
107+
NAVER: [],
108+
};
102109

103110
useEffect(() => {
104-
if (coupangItemList.length === 0 && elevenStreetItemList.length === 0) {
111+
if (itemList['COUPANG'].length === 0 && itemList['11ST'].length === 0) {
105112
// TODO: TOAST๋กœ ๊ณ ์ณ์•ผํ•จ. ๊ทผ๋ฐ ๋ฐ”๊พธ๋‹ˆ๊นŒ ์—๋Ÿฌ๋œธ ์ผ๋‹จ PASS
106113
console.log('๊ฒฐ์ œ ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.');
107114
router.push('/cart');
115+
return;
116+
}
117+
118+
const isCompleted = PLATFORM_LIST.every((platform) => {
119+
if (itemList[platform].length !== 0) {
120+
if (platform === 'COUPANG' ? coupangResponse : elevenStreetResponse) {
121+
if (
122+
platform === 'COUPANG'
123+
? coupangResponse?.status === 'C_COMPLETED'
124+
: elevenStreetResponse?.status === '11_COMPLETED'
125+
) {
126+
return true;
127+
}
128+
}
129+
} else {
130+
return true;
131+
}
132+
133+
return false;
134+
});
135+
136+
if (isCompleted) {
137+
console.log('๊ฒฐ์ œ ์™„๋ฃŒ');
138+
postPurchaseMutate(purcahse);
139+
router.push('/');
140+
return;
108141
}
109142
// eslint-disable-next-line react-hooks/exhaustive-deps
110-
}, [coupangItemList.length, elevenStreetItemList.length]);
143+
}, [coupangResponse, elevenStreetResponse]);
111144

112145
const coupangPromise = async ({
113146
id,
@@ -306,8 +339,6 @@ export default function PaymentMembership() {
306339

307340
if (!platformData || !platformData.data || isLoading) return <></>;
308341

309-
const PLATFORM_LIST: Platform[] = ['COUPANG', '11ST'];
310-
311342
// TODO: ์ˆ˜์ • ํ•„์š” : 3๊ฐœ ๋“ฑ๋ก๋˜์–ด์žˆ์„ ์ˆ˜ ์žˆ์Œ.
312343
const isActive =
313344
platformData.data.platformInfos.length === PLATFORM_LIST.length
@@ -342,17 +373,6 @@ export default function PaymentMembership() {
342373
router.push(`/mypage/membership/${shop}?from=payments`);
343374
};
344375

345-
if (coupangResponse && elevenStreetResponse) {
346-
if (
347-
coupangResponse.status === 'C_COMPLETED' &&
348-
elevenStreetResponse.status === '11_COMPLETED'
349-
) {
350-
console.log('๊ฒฐ์ œ ์™„๋ฃŒ');
351-
postPurchaseMutate(purcahse);
352-
router.push('/');
353-
}
354-
}
355-
356376
return (
357377
<div className='mt-[1.625rem] pb-10 w-full'>
358378
{PLATFORM_LIST.map((platform, idx) => {
@@ -361,31 +381,33 @@ export default function PaymentMembership() {
361381
({ platformName }) => platformName === platform
362382
) ?? false;
363383
return (
364-
<PaymentMebershipCard
365-
key={idx}
366-
shop={platform}
367-
isLinked={isContain}
368-
id={
369-
platformData.data?.platformInfos?.find(
370-
({ platformName }) => platformName === platform
371-
)?.id
372-
}
373-
onLinkClick={() => handleLinking(platform)}
374-
response={
375-
platform === 'COUPANG' ? coupangResponse : elevenStreetResponse
376-
}
377-
isLoading={
378-
platform === 'COUPANG' ? isCoupangLoading : isElevenStreetLoading
379-
}
380-
onButtonClick={
381-
platform === 'COUPANG'
382-
? handleCoupangClick
383-
: handleElevenStreetClick
384-
}
385-
itemList={
386-
platform === 'COUPANG' ? coupangItemList : elevenStreetItemList
387-
}
388-
/>
384+
itemList[platform].length !== 0 && (
385+
<PaymentMebershipCard
386+
key={idx}
387+
shop={platform}
388+
isLinked={isContain}
389+
id={
390+
platformData.data?.platformInfos?.find(
391+
({ platformName }) => platformName === platform
392+
)?.id
393+
}
394+
onLinkClick={() => handleLinking(platform)}
395+
response={
396+
platform === 'COUPANG' ? coupangResponse : elevenStreetResponse
397+
}
398+
isLoading={
399+
platform === 'COUPANG'
400+
? isCoupangLoading
401+
: isElevenStreetLoading
402+
}
403+
onButtonClick={
404+
platform === 'COUPANG'
405+
? handleCoupangClick
406+
: handleElevenStreetClick
407+
}
408+
itemList={itemList[platform]}
409+
/>
410+
)
389411
);
390412
})}
391413

@@ -396,7 +418,18 @@ export default function PaymentMembership() {
396418
className='fixed bottom-[100px] z-10 w-[90%] max-w-[460.8px]'
397419
onClick={() => {
398420
setIsClicked(true);
399-
handleBothClick({ coupangItemList, elevenStreetItemList });
421+
if (itemList['COUPANG'].length && itemList['11ST'].length) {
422+
handleBothClick({
423+
coupangItemList: itemList['COUPANG'],
424+
elevenStreetItemList: itemList['11ST'],
425+
});
426+
} else if (itemList['COUPANG'].length) {
427+
handleCoupangClick({ coupangItemList: itemList['COUPANG'] });
428+
} else if (itemList['11ST'].length) {
429+
handleElevenStreetClick({
430+
elevenStreetItemList: itemList['11ST'],
431+
});
432+
}
400433
}}
401434
>
402435
๊ฒฐ์ œํ•˜๊ธฐ

Diff for: โ€Žapp/api/payment-details/11st/route.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ function transformElevenStreetOrder({
7070
const price = parseFloat(productPrice.replace(/,/g, ''));
7171

7272
return {
73-
payment_time: convertDateToTimestamp(orderDate),
74-
payment_place: '11๋ฒˆ๊ฐ€', // ElevenStreet ์ฃผ๋ฌธ์€ ๋ณดํ†ต "11๋ฒˆ๊ฐ€"๋กœ ํ‘œ๊ธฐํ•ฉ๋‹ˆ๋‹ค.
75-
purchase_product_list: [
73+
paymentTime: convertDateToTimestamp(orderDate),
74+
paymentPlace: '11๋ฒˆ๊ฐ€', // ElevenStreet ์ฃผ๋ฌธ์€ ๋ณดํ†ต "11๋ฒˆ๊ฐ€"๋กœ ํ‘œ๊ธฐํ•ฉ๋‹ˆ๋‹ค.
75+
purchaseProductList: [
7676
{
77-
product_name: productInfo,
77+
productName: productInfo,
7878
price,
7979
quantity: productAmount,
8080
},

Diff for: โ€Žapp/api/payment-details/coupang/route.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,20 @@ function transformCoupangOrder({
1414
orderedAt,
1515
bundleReceiptList,
1616
}: CoupangOrderList): TransformedOrder {
17-
const payment_time = orderedAt;
17+
const paymentPlace = '์ฟ ํŒก';
1818

19-
const payment_place = '์ฟ ํŒก';
20-
21-
const purchase_product_list: PurchaseProduct[] = bundleReceiptList
19+
const purchaseProductList: PurchaseProduct[] = bundleReceiptList
2220
.flatMap(({ vendorItems }) => vendorItems)
2321
.map(({ vendorItemName, unitPrice, quantity }) => ({
24-
product_name: vendorItemName,
22+
productName: vendorItemName,
2523
price: unitPrice,
2624
quantity: quantity,
2725
}));
2826

2927
return {
30-
payment_time,
31-
payment_place,
32-
purchase_product_list,
28+
paymentTime: orderedAt,
29+
paymentPlace,
30+
purchaseProductList,
3331
};
3432
}
3533

Diff for: โ€Žapp/api/payment-details/naverpay/route.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ function transformNaverPayResponse(
1717
.filter(({ status }: NaverPayItem) => status.name !== 'CANCELLED')
1818
.map(({ date, product, additionalData }: NaverPayItem) => {
1919
return {
20-
payment_time: date,
21-
payment_place: '๋„ค์ด๋ฒ„ํŽ˜์ด',
22-
purchase_product_list: [
20+
paymentTime: date,
21+
paymentPlace: '๋„ค์ด๋ฒ„ํŽ˜์ด',
22+
purchaseProductList: [
2323
{
24-
product_name: product.name,
24+
productName: product.name,
2525
price: product.price,
2626
quantity: additionalData.orderQuantity,
2727
},

Diff for: โ€Žapp/payment-details/11st/page.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,25 @@ export default function ElevenStreetPayments() {
116116
<span className='w-1/3'>์ด๊ฐ€๊ฒฉ</span>
117117
</div>
118118
<Separator />
119-
{serverData.map(({ payment_time, purchase_product_list }, idx) => (
119+
{serverData.map(({ paymentTime, purchaseProductList }, idx) => (
120120
<>
121121
<Separator />
122122

123123
<div className='flex flex-col' key={idx}>
124124
<div className='flex'>
125125
<span className='w-1/3'>
126-
{new Date(payment_time).toLocaleDateString()}
126+
{new Date(paymentTime).toLocaleDateString()}
127127
</span>
128128
</div>
129129
<Separator />
130-
{purchase_product_list.map(
131-
({ product_name, price, quantity }, idx) => {
130+
{purchaseProductList.map(
131+
({ productName, price, quantity }, idx) => {
132132
return (
133133
<>
134134
<Separator />
135135

136136
<div className='flex' key={idx + 100}>
137-
<span className='w-1/3'>{product_name}</span>
137+
<span className='w-1/3'>{productName}</span>
138138
<span className='w-1/3'>{quantity}</span>
139139
<span className='w-1/3'>{price}</span>
140140
</div>

Diff for: โ€Žapp/payment-details/coupang/page.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,25 @@ export default function CoupangPayments() {
117117
<span className='w-1/3'>์ด๊ฐ€๊ฒฉ</span>
118118
</div>
119119
<Separator />
120-
{serverData.map(({ payment_time, purchase_product_list }, idx) => (
120+
{serverData.map(({ paymentTime, purchaseProductList }, idx) => (
121121
<>
122122
<Separator />
123123

124124
<div className='flex flex-col' key={idx}>
125125
<div className='flex'>
126126
<span className='w-1/3'>
127-
{new Date(payment_time).toLocaleDateString()}
127+
{new Date(paymentTime).toLocaleDateString()}
128128
</span>
129129
</div>
130130
<Separator />
131-
{purchase_product_list.map(
132-
({ product_name, price, quantity }, idx) => {
131+
{purchaseProductList.map(
132+
({ productName, price, quantity }, idx) => {
133133
return (
134134
<>
135135
<Separator />
136136

137137
<div className='flex' key={idx + 100}>
138-
<span className='w-1/3'>{product_name}</span>
138+
<span className='w-1/3'>{productName}</span>
139139
<span className='w-1/3'>{quantity}</span>
140140
<span className='w-1/3'>{price}</span>
141141
</div>

Diff for: โ€Žapp/payment-details/naverpay/page.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,25 @@ export default function NaverPayments() {
109109
<span className='w-1/3'>์ด๊ฐ€๊ฒฉ</span>
110110
</div>
111111
<Separator />
112-
{serverData.map(({ payment_time, purchase_product_list }, idx) => (
112+
{serverData.map(({ paymentTime, purchaseProductList }, idx) => (
113113
<>
114114
<Separator />
115115

116116
<div className='flex flex-col' key={idx}>
117117
<div className='flex'>
118118
<span className='w-1/3'>
119-
{new Date(payment_time).toLocaleDateString()}
119+
{new Date(paymentTime).toLocaleDateString()}
120120
</span>
121121
</div>
122122
<Separator />
123-
{purchase_product_list.map(
124-
({ product_name, price, quantity }, idx) => {
123+
{purchaseProductList.map(
124+
({ productName, price, quantity }, idx) => {
125125
return (
126126
<>
127127
<Separator />
128128

129129
<div className='flex' key={idx + 100}>
130-
<span className='w-1/3'>{product_name}</span>
130+
<span className='w-1/3'>{productName}</span>
131131
<span className='w-1/3'>{quantity}</span>
132132
<span className='w-1/3'>{price}</span>
133133
</div>

Diff for: โ€Žlib/api.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ export const getUserInfo = async () => {
203203
};
204204

205205
export const postPaymentDetail = async ({
206-
payment_list,
206+
paymentList,
207207
}: {
208-
payment_list: TransformedOrder[];
208+
paymentList: TransformedOrder[];
209209
}) =>
210-
await apiCall.post(BASE_URL + '/accounts/payments/detail', {
211-
payment_list,
210+
await apiCall.post(BASE_URL + '/accounts/payments/details', {
211+
paymentList,
212212
});

Diff for: โ€Žstores/atom.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Purchase, shopCartItem } from '@/types';
1+
import { Purchase, ShopCartItem } from '@/types';
22
import { atom } from 'jotai';
33
import { atomWithStorage } from 'jotai/utils';
44

55
export const fileAtom = atom<File | null>(null);
66
export const recentSearchAtom = atomWithStorage<string[]>('recentSearch', []);
7-
export const shopCartAtom = atom<shopCartItem>({
7+
export const shopCartAtom = atom<ShopCartItem>({
88
coupang: [],
99
'11st': [],
1010
});

0 commit comments

Comments
ย (0)