The cumulative star formation histories of dwarf galaxies with TNG50. I: Environment-driven diversity and connection to quenching