The user will have to approve 2 tx on Metamask the approval of the transfer and the solidity contract call. The approval must happen before calling the solidity function.
Using the ethers library as example this code migth better ilustrate the path you must follow:
const factory = await new ethers.Contract(tokenAddress, tokenAbi, provider);
const erc20 = await factory.attach(tokenAddress); //This will prompt the approval transaction to be approve
Then the solidity call to your contract, if you receive the transfer amount and the token address, if you will always use the same erc20 you could avoid sending the address:
await contract.connect(signer).deposit(depositamount, tokenAddress);
and your function must look something like this:
function deposit(uint _amount, address _token) external {
IERC20 depositor = IERC20(_token);
depositor.transferFrom(msg.sender, address(this), _amount);
}
Hope all these helps!