refactor: simplify protocol handling in MonitorForm by deriving protocol directly from formData.url

This commit is contained in:
Usman Baig
2026-02-07 23:09:37 +01:00
parent 0887e24546
commit 8424863a18

View File

@@ -868,10 +868,8 @@ function MonitorForm({
submitLabel: string
siteDomain: string
}) {
const [protocol, setProtocol] = useState<'https://' | 'http://'>(() => {
if (formData.url.startsWith('http://')) return 'http://'
return 'https://'
})
// * Derive protocol from formData.url so edit modal shows the monitor's actual scheme (no desync)
const protocol: 'https://' | 'http://' = formData.url.startsWith('http://') ? 'http://' : 'https://'
const [showProtocolDropdown, setShowProtocolDropdown] = useState(false)
const dropdownRef = useRef<HTMLDivElement>(null)
@@ -898,9 +896,7 @@ function MonitorForm({
}
const handleProtocolChange = (proto: 'https://' | 'http://') => {
setProtocol(proto)
setShowProtocolDropdown(false)
// * Rebuild URL with new protocol
const path = getPath()
setFormData({ ...formData, url: `${proto}${siteDomain}${path}` })
}