Wiring Bathroom Fan Switch
No way from here to know which wire fed the light or fan, but you have a continuous hot feed into the box that fed the receptacle, light and fan. The third wire, maybe it fed the fan or maybe something something else farther down the line, if the latter that needs to be tied in 100 percent to the hot feed. All whites still tied together, blacks to the dimmer from the light and hot. All grounds tied together set with a screw to the metal box. Securing the ground to the box is not needed if the box is plastic.

Before I got too wordy, here is a sketch



Still have to learn to format better

The sketch is a little rough, it should get the idea across I hope