AI-Assisted Coding · Module 3Lesson 4

Study explanation · Lesson 04 · 13 min

The create/edit modal

Part 3.3 adds a New Task button and Edit buttons that open one modal in two modes. It trims titles before sending anything, uses POST or PATCH, keeps the modal open on a 422, and clears itself on every way out.

Listen to this lesson

Hear the lesson read aloud, with each sentence highlighted as you go.

Narrated by an AI voice.

Where convenience meets the rules

The modal is the place a user types data the backend will judge. It should make creating and editing easy, but it must not paper over what the server decides. The instructor’s method here is focused selected edits: select the form or the submit handler and ask the assistant to change only that section, not to rewrite the file.

Key ideaThe modal is where frontend convenience meets backend rules. It should make creation and editing easy without bypassing validation.

What the modal contains

Six elements. Note that every way of dismissing the modal also clears stale form state.

Modal elements · Lecture notes p. 8
ElementPurpose
New Task buttonOpens the modal in create mode with empty/default values.
Edit button on each cardOpens the modal in edit mode and fills the form from the selected task.
FieldsTitle, description, status, priority, assignee, and a hidden or internal task id for edit mode.
Save actionUses POST /tasks for create mode and PATCH /tasks/{id} for edit mode.
Cancel, close button, Escape, and overlay clickDismiss the modal and clear stale form state.
Error displayShows client validation errors and server 422 messages without pretending the save succeeded.

Create mode and edit mode

One modal, two modes, told apart by whether a task id is known.

Create mode vs. edit mode · Lecture notes p. 8
Create modeEdit mode
No existing task id. The form starts with defaults such as ToDo and Medium unless the UI chooses different defaults.Existing task id is known. The form is prefilled with the current task values.
Submit sends POST /tasks with the new task payload.Submit sends PATCH /tasks/{id} with updated fields.
On success, the board refreshes and the new card appears in the correct column and priority slot.On success, the board refreshes and the edited card moves or reorders if status or priority changed.
If title is empty after trim, no network request should be sent.If the backend rejects an invalid transition, the modal stays open and shows the server message.

Validation rules to preserve

The client checks what it can check cheaply, and the server has the final word. Prompt C2 adds two concrete choices: show “Title is required” for an empty title, and send an empty description as an empty string.

  • Client-side title validation: trim whitespace before checking whether the title is empty.
  • Do not send a request when the title is empty or whitespace-only.
  • Empty assignee can be sent as null if the backend expects optional assignee data.
  • Server-side 422 responses should keep the modal open and show a useful message.
  • A successful create or edit should clear errors, close the modal, and refresh the board.

Read with careThe notes do not say which status code a successful create returns; prompt C2 handles “200/201”. Check what your Module 2 POST route actually returns, and treat both as success only if that matches.

Five flows to verify

Run each flow in the browser with DevTools open. Flow 1 is checked in the Network tab by what does not appear: no request at all.

Five flows to verify · Lecture notes p. 9
FlowExpected behavior
1. Empty titleSubmit with an empty or whitespace-only title. No request fires, and the title error is visible.
2. Create taskCreate a High-priority ToDo task. POST succeeds, and the card appears in the ToDo column above lower-priority cards.
3. Edit taskChange priority or status. PATCH succeeds, and the card reorders or moves to the correct column.
4. Invalid transitionTry a backend-rejected status change. PATCH returns 422, the modal stays open, and the server message is visible.
5. DismissalCancel, X/close, Escape, and overlay click all close the modal and clear stale values or errors.

Debug a failing form from evidence

When a flow fails, “it does not work” gives the assistant nothing to reason with. Collect the action you took, the request’s method and URL, the status code, the response body and what the UI showed, then select the submit handler or close logic and ask for the smallest focused edit. Prompt C3 is that structure, with three constraints worth keeping: do not rewrite the file, do not weaken backend rules, and do not close the modal on a 422 invalid-transition response.

  • The action: what you clicked or typed, exactly.
  • The request: method, URL, status code and response body from the Network tab.
  • The UI: what the screen showed, compared with what it should have shown.
  • The code: the selected submit handler or modal-close logic, not the whole file.

Key ideaEvidence makes the AI more useful and keeps you in control.

Key takeaways

  • One modal, two modes: POST without an id, PATCH with one.
  • Trim the title before checking it, and send nothing if it is empty.
  • A 422 keeps the modal open with the server’s message; success clears, closes and refreshes.
  • All four ways out of the modal clear stale values and errors.
  • Debug with action, request, status, body and UI, not “it does not work”.

Built from the Module 3 lecture notes, prompt library and additional readings; the module videos and slides were not supplied.

Your study checkpoint

Ready to continue?

Mark the lesson complete once you have read it and tried its idea on something real.

Next · Lesson 5