Structuring reusable form components for multiple users

This is more of a general design question, but I’d like to see what you guys think about it.

Currently I have two user types, A and B.

Whenever A or B logins into the site, there’s the standard hamburger button with a sidebar that displays its child elements X, Y, and Z.

X and Y are common to both A and B, but Z is exclusive to A.

Should I create one big “master” form that contains all the elements, X, Y, and Z, and conditionally shows them by checking for the user types? Or should I create separate forms per user type?

“It’s tough to make predictions, especially about the future.”

― Yogi Berra

I suspect it depends on how you foresee the two evolving. Right now they diverge by one item.

If they’re going to grow further and further apart, then it makes sense to have two separate Forms. (They can still share code, in a variety of ways.)

If they’re intended to have only this one difference, forever, even as the requirements grow and change, then it makes sense to have one Form, with a part that is shown/added/removed/hidden dynamically.

6 Likes

Agreed. I know how things change so it’s probably worth it to just have two separate forms completely and don’t even worry about sharing code.

You can still get the best of both worlds. Common code can often be moved to separate modules, and invoked by as many different forms as needed.