There's a fast activating gate that opens quickly in response to membrane depolarization and there's a slow inactivating gate that closes slowly in response to membrane depolarization. NOTE: The stimulus for both gates is the same thing, membrane depolarization. Both gates need to be open for Na+ influx to occur.
So, when membrane potential is depolarized to threshold, the fast activating gate opens. At this time, since the slow inactivating gate still hasn't closed (since it's slow...duh!), both the gates are open, and Na+ flows into the cell to cause the upstroke of the action potential. Once the slow inactivating gate closes (after a time delay), the influx of Na+ ends and the upstroke of the action potential ends. On the action potential chart, this is the peak of the action potential. There's no more Na+ influx. The repolarization phase now begins.
Hope this helps.