Watching it again, I think I understand what went wrong with the plan and it started at the very beginning with the Dothraki. I think they were meant to protect the artillery while the trebuchets thinned the herd. But then the Red Woman comes along and gives them flaming swords. Dothraki are already pretty confident, set their swords on fire and they suddenly feel invincible. So they charge ahead while everyone else is still trying to figure out what's going on.
Daenerys sees her bloodriders slaughtered and abandons her post (she and Jon were supposed to wait for the Night King). Jon tries to stop her, saying "the Night King is coming." She responds with "the dead are already here!" and mounts her dragon. Once airborne she is unable to see the signals from the castle walls to light the trenches, forcing the Unsullied out into the open to protect the Red Woman as she attempts to ignite the trenches manually. It works, but it seems that the disruption to the plan has stunned the troops and they fail to take advantage of the opportunity before the wights start throwing themselves into the flames. It's not until Davos sees them begin to get through that he gives the order to "man the walls". Had he done this sooner their archers would've been much more effective against the stationary targets.
Meanwhile, Jon is steadfast in holding his position when he could be strafing the undead army with close air support. Ironically it seems he is the only one sticking to the original plan and it probably cost them dearly. Instead, the undead breach the walls the Soviet way: by throwing bodies at it and an undead giant breaches the poorly defended main gate. Even with Lady Mormont's heroic sacrifice to neutralize the giant, the damage is done and chaos reigns.
The moral of the story? Never trust a Dothraki Bloodrider with a flaming sword to play defense.