@@ -5,6 +5,8 @@ import { IoIosArrowDown, IoIosArrowUp } from 'react-icons/io';
5
5
6
6
import 'react-toastify/dist/ReactToastify.css' ;
7
7
8
+ import Button from '~/_components/Button' ;
9
+
8
10
import { Spinner } from '~/_components/Globals/Spinner' ;
9
11
10
12
import { useStore , useProductState , useGlobalState } from '~/_hooks/useStore' ;
@@ -81,6 +83,19 @@ const AddToCart = ({ product, isAuthenticated }: ProductProp) => {
81
83
} ) ;
82
84
} ;
83
85
86
+ const buttonLabel = ( ) => {
87
+ if ( product . stock === 0 ) {
88
+ return 'COMING SOON!' ;
89
+ }
90
+ if ( isSubmitting ) {
91
+ return < Spinner size = { 6 } /> ;
92
+ }
93
+ if ( state . isVariantActive || product . options ?. length === 0 ) {
94
+ return 'ADD TO CART' ;
95
+ }
96
+ return 'UNAVAILABLE' ;
97
+ } ;
98
+
84
99
return (
85
100
< >
86
101
< div className = "flex flex-wrap gap-4 py-5" >
@@ -109,26 +124,16 @@ const AddToCart = ({ product, isAuthenticated }: ProductProp) => {
109
124
</ div >
110
125
</ div >
111
126
< span className = "flex items-center gap-2" >
112
- < button
127
+ < Button
113
128
onClick = { ( ) => handleAddToCart ( ) }
114
- disabled = {
115
- product . options ?. length === 0 ? false : ! state . isVariantActive || isSubmitting
116
- }
117
- className = { `font-bold py-3 px-5 md:min-w-[240px]
118
- ${
119
- state . isVariantActive || product . options ?. length === 0
120
- ? 'bg-black font-quicksand border text-white duration-200 cursor-pointer hover:bg-white hover:text-black'
121
- : 'bg-gray-medium text-white font-quicksand border border-gray-medium'
122
- } `}
123
- >
124
- { ( state . isVariantActive || product . options ?. length === 0 ) && ! isSubmitting ? (
125
- 'ADD TO CART'
126
- ) : isSubmitting ? (
127
- < Spinner size = { 6 } />
128
- ) : (
129
- 'UNAVAILABLE'
130
- ) }
131
- </ button >
129
+ label = { buttonLabel ( ) }
130
+ variant = "fill"
131
+ className = { `font-bold py-3 px-5 md:min-w-[240px] ${
132
+ state . isVariantActive || ( product . options ?. length === 0 && product . stock !== 0 )
133
+ ? 'bg-black font-quicksand border text-white duration-200 cursor-pointer hover:bg-white hover:text-black'
134
+ : 'bg-gray-medium text-white font-quicksand border border-gray-medium'
135
+ } `}
136
+ />
132
137
< Wishlist isAuthenticated = { isAuthenticated } productId = { product . id } />
133
138
</ span >
134
139
</ div >
0 commit comments