-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton
More file actions
40 lines (33 loc) · 1.18 KB
/
button
File metadata and controls
40 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { useSelector } from 'react-redux';
import { CART_STATUS } from '@jmsstudiosinc/cart';
import { cartSectionSelector } from '../utils';
import styles from './styles';
import { useNavigation } from '@react-navigation/native';
const ViewButtonCart = () => {
const insets = useSafeAreaInsets();
const cartList = useSelector((state) => cartSectionSelector(state.cart.cartList, CART_STATUS.added));
const formattedCartList = (cartList) => {
let results = [];
for (const cartItem of cartList) {
results = cartItem.data;
}
return results;
};
const totalItems = formattedCartList(cartList)
.map((item) => item.quantity)
.reduce((prev, curr) => prev + curr, 0);
const navigation = useNavigation();
return (
<FAB
icon="cart-arrow-down"
label={`View Cart ${totalItems}`}
uppercase={true}
style={[styles.FAB, { bottom: insets.bottom }]}
mode="elevated"
variant="primary"
onPress={() => navigation.navigate('Cart')}
visible={cartList.length > 0 ? true : false}
/>
);
};
export default ViewButtonCart;