@@ -14,6 +14,7 @@ import Skeleton from '@/components/skeleton/skeleton';
14
14
import { ISeller , IUserSettings , IUser , SellerItem } from '@/constants/types' ;
15
15
import { fetchSellerItems , fetchSingleSeller } from '@/services/sellerApi' ;
16
16
import { fetchSingleUserSettings } from '@/services/userSettingsApi' ;
17
+ import { fetchToggle } from '@/services/toggleApi' ;
17
18
import { checkAndAutoLoginUser } from '@/utils/auth' ;
18
19
19
20
import { AppContext } from '../../../../../../context/AppContextProvider' ;
@@ -37,9 +38,9 @@ export default function BuyFromSellerForm({ params }: { params: { id: string } }
37
38
const [ error , setError ] = useState < string | null > ( null ) ;
38
39
const { currentUser, autoLoginUser } = useContext ( AppContext ) ;
39
40
const [ pickedItems , setPickedItems ] = useState < { id : string ; quantity : number } [ ] > ( [ ] ) ;
41
+ const [ isOnlineShoppingEnabled , setOnlineShoppingEnabled ] = useState ( false ) ;
40
42
41
-
42
- const observer = useRef < IntersectionObserver | null > ( null ) ;
43
+ const observer = useRef < IntersectionObserver | null > ( null ) ;
43
44
44
45
const handleShopItemRef = ( node : HTMLElement | null ) => {
45
46
if ( node && observer . current ) {
@@ -87,30 +88,39 @@ export default function BuyFromSellerForm({ params }: { params: { id: string } }
87
88
}
88
89
} ;
89
90
91
+ const getToggleData = async ( ) => {
92
+ try {
93
+ const toggle = await fetchToggle ( 'onlineShoppingFeature' ) ;
94
+ setOnlineShoppingEnabled ( toggle . enabled ) ;
95
+ } catch ( error ) {
96
+ logger . error ( 'Error fetching toggle:' , error ) ;
97
+ }
98
+ } ;
99
+
90
100
getSellerData ( ) ;
91
101
getSellerSettings ( ) ;
92
-
102
+ getToggleData ( ) ;
93
103
} , [ ] ) ;
94
104
95
105
// Fetch seller items
96
- useEffect ( ( ) => {
97
- const getSellerItems = async ( seller_id : string ) => {
98
- try {
99
- const items = await fetchSellerItems ( seller_id ) ;
100
- if ( items ) {
101
- setDbSellerItems ( items ) ;
102
- } else {
103
- setDbSellerItems ( null ) ;
104
- }
105
- } catch ( error ) {
106
- logger . error ( 'Error fetching seller items data:' , error ) ;
106
+ useEffect ( ( ) => {
107
+ const getSellerItems = async ( seller_id : string ) => {
108
+ try {
109
+ const items = await fetchSellerItems ( seller_id ) ;
110
+ if ( items ) {
111
+ setDbSellerItems ( items ) ;
112
+ } else {
113
+ setDbSellerItems ( null ) ;
107
114
}
108
- } ;
109
-
110
- if ( sellerShopInfo ) {
111
- getSellerItems ( sellerShopInfo . seller_id ) ;
115
+ } catch ( error ) {
116
+ logger . error ( 'Error fetching seller items data:' , error ) ;
112
117
}
113
- } , [ sellerShopInfo ] ) ;
118
+ } ;
119
+
120
+ if ( sellerShopInfo ) {
121
+ getSellerItems ( sellerShopInfo . seller_id ) ;
122
+ }
123
+ } , [ sellerShopInfo ] ) ;
114
124
115
125
116
126
const translateSellerCategory = ( category : string ) : string => {
@@ -211,57 +221,57 @@ export default function BuyFromSellerForm({ params }: { params: { id: string } }
211
221
</ div >
212
222
213
223
{ /* Online Shopping */ }
214
- < ToggleCollapse
215
- header = { t ( 'SCREEN.SELLER_REGISTRATION.SELLER_ONLINE_SHOPPING_LABEL' ) }
216
- open = { false } >
217
- < div className = "max-h-[600px] overflow-y-auto p-1 mb-7 mt-3" >
218
- { dbSellerItems && dbSellerItems . length > 0 &&
219
- dbSellerItems . map ( ( item ) => (
220
- < ListItem
221
- key = { item . _id }
222
- item = { item }
223
- pickedItems = { pickedItems }
224
- setPickedItems = { setPickedItems }
225
- refCallback = { handleShopItemRef } // Attach observer
226
- />
227
- ) )
228
- }
229
- </ div >
230
- < div >
231
- < h2 className = { SUBHEADER } > { t ( 'SCREEN.SELLER_REGISTRATION.FULFILLMENT_METHOD_TYPE.FULFILLMENT_METHOD_TYPE_LABEL' ) } </ h2 >
232
- < Select
233
- name = "fulfillment_method"
234
- options = { translatedFulfillmentMethod }
235
- value = { sellerShopInfo . fulfillment_method }
236
- disabled = { true }
237
- />
238
- < h2 className = { SUBHEADER } > { t ( 'SCREEN.SELLER_REGISTRATION.FULFILLMENT_INSTRUCTIONS_LABEL' ) } </ h2 >
239
- < TextArea
240
- name = "fulfillment_description"
241
- type = "text "
242
- value = { sellerShopInfo . fulfillment_description }
243
- disabled
244
- />
245
- < h2 className = { SUBHEADER } > { t ( 'Buyer Fulfillment Details' ) } </ h2 >
246
- < TextArea
247
- name = "buying_details"
248
- type = "text "
249
- // value={sellerShopInfo.fulfillment_description}
250
- />
251
- </ div >
252
- < div className = "mb-4 mt-3 ml-auto w-min" >
253
- < Button
254
- label = { t ( 'Checkout' ) }
255
- disabled = { pickedItems . length === 0 }
256
- styles = { {
257
- color : '#ffc153' ,
258
- height : '40px' ,
259
- padding : '15px 20px' ,
260
- } }
261
- // onClick={handleSave}
262
- / >
263
- </ div >
264
- </ ToggleCollapse >
224
+ { isOnlineShoppingEnabled && (
225
+ < ToggleCollapse
226
+ header = { t ( 'SCREEN.SELLER_REGISTRATION.SELLER_ONLINE_SHOPPING_LABEL' ) }
227
+ open = { false } >
228
+ < div className = "max-h-[600px] overflow-y-auto p-1 mb-7 mt-3" >
229
+ { dbSellerItems && dbSellerItems . length > 0 &&
230
+ dbSellerItems . map ( ( item ) => (
231
+ < ListItem
232
+ key = { item . _id }
233
+ item = { item }
234
+ pickedItems = { pickedItems }
235
+ setPickedItems = { setPickedItems }
236
+ refCallback = { handleShopItemRef } // Attach observer
237
+ />
238
+ ) )
239
+ }
240
+ </ div >
241
+ < div >
242
+ < h2 className = { SUBHEADER } > { t ( 'SCREEN.SELLER_REGISTRATION.FULFILLMENT_METHOD_TYPE.FULFILLMENT_METHOD_TYPE_LABEL' ) } </ h2 >
243
+ < Select
244
+ name = "fulfillment_method"
245
+ options = { translatedFulfillmentMethod }
246
+ value = { sellerShopInfo . fulfillment_method }
247
+ disabled = { true }
248
+ / >
249
+ < h2 className = { SUBHEADER } > { t ( 'SCREEN.SELLER_REGISTRATION.FULFILLMENT_INSTRUCTIONS_LABEL' ) } </ h2 >
250
+ < TextArea
251
+ name = "fulfillment_description "
252
+ type = "text"
253
+ value = { sellerShopInfo . fulfillment_description }
254
+ disabled
255
+ / >
256
+ < h2 className = { SUBHEADER } > { t ( 'Buyer Fulfillment Details' ) } </ h2 >
257
+ < TextArea
258
+ name = "buying_details "
259
+ type = "text"
260
+ />
261
+ </ div >
262
+ < div className = "mb-4 mt-3 ml-auto w-min" >
263
+ < Button
264
+ label = { t ( 'Checkout' ) }
265
+ disabled = { pickedItems . length === 0 }
266
+ styles = { {
267
+ color : '#ffc153' ,
268
+ height : '40px' ,
269
+ padding : '15px 20px' ,
270
+ } }
271
+ />
272
+ </ div >
273
+ </ ToggleCollapse >
274
+ ) }
265
275
266
276
< ToggleCollapse
267
277
header = { t ( 'SCREEN.BUY_FROM_SELLER.SELLER_CONTACT_DETAILS_LABEL' ) } >
0 commit comments