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