File tree Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Expand file tree Collapse file tree 2 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -8,21 +8,14 @@ import { Text } from '@/shared/components/Text';
8
8
import Back from '../../../../public/Back.png' ;
9
9
import { StepProps } from '../../../shared/types/funnel' ;
10
10
import { CartItem } from '../types/Cart.types' ;
11
+ import { useOrderInfo } from '../hooks/useOrderInfo' ;
11
12
12
13
type OrderConfirmProps = {
13
14
cartItems : CartItem [ ] ;
14
15
} & StepProps ;
15
16
16
17
export const OrderConfirm = ( { cartItems, onPrev } : OrderConfirmProps ) => {
17
- const hasCheckCartLength = cartItems ?. filter ( ( item ) => item . isChecked ) . length ;
18
- const totalQuantity = cartItems ?. reduce (
19
- ( acc , item ) => acc + ( item . isChecked ? item . quantity : 0 ) ,
20
- 0
21
- ) ;
22
- const totalPrice = cartItems ?. reduce (
23
- ( acc , item ) => acc + ( item . isChecked ? item . product . price * item . quantity : 0 ) ,
24
- 0
25
- ) ;
18
+ const { hasCheckCartLength, totalQuantity, totalPrice } = useOrderInfo ( cartItems ) ;
26
19
27
20
return (
28
21
< >
Original file line number Diff line number Diff line change
1
+ import { CartItem } from '../types/Cart.types' ;
2
+
3
+ export const useOrderInfo = ( cartItems : CartItem [ ] = [ ] ) => {
4
+ const hasCheckCartLength = cartItems . filter ( ( item ) => item . isChecked ) . length ;
5
+
6
+ const totalQuantity = cartItems . reduce (
7
+ ( acc , item ) => acc + ( item . isChecked ? item . quantity : 0 ) ,
8
+ 0
9
+ ) ;
10
+
11
+ const totalPrice = cartItems . reduce (
12
+ ( acc , item ) => acc + ( item . isChecked ? item . product . price * item . quantity : 0 ) ,
13
+ 0
14
+ ) ;
15
+
16
+ return {
17
+ hasCheckCartLength,
18
+ totalQuantity,
19
+ totalPrice,
20
+ } ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments