diff --git a/src/components/BuyServices/NewKubernetisUtho.jsx b/src/components/BuyServices/NewKubernetisUtho.jsx
index b4611e9..c7e57a8 100644
--- a/src/components/BuyServices/NewKubernetisUtho.jsx
+++ b/src/components/BuyServices/NewKubernetisUtho.jsx
@@ -1,21 +1,27 @@
-import React, { useState, useEffect } from "react";
+import React, { useState } from "react";
import { Button } from '../ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui/card";
import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from "../ui/select";
import { Input } from "../ui/input";
import { Label } from "../ui/label";
-import Loader from "../ui/loader";
import { useToast } from "../ui/toast";
import { useIsLoggedIn } from '../../lib/isLoggedIn';
-
+import Loader from "../ui/loader";
export default function Kubernetes() {
- const { isLoggedIn, loading, balance } = useIsLoggedIn();
+ // Environment variables and hooks
+ const PUBLIC_DEPLOYMENT_CHANEL_1_URL = import.meta.env.PUBLIC_DEPLOYMENT_CHANEL_1_URL;
+ const { loading, isLoggedIn, balance } = useIsLoggedIn();
const { showToast } = useToast();
+
+ // State management
const [isLoading, setIsLoading] = useState(false);
const [deployError, setDeployError] = useState(null);
const [deployStatus, setDeployStatus] = useState({});
- const [clusterStatus, setClusterStatus] = useState('');
- const [productAmount, setProductAmount] = useState(100);
+ const [productAmount] = useState(100);
+ const [copied, setCopied] = useState(false);
+ const [downloadClusterId, setDownloadClusterId] = useState('');
+
+ // Form states
const [nodePools, setNodePools] = useState([{
label: `${getRandomString()}`,
size: '10215',
@@ -28,7 +34,7 @@ export default function Kubernetes() {
cluster_label: `${getRandomString()}`,
});
- // Generate random string for IDs
+ // Helper functions
function getRandomString(length = 8) {
return Math.random().toString(36).substring(2, length+2);
}
@@ -40,58 +46,8 @@ export default function Kubernetes() {
{ id: '10218', name: '16 vCPU, 32GB RAM' }
];
- // Check cluster status periodically after deployment
- useEffect(() => {
- if (!deployStatus.clusterId || deployStatus.isReady) return;
-
- const checkStatus = async () => {
- try {
- const response = await fetch(
- `https://host-api.cs1.hz.siliconpin.com/v1/kubernetis/?query=status&clusterId=${deployStatus.clusterId}&source=chanel_1`,
- { credentials: "include" }
- );
-
- if (!response.ok) throw new Error("Failed to check status");
-
- const data = await response.json();
-
- // Update status
- setClusterStatus(data.status || 'pending');
-
- if (data.status === 'active') {
- // Cluster is ready for configuration download
- setDeployStatus(prev => ({ ...prev, isReady: true }));
- showToast({
- title: "Cluster Ready",
- description: "Your Kubernetes cluster is now fully configured.",
- variant: "default"
- });
- return; // Stop checking when ready
- } else if (data.status === 'failed') {
- throw new Error("Cluster deployment failed");
- }
-
- // Continue checking every 20 seconds if not ready
- setTimeout(checkStatus, 20000);
- } catch (error) {
- console.error("Status check error:", error);
- // Retry after delay if not a fatal error
- if (!error.message.includes('failed')) {
- setTimeout(checkStatus, 30000);
- } else {
- setDeployError(error.message);
- }
- }
- };
-
- const timer = setTimeout(checkStatus, 15000);
- return () => clearTimeout(timer);
- }, [deployStatus.clusterId, deployStatus.isReady]);
-
const handleSubmit = async (e) => {
- if(balance < productAmount){
- return;
- }
+ if (balance < productAmount) return;
e.preventDefault();
setIsLoading(true);
setDeployError(null);
@@ -114,7 +70,7 @@ export default function Kubernetes() {
};
const response = await fetch(
- "https://host-api.cs1.hz.siliconpin.com/v1/kubernetis/?query=deploy&source=chanel_1",
+ `${PUBLIC_DEPLOYMENT_CHANEL_1_URL}kubernetis/?query=deploy&source=chanel_1`,
{
method: "POST",
credentials: "include",
@@ -130,13 +86,11 @@ export default function Kubernetes() {
if (data.status === "success") {
setDeployStatus({
status: "success",
- clusterId: data.clusterId,
- endpoint: data.endpoint,
- isReady: false
+ clusterId: data.id
});
showToast({
- title: "Deployment Started",
- description: "Your cluster is being provisioned. This may take 10-15 minutes.",
+ title: "Deployment Successful",
+ description: "Your cluster is being provisioned.",
variant: "default"
});
} else {
@@ -154,22 +108,26 @@ export default function Kubernetes() {
}
};
- const downloadKubeConfig = async () => {
- if (!deployStatus.clusterId) return;
-
- try {
- // Trigger download via backend
- window.open(
- `https://host-api.cs1.hz.siliconpin.com/v1/kubernetis/?query=download&clusterId=${deployStatus.clusterId}&source=chanel_1`,
- '_blank'
- );
- } catch (error) {
+ const downloadKubeConfig = (clusterId) => {
+ if (!clusterId) {
showToast({
- title: "Download Failed",
- description: "Could not download configuration. Please try again.",
+ title: "Cluster ID Required",
+ description: "Please enter a valid Cluster ID",
variant: "destructive"
});
+ return;
}
+
+ window.open(
+ `${PUBLIC_DEPLOYMENT_CHANEL_1_URL}kubernetis/?query=download&clusterId=${clusterId}&source=chanel_1`,
+ '_blank'
+ );
+ };
+
+ const handleCopy = (text) => {
+ navigator.clipboard.writeText(text);
+ setCopied(true);
+ setTimeout(() => setCopied(false), 1000);
};
// Form field handlers
@@ -220,11 +178,9 @@ export default function Kubernetes() {
setNodePools(updatedPools);
}
};
-
if (loading) {
return
@@ -235,248 +191,231 @@ export default function Kubernetes() { if (balance < productAmount) { return ( -
- You have insufficient balance to deploy this service. Please click here to go to your profile and add balance, then try again.
- ); - } - - if (deployStatus.status === 'success') { - return ( -- This process may take several minutes. Please don't close this page. -
- )} -- {deployStatus.clusterId} -
-- {deployStatus.endpoint || 'Pending...'} -
-+ You have insufficient balance to deploy this service. Please click here to add balance. +
); } return ( -