Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Autofill feature #15437

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Amit91848
Copy link
Contributor

What does this PR do?

Recording.2024-06-14.204324.mp4

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected)
  • I have added a Docs issue here if this PR makes changes that would require a documentation change
  • I have added or modified automated tests that prove my fix is effective or that my feature works (PRs might be rejected if logical changes are not properly tested)

Copy link

vercel bot commented Jun 14, 2024

@Amit91848 is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Jun 14, 2024
@graphite-app graphite-app bot requested a review from a team June 14, 2024 15:25
@github-actions github-actions bot added consumer Medium priority Created by Linear-GitHub Sync ✨ feature New feature or request ❗️ migrations contains migration files and removed ✨ feature New feature or request Medium priority Created by Linear-GitHub Sync consumer labels Jun 14, 2024
Copy link

graphite-app bot commented Jun 14, 2024

Graphite Automations

"Add community label" took an action on this PR • (06/14/24)

1 label was added to this PR based on Keith Williams's automation.

"Add consumer team as reviewer" took an action on this PR • (06/14/24)

1 reviewer was added to this PR based on Keith Williams's automation.

@dosubot dosubot bot added bookings area: bookings, availability, timezones, double booking event-types area: event types, event-types ✨ feature New feature or request labels Jun 14, 2024
@dosubot dosubot bot added this to the v4.4 milestone Jun 14, 2024
]);

// When initialValues is available(after doing async schema parsing) or session is available(so that we can prefill logged-in user email and name), we need to reset the form with the initialValues
// We also need the key to change if the bookingId changes, so that the form is reset and rerendered with the new initialValues
const key = `${Object.keys(initialValues).length}_${hasSession ? 1 : 0}_${initialValues?.bookingId ?? 0}`;
const key = `${prevResponse ? JSON.stringify(initialValues).length : Object.keys(initialValues).length}_${
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When previous responses were fetched, key was immediately updated and useEffect was executed before the initalValues could update. Not sure if this is the best way

@hariombalhara
Copy link
Member

I don't think it makes sense to prefill guests, notes and other things from previous booking. Ideally, only "the name, email, phone number and maybe some other user property" remains same across bookings.

@@ -88,6 +97,7 @@ export const BookerWebWrapper = (props: BookerWebWrapperAtomProps) => {
hasSession,
extraOptions: routerQuery,
prefillFormParams,
prevResponse: prevResponse?.responses as Record<string, string>,
Copy link
Member

Choose a reason for hiding this comment

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

prevResponse?.responses can be undefined as well which doesn't match the assertion used.

@keithwillcode keithwillcode added the community-interns The team responsible for reviewing, testing and shipping low/medium community PRs label Jul 3, 2024
@github-actions github-actions bot added consumer Medium priority Created by Linear-GitHub Sync labels Jul 3, 2024
const { eventTypeId } = input;
const { user, prisma } = ctx;

return await prisma.booking.findFirst({
Copy link
Member

Choose a reason for hiding this comment

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

We need the latest one and not the first one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah forgot to add orderBy, will fix it

Copy link
Member

@hariombalhara hariombalhara left a comment

Choose a reason for hiding this comment

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

@Amit91848 Left a few comments. I think we need to discuss this feature properly.

@Amit91848
Copy link
Contributor Author

I don't think it makes sense to prefill guests, notes and other things from previous booking. Ideally, only "the name, email, phone number and maybe some other user property" remains same across bookings.

When you say some other user property, what all should it include then? Should we include other booking questions or only stick to name, email and phone number?

@Amit91848 Amit91848 marked this pull request as draft July 16, 2024 15:15
Copy link
Contributor

github-actions bot commented Aug 7, 2024

This PR is being marked as stale due to inactivity.

@dosubot dosubot bot modified the milestones: v4.5, v4.4 Aug 19, 2024
@keithwillcode keithwillcode modified the milestones: v4.4, v4.5 Aug 19, 2024
@hariombalhara
Copy link
Member

I don't think it makes sense to prefill guests, notes and other things from previous booking. Ideally, only "the name, email, phone number and maybe some other user property" remains same across bookings.

When you say some other user property, what all should it include then? Should we include other booking questions or only stick to name, email and phone number?

I think name, email and phone number is what makes the most sense at the moment. We can add more if there is a good reasoning.

};

// Should be used when we know that not all fields responses are present
// - Can happen when we are parsing the prefill query string
// - Can happen when we are parsing a booking's responses (which was created before we added a new required field)
export default function getBookingResponsesSchema({ bookingFields, view }: CommonParams) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it makes sense to pass prevResponses to a function that builds the schema.

If you would see this schema when built, is passed the responses but no responses are passed to it while building the schema.

Copy link
Member

Choose a reason for hiding this comment

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

Wes should se the values here instead https://github.com/calcom/cal.com/blob/main/packages/features/bookings/Booker/components/hooks/useInitialFormValues.ts#L69-L82

It also let's us decide among various sources of name and email where should prevResponse.email's preference lie.

e.g. If a user is loggedIn, shouldn't the loggedIn user's name and email be used instead of using the localstorage one.

@@ -86,6 +87,8 @@ export const BookerWebWrapper = (props: BookerWebWrapperAtomProps) => {
};
}, [searchParams, firstNameQueryParam, lastNameQueryParam]);

const prevResponse = JSON.parse(localStorage.getItem(`prevEventTypeResp`) ?? "{}");
Copy link
Member

@hariombalhara hariombalhara Sep 10, 2024

Choose a reason for hiding this comment

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

Should we store the info per event-type as well? i.e. if a user books using different names for different events, should we honour that? I think if we do want to do it we can do it later.

Better name could be lastBookingResponse as it is the response for any of the bookings made by the user across any of the organizers.

As the customer is looking for feature parity with Calendly here, can we test out their behaviour in terms of booking different events with different emails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it would only be name and email, I think storing it per event type would be a bit too much. But as you said in case the need arises, that would be better done in a follow up PR.

I checked out how calendly does it, and it also stores a common one across all event types.

Comment on lines 81 to 86
if (values.responses) {
const prevResponse = Object.fromEntries(
Object.entries(values.responses).filter(([key]) => prevResponsesToStore.includes(key))
);
localStorage.setItem(`prevEventTypeResp`, JSON.stringify(prevResponse));
}
Copy link
Member

@hariombalhara hariombalhara Sep 10, 2024

Choose a reason for hiding this comment

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

It would be best to abstract getting and setting prevBookingResponse through a new module say previousBookingResponse.ts, so that it can be unit tested.

Copy link
Member

@hariombalhara hariombalhara left a comment

Choose a reason for hiding this comment

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

@Amit91848 Left some more suggestions

@keithwillcode keithwillcode modified the milestones: v4.5, v4.6 Sep 15, 2024
@dosubot dosubot bot modified the milestone: v4.6 Sep 15, 2024
@Amit91848
Copy link
Contributor Author

@hariombalhara I have made suggested changes. Currently we are only storing email and name because phone number identifier is dynamic

@keithwillcode keithwillcode modified the milestones: v4.6, v4.7 Oct 16, 2024
@dosubot dosubot bot modified the milestone: v4.7 Oct 16, 2024
@keithwillcode
Copy link
Contributor

@hariombalhara FYI that @anikdhabal is going to push this one through.

@keithwillcode keithwillcode marked this pull request as draft November 6, 2024 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
booking-page area: booking page, public booking page, booker bookings area: bookings, availability, timezones, double booking community Created by Linear-GitHub Sync community-interns The team responsible for reviewing, testing and shipping low/medium community PRs consumer event-types area: event types, event-types ✨ feature New feature or request Medium priority Created by Linear-GitHub Sync ❗️ migrations contains migration files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CAL-3843] Autofill feature
4 participants