Skip to content

add lending to event creating/editing - #5863

Open
ShaileshS1702 wants to merge 15 commits into
masterfrom
3884-add-lending-to-events
Open

add lending to event creating/editing#5863
ShaileshS1702 wants to merge 15 commits into
masterfrom
3884-add-lending-to-events

Conversation

@ShaileshS1702

@ShaileshS1702 ShaileshS1702 commented Feb 10, 2026

Copy link
Copy Markdown
Member

Description

Add the possibility of lending an object directly from the event edit form

Result

If you've made visual changes, please check the boxes below and include images showing the changes. Descriptions are appreciated.

  • Changes look good on both light and dark theme.
  • Changes look good with different viewports (mobile, tablet, etc.).
  • Changes look good with slower Internet connections.

Caution

Make sure your images do not contain any real user information.

Description Before After
Dark mode ... image
Dark mode with lending objects chosen ... image
 </td>
</tr>

Testing

  • I have thoroughly tested my changes.

Please describe what and how the changes have been tested, and provide instructions to reproduce if necessary.


Resolves #5862

@ShaileshS1702 ShaileshS1702 self-assigned this Feb 10, 2026
@github-actions github-actions Bot added the review-needed Pull requests that need review label Feb 10, 2026
@ShaileshS1702
ShaileshS1702 force-pushed the 3884-add-lending-to-events branch from b9ce526 to 82306b4 Compare February 10, 2026 21:14

@ch0rizo ch0rizo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Really cool feature!

Comment thread lego-webapp/pages/events/src/EventEditor/index.tsx Outdated
@ShaileshS1702
ShaileshS1702 force-pushed the 3884-add-lending-to-events branch from 82306b4 to 22ad34b Compare February 26, 2026 11:44

@ch0rizo ch0rizo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

M

Comment thread lego-webapp/pages/events/src/EventEditor/index.tsx Outdated

@jonasdeluna jonasdeluna left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is very cool! Could we have some relation between the event and requests, so that we can see/filter on the event page or in the ending page based on events? The event could for example store its own lending requests?
Could be a separate more extensive feature though

@ShaileshS1702
ShaileshS1702 requested a review from ch0rizo April 13, 2026 16:16
@ShaileshS1702
ShaileshS1702 force-pushed the 3884-add-lending-to-events branch from 8513cb5 to f554c29 Compare April 13, 2026 18:17
@ShaileshS1702
ShaileshS1702 force-pushed the 3884-add-lending-to-events branch from bce2305 to b7ab5ef Compare April 22, 2026 17:09
@ShaileshS1702
ShaileshS1702 force-pushed the 3884-add-lending-to-events branch from b20825b to aee42ac Compare May 18, 2026 10:18
@ShaileshS1702
ShaileshS1702 force-pushed the 3884-add-lending-to-events branch from aee42ac to 5b793bc Compare May 18, 2026 10:29

@ch0rizo ch0rizo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this a nice and useful feature!! There are some bugs and fixes I would take a closer look.

for (let i = 0; i < values.lendingObjects.length; i++) {
const lendingRequestData: CreateLendingRequest = {
lendableObject: values.lendingObjects[i].value,
comment: values.lendingDescription[i] || '',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
comment: values.lendingDescription[i] || '',
comment: values.lendingDescription?[i] || '',

Crash when an object is selected but no comment typed. Here you fix it with a default empty string. However, lendingDescription is not in the initialValues. If the user selects a lending object, but never types into any comment field, values.lendingDescription is undefined -> underfined[i] throws on submit. Basically since values.lendingDescription is an array it will fail before hitting the default ''

void dispatch(setSaveForUse(key, token, true));
}

// Create lending request if lendingObjects exist and we're creating a new event

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am worried that this will create a lending request on editing the event aswell. Because there are no difference between edit and create form. There should gated with isEditPage.

Comment on lines +27 to +39
export const fetchAvailableLendableObjectIdsByDate = (
start_date: string | Dateish,
end_date: string | Dateish,
) =>
callAPI<EntityId[]>({
types: LendableObjects.FETCH_AVAILABLE,
endpoint: '/lending/objects/available/',
query: { start_date, end_date },
meta: {
errorMessage: 'Henting av tilgjengelige utlånsobjekter feilet',
},
propagateError: true,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Availability fetch keys off startTime/endTime which is never change in the form (LendingSection.tsx). The form's date field is name="date" (a range) -> values.date[0]/values.date[1]. There is no date-driven startTime/endTime on form values. This means:

  • On create: startTime/endtime are undefined -> always hits the clear branch, availability is never fetched.
  • On edit: they hold the stale initial values -> fetched once with the original dates, never updates when the user picks a new range.

However onSubmit correctly uses values.date[0]/values.date[1] for the request - so the two halves of the feature disagree. A possible solution is to switch the availability effect to values.date?.[0] / values.date?.[1]

Comment on lines +45 to +46
// eslint-disable-next-line no-console
console.error('fetchAllLendableObjects failed', err);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would not leave this in prod. If errors is to be announced it should be through user friendly toasts

Comment on lines +70 to +71
// eslint-disable-next-line no-console
console.error('fetchAvailableLendableObjectIdsByDate failed', err);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here as well :)

Comment on lines +272 to +273
// Attach a requestId to meta for request identity (used to ignore stale responses)
const requestId = `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a global change. callAPI.ts is a the foundation of every redux API action in the app. This will add requestId to every action's meta.

Maybe reconsider making a global change for a local need. A proposed solution would be to solve the stale-response handling locally in LendingSection, without touching callAPI at all. The thunk from dispatch(fetchAvailable…) already returns a promise - you can await it and compare against the latest dispatched date range (or keep the "latest request" marker in a useRef (probably not a ideal🤷‍♂️)).

Comment on lines +91 to 92
FETCH_AVAILABLE: generateStatuses('LendableObject.FETCH_AVAILABLE'),
FETCH_AVAILABILITY: generateStatuses('LendableObject.FETCH_AVAILABILITY'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the difference? Should there be a single source of truth, if they have the same purpose

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Its a bit confusing with the naming convention. Seems one is for bulk availability and the other one for a specific one

Comment on lines +44 to +63
state.lastAvailabilityRequestId = action.meta?.requestId ?? null;
},
);
addCase(
LendableObjects.FETCH_AVAILABLE.SUCCESS,
(state, action: AnyAction) => {
// Only apply success payload if it matches the latest request id
const requestId = action.meta?.requestId ?? null;
if (requestId && state.lastAvailabilityRequestId !== requestId) {
// stale response — ignore
return;
}
state.availabilityFetchFailed = false;
state.availableIds = action.payload;
},
);
addCase(
LendableObjects.FETCH_AVAILABLE.FAILURE,
(state, action: AnyAction) => {
const requestId = action.meta?.requestId ?? null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Consider rewriting this if you didn't change callAPI.ts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just curious what is this for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-needed Pull requests that need review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add lending to events

3 participants