Morphology and star formation in IllustrisTNG: the build-up of spheroids and discs