Skip to content

Commit

Permalink
Fix BookingList.tsx and User.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Apr 23, 2024
1 parent 3958c32 commit bb7dc3a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/src/components/BookingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const BookingList = ({
if (agencies && statuses && loggedUser) {
fetchData(page, user)
}
}, [page, loggedUser]) // eslint-disable-line react-hooks/exhaustive-deps
}, [page]) // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (agencies && statuses && loggedUser) {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/pages/Bookings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Bookings = () => {
setLeftPanel(!_admin)
setLoadingAgencies(_admin)

const _allAgencies = _admin ? await AgencyService.getAllAgencies() : []
const _allAgencies = await AgencyService.getAllAgencies()
const _agencies = _admin ? movininHelper.flattenAgencies(_allAgencies) : [_user._id ?? '']
setAllAgencies(_allAgencies)
setAgencies(_agencies)
Expand Down
17 changes: 15 additions & 2 deletions backend/src/pages/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ const User = () => {
const edit = loggedUser && user && (loggedUser.type === movininTypes.RecordType.Admin || loggedUser._id === user._id || (loggedUser.type === movininTypes.RecordType.Agency && loggedUser._id === user.agency))
const agency = user && user.type === movininTypes.RecordType.Agency

const _agencies: string[] = []
if (loggedUser && user) {
if ((agency && loggedUser._id === user._id)
|| (loggedUser.type === movininTypes.RecordType.Admin && user.type === movininTypes.RecordType.Agency)
) {
_agencies.push(user._id as string)
} else if (loggedUser.type === movininTypes.RecordType.Agency && user.type === movininTypes.RecordType.User) {
_agencies.push(loggedUser._id as string)
} else if (loggedUser.type === movininTypes.RecordType.Admin) {
_agencies.push(...agencies)
}
}

return (
<Master onLoad={onLoad} strict>
{loggedUser && user && visible && (
Expand Down Expand Up @@ -196,13 +209,13 @@ const User = () => {
</div>
</div>
<div className="col-2">
{(edit || !agency) && (
{_agencies.length > 0 && (
<BookingList
containerClassName="user"
offset={offset}
loggedUser={loggedUser}
user={agency ? undefined : user}
agencies={agency ? [user._id as string] : agencies}
agencies={_agencies}
statuses={statuses}
hideDates={env.isMobile()}
checkboxSelection={!env.isMobile()}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/BookingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const BookingList = ({
if (agencies && statuses && user) {
fetchData(page, user)
}
}, [page, user]) // eslint-disable-line react-hooks/exhaustive-deps
}, [page]) // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (agencies && statuses && user) {
Expand Down

0 comments on commit bb7dc3a

Please sign in to comment.