Skip to content

Commit

Permalink
Update env.config.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Dec 2, 2024
1 parent 0530781 commit 61a3f14
Show file tree
Hide file tree
Showing 23 changed files with 72 additions and 72 deletions.
14 changes: 7 additions & 7 deletions backend/src/components/BookingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const BookingList = ({
const [loggedUser, setLoggedUser] = useState<bookcarsTypes.User>()
const [user, setUser] = useState<bookcarsTypes.User>()
const [page, setPage] = useState(0)
const [pageSize, setPageSize] = useState(env.isMobile() ? env.BOOKINGS_MOBILE_PAGE_SIZE : env.BOOKINGS_PAGE_SIZE)
const [pageSize, setPageSize] = useState(env.isMobile ? env.BOOKINGS_MOBILE_PAGE_SIZE : env.BOOKINGS_PAGE_SIZE)
const [columns, setColumns] = useState<GridColDef<bookcarsTypes.Booking>[]>([])
const [rows, setRows] = useState<bookcarsTypes.Booking[]>([])
const [rowCount, setRowCount] = useState(0)
Expand All @@ -97,15 +97,15 @@ const BookingList = ({
const [loading, setLoading] = useState(false)

useEffect(() => {
if (!env.isMobile()) {
if (!env.isMobile) {
setPage(paginationModel.page)
setPageSize(paginationModel.pageSize)
}
}, [paginationModel])

const fetchData = async (_page: number, _user?: bookcarsTypes.User) => {
try {
const _pageSize = env.isMobile() ? env.BOOKINGS_MOBILE_PAGE_SIZE : pageSize
const _pageSize = env.isMobile ? env.BOOKINGS_MOBILE_PAGE_SIZE : pageSize

if (suppliers && statuses) {
setLoading(true)
Expand All @@ -129,7 +129,7 @@ const BookingList = ({
}
const totalRecords = Array.isArray(_data.pageInfo) && _data.pageInfo.length > 0 ? _data.pageInfo[0].totalRecords : 0

if (env.isMobile()) {
if (env.isMobile) {
const _rows = _page === 0 ? _data.resultData : [...rows, ..._data.resultData]
setRows(_rows)
setRowCount(totalRecords)
Expand Down Expand Up @@ -355,7 +355,7 @@ const BookingList = ({
}, [bookingLoggedUser])

useEffect(() => {
if (env.isMobile()) {
if (env.isMobile) {
const element: HTMLDivElement | null = (containerClassName
? document.querySelector(`.${containerClassName}`)
: document.querySelector('div.bookings'))
Expand Down Expand Up @@ -432,7 +432,7 @@ const BookingList = ({

const handleConfirmDelete = async () => {
try {
if (env.isMobile()) {
if (env.isMobile) {
const ids = [selectedId]

const _status = await BookingService.deleteBookings(ids)
Expand Down Expand Up @@ -488,7 +488,7 @@ const BookingList = ({
</CardContent>
</Card>
)
) : env.isMobile() ? (
) : env.isMobile ? (
<>
{rows.map((booking, _index) => {
const from = new Date(booking.from)
Expand Down
8 changes: 4 additions & 4 deletions backend/src/components/CarList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const CarList = ({
const [openInfoDialog, setOpenInfoDialog] = useState(false)

useEffect(() => {
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile()) {
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile) {
const element = document.querySelector('body')

if (element) {
Expand Down Expand Up @@ -170,7 +170,7 @@ const CarList = ({
const _totalRecords = Array.isArray(_data.pageInfo) && _data.pageInfo.length > 0 ? _data.pageInfo[0].totalRecords : 0

let _rows: bookcarsTypes.Car[] = []
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile()) {
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile) {
_rows = _page === 1 ? _data.resultData : [...rows, ..._data.resultData]
} else {
_rows = _data.resultData
Expand All @@ -181,7 +181,7 @@ const CarList = ({
setTotalRecords(_totalRecords)
setFetch(_data.resultData.length > 0)

if (((env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile()) && _page === 1) || (env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile())) {
if (((env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile) && _page === 1) || (env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile)) {
window.scrollTo(0, 0)
}

Expand Down Expand Up @@ -673,7 +673,7 @@ const CarList = ({
</DialogActions>
</Dialog>
</section>
{env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile() && (
{env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile && (
<Pager
page={page}
pageSize={env.CARS_PAGE_SIZE}
Expand Down
10 changes: 5 additions & 5 deletions backend/src/components/CountryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const CountryList = ({
const _totalRecords = Array.isArray(_data.pageInfo) && _data.pageInfo.length > 0 ? _data.pageInfo[0].totalRecords : 0

let _rows = []
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile()) {
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile) {
_rows = _page === 1 ? _data.resultData : [...rows, ..._data.resultData]
} else {
_rows = _data.resultData
Expand All @@ -80,8 +80,8 @@ const CountryList = ({
setTotalRecords(_totalRecords)
setFetch(_data.resultData.length > 0)

if (((env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile()) && _page === 1)
|| (env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile())) {
if (((env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile) && _page === 1)
|| (env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile)) {
window.scrollTo(0, 0)
}

Expand All @@ -108,7 +108,7 @@ const CountryList = ({
}, [page]) // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile()) {
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile) {
const element = document.querySelector('body')

if (element) {
Expand Down Expand Up @@ -263,7 +263,7 @@ const CountryList = ({
</DialogActions>
</Dialog>
</section>
{env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile() && (
{env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile && (
<Pager
page={page}
pageSize={env.PAGE_SIZE}
Expand Down
10 changes: 5 additions & 5 deletions backend/src/components/LocationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const LocationList = ({
const _totalRecords = Array.isArray(_data.pageInfo) && _data.pageInfo.length > 0 ? _data.pageInfo[0].totalRecords : 0

let _rows = []
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile()) {
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile) {
_rows = _page === 1 ? _data.resultData : [...rows, ..._data.resultData]
} else {
_rows = _data.resultData
Expand All @@ -79,8 +79,8 @@ const LocationList = ({
setTotalRecords(_totalRecords)
setFetch(_data.resultData.length > 0)

if (((env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile()) && _page === 1)
|| (env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile())) {
if (((env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile) && _page === 1)
|| (env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile)) {
window.scrollTo(0, 0)
}

Expand All @@ -107,7 +107,7 @@ const LocationList = ({
}, [page]) // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile()) {
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile) {
const element = document.querySelector('body')

if (element) {
Expand Down Expand Up @@ -273,7 +273,7 @@ const LocationList = ({
</DialogActions>
</Dialog>
</section>
{env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile() && (
{env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile && (
<Pager
page={page}
pageSize={env.PAGE_SIZE}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/components/SimpleBackdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface SimpleBackdropProps {
text?: string
}

const marginTop = env.isMobile() ? 56 : 64
const marginTop = env.isMobile ? 56 : 64

const SimpleBackdrop = ({ progress, text }: SimpleBackdropProps) => (
<div>
Expand Down
8 changes: 4 additions & 4 deletions backend/src/components/SupplierList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const SupplierList = ({
const _totalRecords = Array.isArray(_data.pageInfo) && _data.pageInfo.length > 0 ? _data.pageInfo[0].totalRecords : 0

let _rows = []
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile()) {
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile) {
_rows = _page === 1 ? _data.resultData : [...rows, ..._data.resultData]
} else {
_rows = _data.resultData
Expand All @@ -77,7 +77,7 @@ const SupplierList = ({
setTotalRecords(_totalRecords)
setFetch(_data.resultData.length > 0)

if (((env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile()) && _page === 1) || (env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile())) {
if (((env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile) && _page === 1) || (env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile)) {
window.scrollTo(0, 0)
}

Expand All @@ -104,7 +104,7 @@ const SupplierList = ({
}, [page]) // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile()) {
if (env.PAGINATION_MODE === Const.PAGINATION_MODE.INFINITE_SCROLL || env.isMobile) {
const element = document.querySelector('body')

if (element) {
Expand Down Expand Up @@ -238,7 +238,7 @@ const SupplierList = ({
</DialogActions>
</Dialog>
</section>
{env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile() && (
{env.PAGINATION_MODE === Const.PAGINATION_MODE.CLASSIC && !env.isMobile && (
<Pager
page={page}
pageSize={env.PAGE_SIZE}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/config/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const LANGUAGES = [
]

const env = {
isMobile: () => window.innerWidth <= 960,
isMobile: window.innerWidth <= 960,

APP_TYPE: bookcarsTypes.AppType.Backend,
API_HOST: String(import.meta.env.VITE_BC_API_HOST),
Expand Down
6 changes: 3 additions & 3 deletions backend/src/pages/Bookings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const Bookings = () => {
onSubmit={handleBookingFilterSubmit}
language={(user && user.language) || env.DEFAULT_LANGUAGE}
className="cl-booking-filter"
collapse={!env.isMobile()}
collapse={!env.isMobile}
/>
</>
)}
Expand All @@ -104,8 +104,8 @@ const Bookings = () => {
statuses={statuses}
filter={filter}
loading={loadingSuppliers}
hideDates={env.isMobile()}
checkboxSelection={!env.isMobile()}
hideDates={env.isMobile}
checkboxSelection={!env.isMobile}
/>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions backend/src/pages/Car.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ const Car = () => {
car={car._id}
hideSupplierColumn
hideCarColumn
hideDates={env.isMobile()}
checkboxSelection={!env.isMobile()}
hideDates={env.isMobile}
checkboxSelection={!env.isMobile}
/>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions backend/src/pages/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ const User = () => {
user={supplier ? undefined : user}
suppliers={_suppliers}
statuses={statuses}
hideDates={env.isMobile()}
checkboxSelection={!env.isMobile()}
hideDates={env.isMobile}
checkboxSelection={!env.isMobile}
hideSupplierColumn={supplier}
language={loggedUser.language}
/>
Expand Down
4 changes: 2 additions & 2 deletions backend/src/pages/Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const Users = () => {
user={user}
types={types}
keyword={keyword}
checkboxSelection={!env.isMobile() && admin}
hideDesktopColumns={env.isMobile()}
checkboxSelection={!env.isMobile && admin}
hideDesktopColumns={env.isMobile}
/>
</div>
</div>
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/BookingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const BookingList = ({
}: BookingListProps) => {
const [user, setUser] = useState<bookcarsTypes.User>()
const [page, setPage] = useState(0)
const [pageSize, setPageSize] = useState(env.isMobile() ? env.BOOKINGS_MOBILE_PAGE_SIZE : env.BOOKINGS_PAGE_SIZE)
const [pageSize, setPageSize] = useState(env.isMobile ? env.BOOKINGS_MOBILE_PAGE_SIZE : env.BOOKINGS_PAGE_SIZE)
const [columns, setColumns] = useState<GridColDef<bookcarsTypes.Booking>[]>([])
const [rows, setRows] = useState<bookcarsTypes.Booking[]>([])
const [rowCount, setRowCount] = useState(0)
Expand All @@ -91,15 +91,15 @@ const BookingList = ({
const [cancelRequestProcessing, setCancelRequestProcessing] = useState(false)

useEffect(() => {
if (!env.isMobile()) {
if (!env.isMobile) {
setPage(paginationModel.page)
setPageSize(paginationModel.pageSize)
}
}, [paginationModel])

const fetchData = async (_page: number, _user?: bookcarsTypes.User) => {
try {
const _pageSize = env.isMobile() ? env.BOOKINGS_MOBILE_PAGE_SIZE : pageSize
const _pageSize = env.isMobile ? env.BOOKINGS_MOBILE_PAGE_SIZE : pageSize

if (suppliers && statuses) {
setLoading(true)
Expand All @@ -124,7 +124,7 @@ const BookingList = ({
}
const totalRecords = Array.isArray(_data.pageInfo) && _data.pageInfo.length > 0 ? _data.pageInfo[0].totalRecords : 0

if (env.isMobile()) {
if (env.isMobile) {
const _rows = _page === 0 ? _data.resultData : [...rows, ..._data.resultData]
setRows(_rows)
setRowCount(totalRecords)
Expand Down Expand Up @@ -316,7 +316,7 @@ const BookingList = ({
}, [suppliers, statuses, filter]) // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (env.isMobile()) {
if (env.isMobile) {
const element = document.querySelector('body')

if (element) {
Expand Down Expand Up @@ -389,7 +389,7 @@ const BookingList = ({
</CardContent>
</Card>
)
) : env.isMobile() ? (
) : env.isMobile ? (
<>
{rows.map((booking) => {
const _bookingCar = booking.car as bookcarsTypes.Car
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/components/CarFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ const CarFilter = ({
<LocationSelectList
label={commonStrings.PICK_UP_LOCATION}
hidePopupIcon
customOpen={env.isMobile()}
init={!env.isMobile()}
customOpen={env.isMobile}
init={!env.isMobile}
required
variant="standard"
value={pickupLocation as bookcarsTypes.Location}
Expand All @@ -150,8 +150,8 @@ const CarFilter = ({
label={commonStrings.DROP_OFF_LOCATION}
value={dropOffLocation as bookcarsTypes.Location}
hidePopupIcon
customOpen={env.isMobile()}
init={!env.isMobile()}
customOpen={env.isMobile}
init={!env.isMobile}
required
variant="standard"
onChange={handleDropOffLocationChange}
Expand Down Expand Up @@ -248,8 +248,8 @@ const CarFilter = ({
<LocationSelectList
label={commonStrings.PICK_UP_LOCATION}
hidePopupIcon
customOpen={env.isMobile()}
init={!env.isMobile()}
customOpen={env.isMobile}
init={!env.isMobile}
required
variant="standard"
value={pickupLocation as bookcarsTypes.Location}
Expand Down Expand Up @@ -308,8 +308,8 @@ const CarFilter = ({
label={commonStrings.DROP_OFF_LOCATION}
value={dropOffLocation as bookcarsTypes.Location}
hidePopupIcon
customOpen={env.isMobile()}
init={!env.isMobile()}
customOpen={env.isMobile}
init={!env.isMobile}
required
readOnly={sameLocation}
variant="standard"
Expand Down
Loading

0 comments on commit 61a3f14

Please sign in to comment.