Skip to content

fix(booking): ensure BASE/SELF_SERVICE users can create bookings from asset index#2161

Merged
DonKoko merged 2 commits intomainfrom
fix-issue-with-custodian-select-for-bookings
Nov 3, 2025
Merged

fix(booking): ensure BASE/SELF_SERVICE users can create bookings from asset index#2161
DonKoko merged 2 commits intomainfrom
fix-issue-with-custodian-select-for-bookings

Conversation

@DonKoko
Copy link
Copy Markdown
Contributor

@DonKoko DonKoko commented Nov 3, 2025

Add teamMembersForForm support to both simple and advanced mode loaders in data.server.ts. This ensures BASE/SELF_SERVICE users always have their team member available in the custodian dropdown when creating bookings from the asset index bulk actions, regardless of pagination settings.

Previously, when canSeeAllCustody was true, team members were paginated to 12 items, and the current user's team member might not be in the first page, preventing booking creation.

This completes the fix across all booking creation entry points:

  • Bookings index
  • Calendar
  • Asset detail page
  • Kit detail page
  • Asset index bulk actions (this change)

… asset index

Add teamMembersForForm support to both simple and advanced mode loaders
in data.server.ts. This ensures BASE/SELF_SERVICE users always have their
team member available in the custodian dropdown when creating bookings
from the asset index bulk actions, regardless of pagination settings.

Previously, when canSeeAllCustody was true, team members were paginated
to 12 items, and the current user's team member might not be in the
first page, preventing booking creation.

This completes the fix across all booking creation entry points:
- Bookings index
- Calendar
- Asset detail page
- Kit detail page
- Asset index bulk actions (this change)
@vercel
Copy link
Copy Markdown

vercel bot commented Nov 3, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
shelf-docs Ignored Ignored Preview Nov 3, 2025 3:08pm

@DonKoko DonKoko requested a review from Copilot November 3, 2025 14:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors team member data fetching for booking forms to optimize performance and separate concerns between filter dropdowns and form custodian selects. The key change introduces a new getTeamMemberForForm function that optimizes the query for BASE/SELF_SERVICE users by fetching only their team member in a single query, while ADMIN users continue to get the paginated list.

  • Replaces getTeamMemberForCustodianFilter with getTeamMemberForForm in booking form contexts
  • Introduces conditional data fetching: BASE/SELF_SERVICE users get optimized single queries, ADMIN users reuse filter data
  • Adds teamMembersForForm property across multiple routes to maintain backward compatibility and clear separation

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
app/modules/team-member/service.server.ts Adds new getTeamMemberForForm function that optimizes team member fetching for forms
app/routes/_layout+/bookings.new.tsx Replaces getTeamMemberForCustodianFilter with getTeamMemberForForm and adds teamMembersForForm property
app/routes/_layout+/bookings._index.tsx Conditionally fetches team members for forms, reusing filter data for ADMIN users
app/routes/_layout+/calendar.tsx Separates filter and form team member fetching with conditional logic for BASE/SELF_SERVICE
app/routes/_layout+/assets.$assetId.overview.create-new-booking.tsx Updates to use getTeamMemberForForm for booking creation
app/routes/_layout+/kits.$kitId.assets.create-new-booking.tsx Updates to use getTeamMemberForForm for kit booking creation
app/modules/asset/data.server.ts Adds conditional team member fetching for both simple and advanced mode loaders
app/components/booking/forms/new-booking-form.tsx Updates to use teamMembersForForm with fallback to teamMembers
app/components/booking/forms/fields/custodian.tsx Changes initialDataKey from teamMembers to teamMembersForForm
app/components/booking/create-booking-dialog.tsx Updates to use teamMembersForForm instead of teamMembers
Comments suppressed due to low confidence (1)

app/modules/team-member/service.server.ts:576

  • Corrected spelling of 'THis' to 'This' and 'doenst' to 'doesn't'.
 * Fixes team members with invalid names. THis runs as void on the background so it doenst block the main thread

Comment thread app/modules/team-member/service.server.ts Outdated
Comment thread app/modules/team-member/service.server.ts
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

export default function CreateBookingForSelectedAssetsDialog() {
const { currentOrganization, teamMembers, tagsData } =
useLoaderData<AssetIndexLoaderData>();
const tagsSuggestions = tagsData.tags.map((tag) => ({
label: tag.name,
value: tag.id,
}));
const selectedAssets = useAtomValue(selectedBulkItemsAtom);
const workingHoursData = useWorkingHours(currentOrganization.id);
const { workingHours } = workingHoursData;
const bookingSettings = useBookingSettings();
const zo = useZorm(
"CreateBookingWithAssets",
BookingFormSchema({
action: "new",
workingHours,
bookingSettings,
})
);
const { startDate: defaultStartDate, endDate: defaultEndDate } =
getBookingDefaultStartEndTimes(
workingHours,
bookingSettings.bufferStartTime
);
const [startDate, setStartDate] = useState(defaultStartDate);
const [endDate, setEndDate] = useState(defaultEndDate);
const { isBaseOrSelfService, roles } = useUserRoleHelper();
const user = useUserData();
const defaultTeamMember = isBaseOrSelfService
? teamMembers.find((tm) => tm.userId === user!.id)

P1 Badge Custodian defaults still pull from paginated teamMembers list

The bulk booking dialog on the asset index still derives defaultTeamMember from teamMembers. For BASE/SELF_SERVICE users with canSeeAllCustody, that array is paginated to 12 results and often does not contain the current user—exactly the scenario this change set is meant to solve. Although the loader now returns teamMembersForForm with the guaranteed current team member, the dialog ignores it and therefore still yields undefined defaults and an unusable custodian select. Use teamMembersForForm (or fall back to teamMembers) for the lookup so these users can actually create bookings from the asset index.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

1. Use teamMembersForForm in CreateBookingForSelectedAssetsDialog
   Previously, the dialog searched the paginated teamMembers array for
   the default custodian, causing undefined defaults when the user's
   team member wasn't in the first 12 results. Now uses
   teamMembersForForm which guarantees the current user's team member
   is present for BASE/SELF_SERVICE users.

2. Fix totalTeamMembers count in getTeamMemberForForm
   Changed from hardcoded 1 to teamMember ? 1 : 0 to accurately
   reflect when no team member is found. This prevents inconsistencies
   that could affect pagination or UI logic depending on this count.

3. Explicitly pass filterByUserId: false for ADMIN users
   Made the intent clear by explicitly passing filterByUserId: false
   when calling getTeamMemberForCustodianFilter for ADMIN users,
   rather than relying on undefined behavior.
@DonKoko DonKoko merged commit fb13d29 into main Nov 3, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants