From f9d1556ce9bd966399caea2f3e414bb5f89272dd Mon Sep 17 00:00:00 2001 From: Arkadyuti Sarkar Date: Fri, 28 Mar 2025 16:48:41 +0530 Subject: [PATCH] added api --- src/components/DomainSetupForm.jsx | 50 +++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/components/DomainSetupForm.jsx b/src/components/DomainSetupForm.jsx index 4632a98..5cbc171 100644 --- a/src/components/DomainSetupForm.jsx +++ b/src/components/DomainSetupForm.jsx @@ -187,23 +187,45 @@ export const DomainSetupForm = ({ defaultSubdomain }) => { setValidationMessage(''); setShowDnsConfig(false); - // Simulate an API call to validate the domain - setTimeout(() => { - // Simulate a real domain check - in a real app this would be an API call - const checkResult = true; // Assume domain is valid for demo + fetch('/validate-domain', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + domain, + type: domainType + }) + }) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then(data => { + const checkResult = data.status === "success"; + console.log("finding:: checkResult:: ", checkResult, data); - setIsValidating(false); - setIsValidDomain(checkResult); + setIsValidating(false); + setIsValidDomain(checkResult); - if (checkResult) { - setValidationMessage('Domain is valid and registered.'); - setShowDnsConfig(true); - } else { - setValidationMessage('Domain appears to be unregistered or unavailable.'); - } + if (checkResult) { + setValidationMessage('Domain is valid and registered.'); + setShowDnsConfig(true); + } else { + setValidationMessage('Domain appears to be unregistered or unavailable.'); + } - validateForm(); - }, 1500); + validateForm(); + }) + .catch(error => { + console.error('Error validating domain:', error); + setIsValidating(false); + setIsValidDomain(false); + setValidationMessage('Error checking domain. Please try again.'); + validateForm(); + }); }; // Check DNS configuration