Skip to content

Commit 18a807f

Browse files
authored
Merge pull request #162 from w3bdesign/development
Add UI feedback for adding to cart
2 parents 5caf92e + 4843213 commit 18a807f

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

components/Cart/AddToCartButton.component.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { v4 as uuidv4 } from 'uuid';
66
import { useQuery, useMutation } from '@apollo/react-hooks';
77

88
import { AppContext } from 'utils/context/AppContext';
9+
import LoadingSpinner from '../LoadingSpinner/LoadingSpinner.component';
910

1011
import { GET_CART } from 'utils/const/GQL_QUERIES';
1112
import { ADD_TO_CART } from 'utils/const/GQL_MUTATIONS';
@@ -92,6 +93,13 @@ const AddToCartButton = (props) => {
9293
>
9394
KJØP
9495
</button>
96+
{addToCartLoading && (
97+
<div className="text-xl text-center">
98+
Legger i handlekurv, vennligst vent ...
99+
<br />
100+
<LoadingSpinner />
101+
</div>
102+
)}
95103
</>
96104
);
97105
};

components/Cart/CartPage/CartItemsContainer.component.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const CartItemsContainer = () => {
4040
setRequestError(error);
4141
},
4242
});
43-
// TODO We will focus on fetching the cart before we add more functionality
43+
// TODO Add more functionality
4444

4545
return (
4646
<>

components/Checkout/CheckoutForm.component.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const CheckoutForm = () => {
2424
const [input, setInput] = useState(INITIAL_STATE);
2525
const [orderData, setOrderData] = useState(null);
2626
const [requestError, setRequestError] = useState(null);
27+
const [orderCompleted, setorderCompleted] = useState(false);
2728

2829
// Checkout GraphQL mutation
2930
const [
@@ -34,6 +35,7 @@ const CheckoutForm = () => {
3435
input: orderData,
3536
},
3637
onCompleted: () => {
38+
setorderCompleted(true);
3739
refetch();
3840
},
3941
onError: (error) => {
@@ -125,9 +127,13 @@ const CheckoutForm = () => {
125127
</div>
126128
</form>
127129
) : (
128-
<div className="container m-12 mx-auto text-xl text-center">
129-
Takk for din ordre!
130-
</div>
130+
<>
131+
{orderCompleted && (
132+
<div className="container m-12 mx-auto text-xl text-center">
133+
Takk for din ordre!
134+
</div>
135+
)}
136+
</>
131137
)}
132138
</>
133139
);

components/LoadingSpinner/LoadingSpinner.component.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const rotateAnimation = keyframes`
2424
`;
2525

2626
const Circle = styled.div`
27-
width: 100px;
28-
height: 100px;
27+
width: 50px;
28+
height: 50px;
2929
border-radius: 50px;
3030
border: 10px solid black;
3131
border-right: 10px solid white;
@@ -42,5 +42,5 @@ const Container = styled.div`
4242
align-items: center;
4343
justify-content: center;
4444
flex-direction: column;
45-
height: 130px;
45+
height: 110px;
4646
`;

0 commit comments

Comments
 (0)