Skip to content

Commit

Permalink
Add configuration to toggle supplier visibility in the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Feb 3, 2025
1 parent 48bddef commit 2f7ab32
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 34 deletions.
1 change: 1 addition & 0 deletions frontend/.env.docker.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ VITE_BC_APPLE_ID=XXXXXXXXXX
VITE_BC_GG_APP_ID=XXXXXXXXXX
VITE_BC_MIN_LOCATIONS=4
VITE_BC_WEBSITE_NAME=BookCars
VITE_BC_HIDE_SUPPLIERS=false
1 change: 1 addition & 0 deletions frontend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ VITE_BC_APPLE_ID=XXXXXXXXXX
VITE_BC_GG_APP_ID=XXXXXXXXXX
VITE_BC_MIN_LOCATIONS=4
VITE_BC_WEBSITE_NAME=BookCars
VITE_BC_HIDE_SUPPLIERS=false
2 changes: 1 addition & 1 deletion frontend/src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Footer = () => {
<div className="main-section">
<div className="title">{strings.RENT}</div>
<ul className="links">
<li onClick={() => navigate('/suppliers')}>{strings.SUPPLIERS}</li>
{!env.HIDE_SUPPLIERS && <li onClick={() => navigate('/suppliers')}>{strings.SUPPLIERS}</li>}
<li onClick={() => navigate('/locations')}>{strings.LOCATIONS}</li>
</ul>
</div>
Expand Down
20 changes: 11 additions & 9 deletions frontend/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,17 @@ const Header = ({
<ListItemText primary={strings.BOOKINGS} />
</ListItem>
)}
<ListItem
onClick={() => {
navigate('/suppliers')
handleSideMenuClose()
}}
>
<ListItemIcon><SupplierIcon /></ListItemIcon>
<ListItemText primary={strings.SUPPLIERS} />
</ListItem>
{!env.HIDE_SUPPLIERS && (
<ListItem
onClick={() => {
navigate('/suppliers')
handleSideMenuClose()
}}
>
<ListItemIcon><SupplierIcon /></ListItemIcon>
<ListItemText primary={strings.SUPPLIERS} />
</ListItem>
)}
<ListItem
onClick={() => {
navigate('/locations')
Expand Down
1 change: 1 addition & 0 deletions frontend/src/config/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const env = {
* Minimum number of locations required for country tabs in homepage.
*/
MIN_LOCATIONS: Number.parseInt(String(import.meta.env.VITE_BC_MIN_LOCATIONS), 10) || 4,
HIDE_SUPPLIERS: (import.meta.env.VITE_BC_HIDE_SUPPLIERS && import.meta.env.VITE_BC_HIDE_SUPPLIERS.toLowerCase()) === 'true',
}

export default env
22 changes: 12 additions & 10 deletions frontend/src/pages/Booking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,18 @@ const Booking = () => {
<div className="booking">
<div className="col-1">
<form onSubmit={handleSubmit}>
<FormControl fullWidth margin="dense">
<SupplierSelectList
label={blStrings.SUPPLIER}
required
variant="standard"
onChange={handleSupplierChange}
value={supplier}
readOnly={!edit}
/>
</FormControl>
{!env.HIDE_SUPPLIERS && (
<FormControl fullWidth margin="dense">
<SupplierSelectList
label={blStrings.SUPPLIER}
required
variant="standard"
onChange={handleSupplierChange}
value={supplier}
readOnly={!edit}
/>
</FormControl>
)}

<FormControl fullWidth margin="dense">
<LocationSelectList
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/Bookings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const Bookings = () => {
hideDates={env.isMobile}
checkboxSelection={false}
onLoad={() => setLoadingPage(false)}
hideSupplierColumn={env.HIDE_SUPPLIERS}
/>
</div>
</div>
Expand Down
18 changes: 10 additions & 8 deletions frontend/src/pages/Checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ const Checkout = () => {
hidePrice
sizeAuto
onLoad={() => setLoadingPage(false)}
// hideSupplier
hideSupplier={env.HIDE_SUPPLIERS}
/>

<CheckoutOptions
Expand Down Expand Up @@ -621,15 +621,17 @@ const Checkout = () => {
<span className="checkout-detail-title">{strings.CAR}</span>
<div className="checkout-detail-value">{`${car.name} (${bookcarsHelper.formatPrice(price / days, commonStrings.CURRENCY, language)}${commonStrings.DAILY})`}</div>
</div>
<div className="checkout-detail" style={{ height: bookingDetailHeight }}>
<span className="checkout-detail-title">{commonStrings.SUPPLIER}</span>
<div className="checkout-detail-value">
<div className="car-supplier">
<img src={bookcarsHelper.joinURL(env.CDN_USERS, car.supplier.avatar)} alt={car.supplier.fullName} style={{ height: env.SUPPLIER_IMAGE_HEIGHT }} />
<span className="car-supplier-name">{car.supplier.fullName}</span>
{!env.HIDE_SUPPLIERS && (
<div className="checkout-detail" style={{ height: bookingDetailHeight }}>
<span className="checkout-detail-title">{commonStrings.SUPPLIER}</span>
<div className="checkout-detail-value">
<div className="car-supplier">
<img src={bookcarsHelper.joinURL(env.CDN_USERS, car.supplier.avatar)} alt={car.supplier.fullName} style={{ height: env.SUPPLIER_IMAGE_HEIGHT }} />
<span className="car-supplier-name">{car.supplier.fullName}</span>
</div>
</div>
</div>
</div>
)}
<div className="checkout-detail" style={{ height: bookingDetailHeight }}>
<span className="checkout-detail-title">{strings.COST}</span>
<div className="checkout-detail-value booking-price">{bookcarsHelper.formatPrice(price, commonStrings.CURRENCY, language)}</div>
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ const Home = () => {
}

const onLoad = async () => {
let _suppliers = await SupplierService.getAllSuppliers()
_suppliers = _suppliers.filter((supplier) => supplier.avatar && !/no-image/i.test(supplier.avatar))
bookcarsHelper.shuffle(_suppliers)
setSuppliers(_suppliers)
if (!env.HIDE_SUPPLIERS) {
let _suppliers = await SupplierService.getAllSuppliers()
_suppliers = _suppliers.filter((supplier) => supplier.avatar && !/no-image/i.test(supplier.avatar))
bookcarsHelper.shuffle(_suppliers)
setSuppliers(_suppliers)
}

const _countries = await CountryService.getCountriesWithLocations('', true, env.MIN_LOCATIONS)
setCountries(_countries)
const _locations = await LocationService.getLocationsWithPosition()
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/pages/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as bookcarsTypes from ':bookcars-types'
import * as bookcarsHelper from ':bookcars-helper'
import { strings } from '@/lang/search'
import * as helper from '@/common/helper'
import env from '@/config/env.config'
import * as LocationService from '@/services/LocationService'
import * as SupplierService from '@/services/SupplierService'
// import * as UserService from '@/services/UserService'
Expand Down Expand Up @@ -291,7 +292,7 @@ const Search = () => {
{
showFilters && (
<>
<SupplierFilter className="filter" suppliers={suppliers} onChange={handleSupplierFilterChange} />
{!env.HIDE_SUPPLIERS && <SupplierFilter className="filter" suppliers={suppliers} onChange={handleSupplierFilterChange} />}
<CarRatingFilter className="filter" onChange={handleRatingFilterChange} />
<CarRangeFilter className="filter" onChange={handleRangeFilterChange} />
<CarMultimediaFilter className="filter" onChange={handleMultimediaFilterChange} />
Expand Down Expand Up @@ -329,7 +330,7 @@ const Search = () => {
seats={seats}
// distance={distance}
// onLoad={() => setLoadingPage(false)}
// hideSupplier
hideSupplier={env.HIDE_SUPPLIERS}
// includeAlreadyBookedCars
includeComingSoonCars
/>
Expand Down

0 comments on commit 2f7ab32

Please sign in to comment.