According to the first and second law for a closed system containing different chemicals we have
\begin{align} &\delta Q - \delta W = dU = T dS - p dV +\sum_i \mu_i d N_i\\ &\Rightarrow\;\delta W - p dV + \sum_i \mu_i dN_i = \delta Q - T d S \le 0\qquad\because\text{2nd law}\\ &\Rightarrow\;\delta W - p dV + dG\bigr|_{p,T} \le 0\\ &\Rightarrow\;\delta W - p dV \le -dG\bigr|_{p,T}\\ \end{align}
If $\delta W = p dV$ then $dG\bigr|_{p,T}\le 0$, that is, the condition $dG\bigr|_{p,T}\le 0$ coincides with the second law only if the only work done by the system is the pressure work and no other kind.
In addition, if $\delta W = p dV + \text{``other works"}$, then $\text{``other works"}\le -dG\bigr|_{p,T}$. This means the change in the "minus Gibbs function" is the maximum work attainable from the system beside the pressure work. This extra work can be positive or negative, in the form of electric work, friction work etc.
Therefore, it is clear that:
A system cannot at the same be derived by $dG\bigr|_{p,T}\le 0$ and does e.g. an electric work $\delta W_{Electric}$;
If the system does have a $\delta W_{Electric}$ then its maximum value would be equal to $dG\bigr|_{p,T}$ but if so, then the process is already assumed reversible and all the inequalities should be substituted by equalities.
However, according to this Mc Graw-Hill link during a spontaneous reduction-oxidation chemical reaction the Gibbs Free Enthalpy must decrease and at the same time the change in the Gibbs Free Enthalpy is the maximum electric work that the reaction can do: $$\Delta G = W_{max}\le 0$$ I cannot understand this and have a number of problems with this derivation:
First of all, the maximum work that a system can do on its surrounding equals minus the change of the Gibbs Free Enthalpy, so the equality $\Delta G = W_{max}$ doesn't hold?
If the work has attained its maximum value, then the process must be assumed as reversible, but the inequality in the formula above holds for irreversible processes!
If there is an Electric work done by the system then decreasing Gibbs free energy is no longer necessary due to the second law?
When both the donor and acceptor of electron in the chemical reaction lay inside the system the electric work will nowhere enter the formulation as the electric work is an internal work that does not crosses the boundary of the system!? But the whole formulation is here to study $W_{electric}$ in the system as spontaneity of the reaction should be related to the electromotive force of the reaction which has a chance to appear in $W_{electric}$ only! So what should be taken as system here?
Hint. In the books on thermodynamics that I have seen that discuss the electric works they are usually dealing with the problem of Electrochemical cells. But electrochemical cells work in an outer electric circuit and so if one assume the cell as the closed system yet the electric work will enter the discussion. Only one book was talking about open-circuit Emf but again I have the problems listed above with that as well.
[I have asked the same question at the Chemistry.SE herehere but have not been convinced with the single answer given there.]