Skip to content

Commit

Permalink
Merge pull request #1410 from Shelf-nu/1409-bug-custodian-bookings
Browse files Browse the repository at this point in the history
fix: bug with default value of custodian field in booking form
  • Loading branch information
DonKoko authored Nov 12, 2024
2 parents 2637182 + 1dff603 commit cec0dc8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions app/components/booking/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ type BookingFormData = {
name?: string;
startDate?: string;
endDate?: string;
custodianUserId?: string; // This is a stringified value for custodianUser
custodianRef?: string; // This is a stringified value for custodianRef. It can be either a team member id or a user id
bookingStatus?: ReturnType<typeof useBookingStatusHelpers>;
bookingFlags?: BookingFlags;
assetIds?: string[] | null;
Expand All @@ -130,7 +130,7 @@ export function BookingForm({
name,
startDate,
endDate,
custodianUserId,
custodianRef,
bookingStatus,
bookingFlags,
assetIds,
Expand Down Expand Up @@ -181,13 +181,12 @@ export function BookingForm({
const now = DateTime.now();
return end < now;
}, [endDate]);

/** This is used when we have selfSErvice or Base as we are setting the default */
const defaultTeamMember = rawTeamMembers?.find(
(m) => m.userId === custodianUserId
(m) => m.userId === custodianRef || m.id === custodianRef
);


return (
<div>
<Form ref={zo.ref} method="post">
Expand Down
2 changes: 1 addition & 1 deletion app/components/booking/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function BookingPageContent() {
? dateForDateTimeInputValue(new Date(booking.to))
: undefined
}
custodianUserId={custodianUser?.id}
custodianRef={custodianUser?.id}
bookingStatus={bookingStatus}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/routes/_layout+/bookings.new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default function NewBooking() {
useLoaderData<typeof loader>();
const { startDate, endDate } = getBookingDefaultStartEndTimes();
// The loader already takes care of returning only the current user so we just get the first and only element in the array
const custodianUserId = isSelfServiceOrBase ? teamMembers[0]?.id : undefined;
const custodianRef = isSelfServiceOrBase ? teamMembers[0]?.id : undefined;

return (
<div className="booking-inner-wrapper">
Expand All @@ -205,7 +205,7 @@ export default function NewBooking() {
startDate={startDate}
endDate={endDate}
assetIds={assetIds}
custodianUserId={custodianUserId}
custodianRef={custodianRef}
/>
</div>
</div>
Expand Down

0 comments on commit cec0dc8

Please sign in to comment.