In this episode, we dive into creating the "Edit Team" functionality, giving users the ability to update their team's name. Here's how we tackle it step by step:
We start out by setting up the edit route and hooking up the navigation to point to our new team settings page. Then, in the controller, we pull in the current team for the user and return a view for editing. For the front end, we reuse some of the design from the profile edit page to keep things consistent and efficient, then swap out the necessary bits to make it team-specific.
Next, we wire up the actual form to update the team name, handling the PATCH request in the controller. We make sure this is all connected with route model binding so that updating the team details works as expected. To make sure everything's locked down, we implement authorization so only users in the team can make changes. We add this check via a policy and confirm it with a couple of tests—one for when a user is allowed to update, and another for when they're not.
Speaking of tests, we add simple ones to make sure everything is working as intended: the right users can update, unauthorized users can't, and the team name changes as expected in the database. Lastly, we tighten things up with validation, making sure the team name is actually provided and doesn't exceed the maximum length.
By the end of this video, you'll have a fully working "Edit Team Name" form, complete with view, controller logic, policy-based authorization, validation, and tests to cover the basics!