diff --git a/src/layout/DashboardLayout.tsx b/src/layout/DashboardLayout.tsx
index e62f65c..59a63b5 100644
--- a/src/layout/DashboardLayout.tsx
+++ b/src/layout/DashboardLayout.tsx
@@ -47,7 +47,7 @@ export default function DashboardLayout() {
}
>
- Create Cluster
+ List Cluster
diff --git a/src/pages/CreateCluster.tsx b/src/pages/CreateCluster.tsx
index 132cb4e..a952c74 100644
--- a/src/pages/CreateCluster.tsx
+++ b/src/pages/CreateCluster.tsx
@@ -1,11 +1,15 @@
import { useState } from 'react'
import { Link } from 'react-router-dom'
-import { Download, Trash2 } from 'lucide-react'
+import { Download, Feather, Trash2 } from 'lucide-react'
import type { FormEvent } from 'react'
interface Cluster {
id: string
- name: string
+ Name: string
+ ControlPlane: string
+ PlatformVersion: string
+ Cpu: string
+ Memory: string
clusterId: string
status: string
version: string
@@ -15,15 +19,30 @@ interface Cluster {
export default function CreateCluster() {
const [clusters, setClusters] = useState(() => {
+ fetch('http://localhost:8082/clusters', {
+ method: 'GET',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `${localStorage.getItem('auth:token') || ''}`
+ },
+ }).then(async (res) => {
+ if (res.ok) {
+ const data = await res.json()
+ setClusters(data.clusters || [])
+ return data.clusters || []
+ //localStorage.setItem('clusters', JSON.stringify(data.clusters || []))
+ } else {
+ const data = await res.json()
+ console.error(data.message || 'Failed to fetch clusters')
+ }
+ }).catch(() => {
+ console.error('Failed to fetch clusters')
+ })
const saved = localStorage.getItem('clusters')
if (saved) {
return JSON.parse(saved)
}
- return [
- { id: '1', name: 'dev-cluster', clusterId: '680d172c', status: 'Healthy', version: 'v1.28.0', alerts: '0', endpoint: 'https://dev-cluster.example.com' },
- { id: '2', name: 'prod-cluster', clusterId: 'd02b06fe', status: 'Healthy', version: 'v1.28.0', alerts: '0', endpoint: 'https://prod-cluster.example.com' },
- { id: '3', name: 'test-prod', clusterId: '937261be', status: 'Healthy', version: 'v1.28.0', alerts: '0', endpoint: 'https://test-prod.example.com' },
- ]
+ return []
})
const [showModal, setShowModal] = useState(false)
@@ -32,34 +51,51 @@ export default function CreateCluster() {
namespace: '',
controlPlane: 'Kubernetes (k8s)',
kubernetesVersion: 'v1.31.6 (recommended)',
- cpu: 1,
- memory: 2048
+ Cpu: 1,
+ Memory: 1024
})
const handleSubmit = (e: FormEvent) => {
e.preventDefault()
- const newCluster: Cluster = {
- id: Date.now().toString(),
- name: formData.clusterName,
+ const newCluster: Cluster = {
+ Name: formData.clusterName,
clusterId: Math.random().toString(36).substr(2, 8),
status: 'Creating',
- version: formData.kubernetesVersion.split(' ')[0],
- alerts: '0',
- endpoint: `https://${formData.clusterName}.example.com`
- }
+ ControlPlane: formData.controlPlane,
+ Cpu: formData.Cpu.toString(),
+ Memory: formData.Memory.toString(),
+ PlatformVersion: formData.kubernetesVersion.split(' ')[0]
+ }
- const updatedClusters = [...clusters, newCluster]
- setClusters(updatedClusters)
- localStorage.setItem('clusters', JSON.stringify(updatedClusters))
- setShowModal(false)
- setFormData({
- clusterName: '',
- namespace: '',
- controlPlane: 'Kubernetes (k8s)',
- kubernetesVersion: 'v1.31.6 (recommended)',
- cpu: 1,
- memory: 2048
- })
+ fetch('http://localhost:8082/createcluster', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json', 'Authorization': localStorage.getItem('auth:token') || '' },
+ body: JSON.stringify(newCluster),
+ }).then(async (res) => {
+ if (res.ok) {
+ const data = await res.json()
+ console.log(data)
+ } else {
+ const data = await res.json()
+ console.log(data)
+ // setError(data.message || 'Login failed')
+ }
+ }).catch(() => {
+ //setError('Login failed')
+ })
+
+ // const updatedClusters = [...clusters, newCluster]
+ // setClusters(updatedClusters)
+ // localStorage.setItem('clusters', JSON.stringify(updatedClusters))
+ // setShowModal(false)
+ // setFormData({
+ // clusterName: '',
+ // namespace: '',
+ // controlPlane: 'Kubernetes (k8s)',
+ // kubernetesVersion: 'v1.31.6 (recommended)',
+ // Cpu: 1,
+ // Memory: 2048
+ // })
}
const downloadKubeconfig = (clusterId: string) => {
@@ -138,7 +174,7 @@ users:
to={`/app/clusters/${cluster.id}`}
className="text-sm font-medium text-blue-600 hover:text-blue-900"
>
- {cluster.name}
+ {cluster.Name}
| {cluster.clusterId} |
@@ -202,18 +238,7 @@ users:
required
/>
-
-
- setFormData({...formData, namespace: e.target.value})}
- className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
- required
- />
-
+
@@ -256,14 +281,14 @@ users:
diff --git a/src/pages/Login.tsx b/src/pages/Login.tsx
index 0a40f6c..344d643 100644
--- a/src/pages/Login.tsx
+++ b/src/pages/Login.tsx
@@ -5,22 +5,38 @@ import Button from '../components/ui/button'
export default function Login() {
const navigate = useNavigate()
- const [email, setEmail] = useState('')
+ const [username, setusername] = useState('')
const [password, setPassword] = useState('')
const [error, setError] = useState(null)
function onSubmit(e: FormEvent) {
e.preventDefault()
setError(null)
- const usersString = localStorage.getItem('auth:users')
- const users: Array<{ email: string; password: string }> = usersString ? JSON.parse(usersString) : []
- const match = users.find((u) => u.email === email && u.password === password)
- if (!match) {
- setError('Invalid credentials')
- return
- }
- localStorage.setItem('auth:user', JSON.stringify({ email }))
- navigate('/app')
+
+ fetch('http://localhost:8082/login', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ username, password }),
+ }).then(async (res) => {
+ if (res.ok) {
+ const data = await res.json()
+ localStorage.setItem('auth:token', data.token)
+ navigate('/app')
+ } else {
+ const data = await res.json()
+ setError(data.message || 'Login failed')
+ }
+ }).catch(() => {
+ setError('Login failed')
+ })
+ // const usersString = localStorage.getItem('auth:users')
+ // const users: Array<{ username: string; password: string }> = usersString ? JSON.parse(usersString) : []
+ // const match = users.find((u) => u.username === username && u.password === password)
+ // if (!match) {
+ // setError('Invalid credentials')
+ // return
+ // }
+ // localStorage.setItem('auth:user', JSON.stringify({ username }))
}
return (
@@ -29,13 +45,13 @@ export default function Login() {
Login