Skip to content

Fixes for advanced tabs form logic#4731

Merged
emrysal merged 4 commits intomainfrom
fixes/eventtype-advanced-form-logic
Sep 29, 2022
Merged

Fixes for advanced tabs form logic#4731
emrysal merged 4 commits intomainfrom
fixes/eventtype-advanced-form-logic

Conversation

@zomars
Copy link
Copy Markdown
Contributor

@zomars zomars commented Sep 28, 2022

What does this PR do?

  • Adds disabled cursor for disabled switches
  • Fixes logic for seated events
Grabacion.de.pantalla.2022-09-28.a.la.s.12.17.14.mov

Environment: Staging(main branch) / Production

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Go to an event type edit view and play with the advanced type values. Should be working as expected

@vercel
Copy link
Copy Markdown

vercel Bot commented Sep 28, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
cal ✅ Ready (Inspect) Visit Preview Sep 29, 2022 at 4:46PM (UTC)

@zomars zomars requested review from a team, joeauyeung and sean-brydon and removed request for joeauyeung September 28, 2022 10:36
const [hashedLinkVisible, setHashedLinkVisible] = useState(!!eventType.hashedLink);
const [hashedUrl, setHashedUrl] = useState(eventType.hashedLink?.link);
const [seatsInputVisible, setSeatsInputVisible] = useState(!!eventType.seatsPerTimeSlot);
const [seatsPerTimeSlot, setSeatsPerTimeSlot] = useState(eventType.seatsPerTimeSlot || 2);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When using form, we should not rely on useState as much as possible. We already have a "Form State" we should take advantage of it as much as possible.

<hr />
<Controller
name="seatsPerTimeSlot"
name="seatsPerTimeSlotEnabled"
Copy link
Copy Markdown
Contributor Author

@zomars zomars Sep 28, 2022

Choose a reason for hiding this comment

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

Added a pseudo-field that won't be sent to the backend but will allow us to keep track of this state locally.


const animationRef = useRef(null);
const seatsEnabled = !!eventType.seatsPerTimeSlot;
const seatsEnabled = formMethods.getValues("seatsPerTimeSlotEnabled");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As per my comment above. Use the form as much as possible.

Comment on lines +325 to +332
// Enabling seats will disable guests and requiring confimation until fully supported
if (e) {
formMethods.setValue("disableGuests", true);
formMethods.setValue("requiresConfirmation", false);
formMethods.setValue("seatsPerTimeSlot", 2);
} else {
formMethods.setValue("seatsPerTimeSlot", null);
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here's the actual logic, we don't need to manipulate external state, just the actual form values.

/>
{seatsInputVisible && (
<Controller
name="seatsPerTimeSlot"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The Switch (which is a boolean) was manipulating a number value. This makes it right.

className={classNames(
props.checked ? "bg-gray-900" : "bg-gray-200 hover:bg-gray-300",
props.checked ? "bg-gray-900" : "bg-gray-200",
primitiveProps.disabled ? "cursor-not-allowed" : "hover:bg-gray-300",
Copy link
Copy Markdown
Contributor Author

@zomars zomars Sep 28, 2022

Choose a reason for hiding this comment

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

At least for desktop users, disabled switches will display a "non allowed" cursor. Tried adding opacity as well but it becomes confusing between on-disabled/off-disabled/on-enabled/off-enabled cc @Jaibles any suggestions for mobile users?

Copy link
Copy Markdown
Contributor

@emrysal emrysal left a comment

Choose a reason for hiding this comment

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

I don't really like pseudo-fields, at that point you're better off with state again, which Controller under the hood also does. Minor nit.

@zomars
Copy link
Copy Markdown
Contributor Author

zomars commented Sep 28, 2022

I don't really like pseudo-fields, at that point you're better off with state again, which Controller under the hood also does. Minor nit.

We could make it an actual field and move this logic to the backend tho. "If input. seatsPerTimeSlotEnabled is false then set the seatsPerTimeSlot to null"

@emrysal
Copy link
Copy Markdown
Contributor

emrysal commented Sep 28, 2022

We could make it an actual field and move this logic to the backend tho. "If input. seatsPerTimeSlotEnabled is false then set the seatsPerTimeSlot to null"

I'd say no as it's purely FE logic, if I ask myself "What if I update through the API" that doesn't make sense. But asking myself the same question the following logic does come to mind as belonging to the BE.

// Enabling seats will disable guests and requiring confirmation until fully supported
if (e) {
  formMethods.setValue("disableGuests", true);
  formMethods.setValue("requiresConfirmation", false);
  formMethods.setValue("seatsPerTimeSlot", 2);
} else {
  formMethods.setValue("seatsPerTimeSlot", null);
}

Maybe not as a side-effect but as a guards; e.g. "Requiring confirmation is not possible during events with multiple seats." or "Unable to disable guests as this event has multiple seats".

@emrysal emrysal enabled auto-merge (squash) September 29, 2022 16:29
@emrysal emrysal added ♻️ autoupdate tells kodiak to keep this branch up-to-date automerge labels Sep 29, 2022
@emrysal emrysal merged commit d2f27a0 into main Sep 29, 2022
@emrysal emrysal deleted the fixes/eventtype-advanced-form-logic branch September 29, 2022 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge ♻️ autoupdate tells kodiak to keep this branch up-to-date

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants