We define work as the product of force on a body and its displacement. In Figure 1 a body undergoes a displacement of $ {\Delta \vec s} = {\vec s _f} - {\vec s _i}$ towards positive x-direction under the action of a constant force ${\vec F}$. But in Figure 2 the body undergoes a displacement of $\Delta \vec s = \vec s_f - \vec s_i$ under the action of a constant force $\vec F$ which makes an angle $\beta$ with the displacement. If $W$ is the work done, we have

\[W = {\vec F} \cdot {\Delta \vec s} \tag{1} \label{1}\]

Note that both ${\vec F}$ and $ {\Delta \vec s} $ are vectors but the work is a scalar quantity, so the work done is a dot (scalar) product of ${\vec F}$ and $ {\Delta \vec s} $. Therefore,

\[W = {F}\Delta s\cos \beta \label{2} \tag{2}\]

Note that friction always does a negative work as it always applies a force in opposite direction of displacement. The friction which does negative work is always kinetic friction. If you consider the friction between the surfaces of the box and the floor, the work done by the constant force $\vec F$ is the maximum work done which is $W_\text{max} = F\Delta s \cos \beta$. The work done by the kinetic friction is $W_k = f_k\Delta s \cos 180 = -f_k\Delta s$. Therefore, the total work done is $W_\text{total} = F\Delta s \cos \beta - f_k\Delta s$ which is the same as the work done by the resultant force. The resultant force is the result of the sum of all forces on a body.

One interesting thing in Figure 2 is that the force $\vec F$ has two components $\vec F_x$ and $\vec F_y$. The sum of the y-component $\vec F_y$ and the normal force is balanced by the weight of the body and hence the normal force decreases. Therefore the kinetic friction decreases due to the y-component of the force $\vec F$. In this case the work is done by the x-component $\vec F_x$ only. Obviously the friction plays negative role here. The unit of work is Joule denoted by J which is $kg \cdot {m^2}/{s^2}$.

If the force is not always constant or the displacement is not always along a straight line, we find the small work through an infinitesimally small displacement (infinitesimally small distance has can be considered as displacement as it has a particular direction) in which the force can be considered as constant. Then we integrate to find the total work done along the whole path. If $dW$ is the small work done by the force $\vec F $ along an infinitesimal displacement $ds$, then the total work done is,

\[W = \int {dW} = \int {Fds\cos \beta } \tag{3}\]

where $\beta$ is the angle between the force and the displacement.