The use of commas in direct speech

There should be a comma, full stop, question mark, or exclamation mark at the end of a piece of speech. This is placed inside the closing inverted comma or commas.

‘Can I come in?’ he asked.
‘Just a moment!’ she shouted.
‘You’re right,’ he said.
‚I didn’t expect to win.‘

If direct speech comes after the information about who is speaking, you should use a comma to introduce the piece of speech, placed before the first inverted comma:

Steve replied, ‘No problem.’

If the direct speech is broken up by information about who is speaking, you need a comma (or a question mark or exclamation mark) to end the first piece of speech and a full stop or another comma before the second piece (before the inverted comma or commas):

‘You’re right,’ he said. ‘It feels strange.’
‘Thinking back,’ she said, ‘he didn’t expect to win.’
‘No!’ he cried. ‘You can’t leave now!’

from: https://en.oxforddictionaries.com/punctuation/punctuation-in-direct-speech