Problem statement
A studio booking form that has to be checked before it is sent, whose values have to be tidied up into a clean payload with the right kinds of data, and that has to actually send that payload to a booking service the environment provides. If the service says the booking went through, show the reference it returns. If the service says no, let the person try again with what they had already typed still in the form.
Demo
The page, styles, form markup, message spots, submit button, error banner and confirmation banner are already scaffolded and wired. A booking service is provided for you by the environment — you only need to call it. Only the validate function in src/js/validation.ts, the buildPayload function in src/js/payload.ts, and the renderFieldError, renderFormDisabled, renderSubmitError and renderConfirmation functions in src/js/render.ts are missing — implement them so every test passes. Do not edit any other file.
What to implement
- When the person tries to submit, show a short reminder next to any field that is empty or wrong, and do not send the booking at all until every field is fine.
- When every field is fine, tidy the typed values into a clean payload — no extra spaces around text, numbers as actual numbers rather than text, and the chosen date as a plain date.
- Send that clean payload to the booking service exactly once per submit — never twice for the same click.
- While the booking service is thinking, switch off the whole form so nothing can be edited or resubmitted mid-flight.
- When the booking service comes back with a yes, show a confirmation banner with the reference it gave back.
- When the booking service comes back with a no, show a red banner with the reason it gave, switch the form back on, and leave every value the person typed exactly where it was.
- Everything shown must come from the values the person typed and from what the booking service returns — nothing should be hardcoded.
