I can connect the phone to Wi-FI manually, but after several minutes, it loses the connection, and I have to restore it manually. This did not happen before I installed iOS 12.
Before doing anything, have you erased network settings and verified WiFi is stable?
Next, erase all content and settings and retest on a new network.
Apple typically stops signing the previous release within a week of a new iOS, so you could try restoring back to iOS 11 to rule out a hardware failure that was a coincidence. At that point you can decide to see Apple service before upgrading to understand if you have any recourse from them in case a second upgrade also fails.
Many many iPhone 7 era devices work fine, so it’s almost certainly not a widespread bug. If you’re sure you want iOS 12 I would erase and restore the device and then connect to a Mac to look over the system logs if the failure continues.