When someone does "the right thing", it means that they do what is honest or morally right. For example, you can tell someone that they "did the right thing" in situations like:
- a student reports some dangerous behavior by another student to their teacher
- someone found a missing wallet and returned it to the owner
This is different from telling someone that they were "right", which means "correct":
You were right. It's scheduled for Monday, not Tuesday.
To mention which action was "the right thing", you can say "by ___ing":
You did the right thing by coming to me.