Restricting user to ONE booking per month

Hey,

I’m trying to limit bookings (with Type = Trial) to one per month for each individual listing on my marketplace.

For example, user can book listing A on the 9th June, and again on the 1st July.

At the moment, when the user clicks the ‘book’ button, I create a new booking with type = Trial.

I’m not sure which constraints to add to make sure they can only book once per month. If user has booked within the current month, I’d like to hide the ‘book’ button completely and replace it with a message.

Here’s what my workflow for a booking (with Type = Trial) looks like at the moment.

Any help would be great! Thanks :slight_smile:

I would extract the month from the date of the booking and then check the current date. If it is equal to the date of the last booking then dont show the button.

Should I write that as a conditional on the button? Not sure how I can extract the month from the booking date for the current page user (or should I ‘do a search for’)?

I suspect that this “extract month” approach, would mean that I could create a booking on the 30th of Nov and again on the 1st of Dec? Is this acceptable? If not then perhaps another approach is to only display the button when the user is not on trial or when they are on trial AND count of bookings where date > current date/time :+days(-30) is 0. Something like that. Note: I don’t have access to Bubble right now so I can’t look to see if :+months(-1) is possible.

1 Like

I considered both:

a.) once per month (so it could be 30th Nov and 1st dec)
b.) once every 30 days

I’m probably leaning towards once every 30 days right now, but will put more thought into it.

I think the word ‘Trial’ in this case is misleading, as it’s not a ‘trial plan’ but a membership type - so if the user is paying for the ‘trial’ plan, then they have membership until they stop paying.

I’m just a little confused about how to add the functionality - I’m leaning towards on a conditional on the ‘book’ button, and I basically want to say:

When current user has booked this listing within 30 days, this button should be invisible.

Can’t figure out the exact commands (past ‘When current user’)!

Try starting with do a search for booking instead, and set constraints to booked by current user, listing = this listing, date within 30 days, then finish with count = 0.

1 Like

Thanks for the help, think I’m getting there - I’m trying to apply your advice to the ‘book unlimited’ button which displays the actual booking overlay.

I’d like to have the ‘Book Unlimited’ button to disappear if 30 days has not been yet reached (or replace it with a ‘You can book this again in X days’ message), so I’ve done the following:

Not sure what to add after ‘Search for Bookings’.

I’ve been able to work through most issues but this one is really puzzling me!

Don’t you need one more constraint for the date? From your earlier screenshot, I believe the field is selected date. So in addition to Client and ActivityListing, I thought you would set selected date > current date/time :+days(-30).

Select :count then type > 0. Note: I’m saying > because I assume the button is enabled by default and you want to disable or hide it if there is already a listing matching your criteria.

1 Like

Yep you’re right, I’ve added the date constraint too. I have this working up to the point where I can affect the button (not clickable + text changed), but I’m not sure how the countdown works.

I changed current date/time :+days(-30) to current date/time :+seconds(-30) to test if the button would revert, but it doesn’t seem to go back to its previous state to allow me to book the listing again.

I’ve changed ‘Trial’ to ‘Unlimited’ so that it makes more sense.

After 30 days (in this case, 30 seconds), the book button should allow me to book the listing again, that’s the only bit missing so far!

Thanks

If you have a booking that matches the criteria then this should work (revert).

Quick test - add a text element to your page within the same group as the button. Copy your search to it, removing the ‘> 0’ at the end. What is the count you get?

If you still can’t get it to work, consider sharing a link to your application editor.

1 Like

The count I get is ‘1’, so that’s showing the correct number of bookings.

But after 30 seconds, there is no change (and I don’t know if we’ve commanded it to change) to allow the user to re-book that listing.

Here’s my editor:

Your app editor isn’t public for viewing. You have to set that in the Setting/General tab.

1 Like

Strange, I have it set to ‘Everyone can edit’ - anything else I need to do?

Thanks

Ok, for some reason your link in the forums is the problem. The ampersands are encoded as & which breaks the link. I modified it and I am in your app looking. Stay tuned.

1 Like

Ok, here is what I am pretty sure is the issue. Your date-time field in your booking table is of type text, not date. You are trying to see if the TEXT value “11/03/2017 12:00:00” is greater than the DATE value of NOW. Your date-time field needs to be an actual date field type.

Marc

2 Likes

Hey,

Ah - I changed the date-time field to use a date TYPE instead (called Booking date), but the button text isn’t changing/the button isn’t allowing me to book again after 30 seconds. I think everything is configured correctly now.

I’m still trying to comprehend this: Booking Date > Current date/time +(seconds) -30

What does the statement above mean (if you phrased it as a sentence)?

Booking Date > Current date/time +(seconds) -30 means is the date you stored in the “booking date” field greater than (or more specifically LATER than) 30 seconds prior to NOW.

Based on the one record in the booking table that currently has a booking date, your problem is that it has a date in the future. You are presumably storing the date of the class/event/etc. I think what you are trying to do is store the date/time the booking happened. (I booked a class TODAY at 1PM that is scheduled to happen a week from now). You could use Created Date instead.

Created Date > Current date/time +(seconds) -30

2 Likes

Thanks for the explanation - I have it working now! Thanks very much @louisadekoya and @mguerrasio

If a user books class on the 1st December, they will be able to book again on the 31st December. I tested it with -30 seconds and it worked perfectly (after a page refresh) so I’ve scaled it up to 30 days now.

The only thing I don’t have working is a button countdown - when a class can’t be booked, the button says: You can book this again in X days - I want X to start at 30 days and countdown daily (not in realtime, just on page refresh).

I found a few guides on Bubble for this so I should be OK but I will ask if I need further assistance.

Thanks again guys

1 Like

Try do a search for (latest booking)'s created date +days 30 - current date/time :format as days. It should look something like below, but of course, in your case, the search is for a booking (last unlimited one by the user).

example2

1 Like

That seems to work, thanks!

By adding the :first item’s Creation Date, will that apply to the most recent bookings or only the first ever booking?

Thanks again