Skip to content

Commit

Permalink
fix: make order button disabled in case cart is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jsapro committed Dec 22, 2023
1 parent 9a68fb9 commit f2bd617
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/components/Button/button.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
transition: 0.5s;

&:disabled {
background-color: black;
cursor: not-allowed;
background-color: $accent-color-lightest-green;
cursor: initial;
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/components/making-order-btn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import styles from './making-order-btn.module.scss';
import Button from '@components/Button';

interface MakingOrderBtnProps {
isDisabled: boolean;
onClick?: () => void;
}

const MakingOrderBtn: React.FC<MakingOrderBtnProps> = ({ onClick }) => {
const MakingOrderBtn: React.FC<MakingOrderBtnProps> = ({ onClick, isDisabled }) => {
return (
<div className={styles.order}>
<Button buttonText="Оформить заказ" buttonStyle="green-button" onClick={onClick} />
<Button
buttonText="Оформить заказ"
buttonStyle="green-button"
onClick={onClick}
disabled={isDisabled}
/>
<p className={`${styles.order__title}`}>
Нажимая на&nbsp;кнопку &laquo;Оформить заказ&raquo;, вы&nbsp;соглашаетесь
с&nbsp;условиями обработки персональных данных, а&nbsp;также с&nbsp;условиями
Expand Down
4 changes: 2 additions & 2 deletions src/components/making-order-btn/making-order-btn.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
transition: 0.5s;

&:disabled {
background-color: black;
cursor: not-allowed;
background-color: $accent-color-lightest-green;
cursor: initial;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/pages/checkout/checkout.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@
transition: 0.5s;

&:disabled {
background-color: black;
cursor: not-allowed;
background-color: $accent-color-lightest-green;
cursor: initial;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/pages/checkout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ const Checkout: React.FC = () => {
!isLoggedIn && !isValid ? `${styles['orderse__buttonStyle_error']}` : ''
}`}
onClick={handleSubmitOrder}
disabled={cartData.products.length === 0}
>
Оформить заказ
</button>
Expand Down
5 changes: 4 additions & 1 deletion src/pages/shopping-cart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ const ShoppingCart: React.FC = () => {
</p>
</div>
</div>
<MakingOrderBtn onClick={handleSubmitOrderClick} />
<MakingOrderBtn
onClick={handleSubmitOrderClick}
isDisabled={cartData.products.length === 0}
/>
</div>
</div>
)}
Expand Down

0 comments on commit f2bd617

Please sign in to comment.