Dry-hopping in primary is fine. Many people don't rack to a secondary fermentation vessel anymore unless they're actually adding additional fermentables. In fact, dry-hopping before primary-fermentation is complete (even at high krausen) is sometimes recommended.
In terms of timing I've seen many different recommendations, generally in reference to time before packaging (bottling or kegging). Somewhere between 3 to 7 days before packaging seems pretty normal. Some people fear that dry-hopping for longer (7+ days) can contribute to a grassy flavor in the final beer and err on the shorter side.
In a Brulosophy exBEERiment they tested the differences between short- and long-dry-hopped beers and found that though there seemed to be noticeable differences it was more a matter of preference than anything. Maybe the results there can give you some hints as to how you might want to go based on what you want out of your beer.