|
| 1 | +'use client' |
| 2 | + |
| 3 | +import { useState } from 'react' |
| 4 | +import { Radio, RadioGroup } from '@headlessui/react' |
| 5 | +import { CheckCircleIcon } from '@heroicons/react/20/solid' |
| 6 | + |
| 7 | +const container_registry_lists = [ |
| 8 | + { |
| 9 | + id: 1, |
| 10 | + registry_name: 'docker hub', |
| 11 | + registry_slug: 'docker-hub', |
| 12 | + registry_description: 'Public container registry by Docker' |
| 13 | + }, |
| 14 | + { |
| 15 | + id: 2, |
| 16 | + registry_name: 'azure acr', |
| 17 | + registry_slug: 'azure-acr', |
| 18 | + registry_description: 'Azure Container Registry by Microsoft' |
| 19 | + }, |
| 20 | + { |
| 21 | + id: 3, |
| 22 | + registry_name: 'aws ecr', |
| 23 | + registry_slug: 'aws-ecr', |
| 24 | + registry_description: 'Amazon Elastic Container Registry by AWS' |
| 25 | + } |
| 26 | +]; |
| 27 | + |
| 28 | +export default function TheRegistry(): JSX.Element { |
| 29 | + const [selectedRegistry, setSelectedRegistry] = useState(container_registry_lists[0]) |
| 30 | + const [dockerHubToken, setDockerHubToken] = useState('') |
| 31 | + const [awsPublicKey, setAwsPublicKey] = useState('') |
| 32 | + const [awsSecretKey, setAwsSecretKey] = useState('') |
| 33 | + const [acrUsername, setAcrUsername] = useState('') |
| 34 | + const [acrPassword, setAcrPassword] = useState('') |
| 35 | + |
| 36 | + const handleSave = () => { |
| 37 | + const registryData = { |
| 38 | + registry: selectedRegistry, |
| 39 | + credentials: {} |
| 40 | + } |
| 41 | + |
| 42 | + if (selectedRegistry.registry_slug === 'docker-hub') { |
| 43 | + registryData.credentials = { token: dockerHubToken } |
| 44 | + } else if (selectedRegistry.registry_slug === 'aws-ecr') { |
| 45 | + registryData.credentials = { publicKey: awsPublicKey, secretKey: awsSecretKey } |
| 46 | + } else if (selectedRegistry.registry_slug === 'azure-acr') { |
| 47 | + registryData.credentials = { username: acrUsername, password: acrPassword } |
| 48 | + } |
| 49 | + |
| 50 | + console.log('Saved registry data:', registryData) |
| 51 | + // Here you can send `registryData` to your backend or handle it as needed. |
| 52 | + } |
| 53 | + |
| 54 | + return ( |
| 55 | + <div className="flex bg-white shadow mt-2 ml-4 min-h-[70vh] rounded"> |
| 56 | + <div className="w-full"> |
| 57 | + <div className="mt-2 pl-6 pr-6 mb-4"> |
| 58 | + <p>Container Registry</p> |
| 59 | + </div> |
| 60 | + <div className="pl-6 pr-6"> |
| 61 | + <fieldset> |
| 62 | + <legend className="text-sm font-semibold leading-6 text-gray-900"> |
| 63 | + Select registry |
| 64 | + </legend> |
| 65 | + <RadioGroup |
| 66 | + value={selectedRegistry} |
| 67 | + onChange={setSelectedRegistry} |
| 68 | + className="mt-6 grid grid-cols-1 gap-y-6 sm:grid-cols-3 sm:gap-x-4" |
| 69 | + > |
| 70 | + {container_registry_lists.map((registry) => ( |
| 71 | + <Radio |
| 72 | + key={registry.id} |
| 73 | + value={registry} |
| 74 | + aria-label={registry.registry_name} |
| 75 | + aria-description={registry.registry_description} |
| 76 | + className="group relative flex cursor-pointer rounded-lg border border-gray-300 bg-white p-4 shadow-sm focus:outline-none data-[focus]:border-teal-600 data-[focus]:ring-2 data-[focus]:ring-teal-600" |
| 77 | + > |
| 78 | + <span className="flex flex-1"> |
| 79 | + <span className="flex flex-col"> |
| 80 | + <span className="block text-sm font-medium text-gray-900"> |
| 81 | + {registry.registry_name} |
| 82 | + </span> |
| 83 | + <span className="mt-1 flex items-center text-sm text-gray-500"> |
| 84 | + {registry.registry_description} |
| 85 | + </span> |
| 86 | + </span> |
| 87 | + </span> |
| 88 | + <CheckCircleIcon |
| 89 | + aria-hidden="true" |
| 90 | + className="h-5 w-5 text-teal-600 [.group:not([data-checked])_&]:invisible" |
| 91 | + /> |
| 92 | + <span |
| 93 | + aria-hidden="true" |
| 94 | + className="pointer-events-none absolute -inset-px rounded-lg border-2 border-transparent group-data-[focus]:border group-data-[checked]:border-teal-600" |
| 95 | + /> |
| 96 | + </Radio> |
| 97 | + ))} |
| 98 | + </RadioGroup> |
| 99 | + </fieldset> |
| 100 | + </div> |
| 101 | + <div className="pl-6 pr-6"> |
| 102 | + {selectedRegistry.registry_slug === 'docker-hub' && ( |
| 103 | + <div className="mt-4"> |
| 104 | + <label htmlFor="docker-hub-token" className="block text-sm font-medium text-gray-700"> |
| 105 | + Docker Hub Token |
| 106 | + </label> |
| 107 | + <input |
| 108 | + type="password" |
| 109 | + id="docker-hub-token" |
| 110 | + value={dockerHubToken} |
| 111 | + onChange={(e) => setDockerHubToken(e.target.value)} |
| 112 | + className="block w-full border border-gray-300 rounded-md shadow-sm py-1.5 px-3 focus:outline-none focus:ring-teal-500 focus:border-teal-500 sm:text-sm" |
| 113 | + /> |
| 114 | + </div> |
| 115 | + )} |
| 116 | + {selectedRegistry.registry_slug === 'aws-ecr' && ( |
| 117 | + <> |
| 118 | + <div className="mt-4"> |
| 119 | + <label htmlFor="aws-public-key" className="block text-sm font-medium text-gray-700"> |
| 120 | + AWS Public Key |
| 121 | + </label> |
| 122 | + <input |
| 123 | + type="text" |
| 124 | + id="aws-public-key" |
| 125 | + value={awsPublicKey} |
| 126 | + onChange={(e) => setAwsPublicKey(e.target.value)} |
| 127 | + className="block w-full border border-gray-300 rounded-md shadow-sm py-1.5 px-3 focus:outline-none focus:ring-teal-500 focus:border-teal-500 sm:text-sm" |
| 128 | + /> |
| 129 | + </div> |
| 130 | + <div className="mt-4"> |
| 131 | + <label htmlFor="aws-secret-key" className="block text-sm font-medium text-gray-700"> |
| 132 | + AWS Secret Key |
| 133 | + </label> |
| 134 | + <input |
| 135 | + type="password" |
| 136 | + id="aws-secret-key" |
| 137 | + value={awsSecretKey} |
| 138 | + onChange={(e) => setAwsSecretKey(e.target.value)} |
| 139 | + className="block w-full border border-gray-300 rounded-md shadow-sm py-1.5 px-3 focus:outline-none focus:ring-teal-500 focus:border-teal-500 sm:text-sm" |
| 140 | + /> |
| 141 | + </div> |
| 142 | + </> |
| 143 | + )} |
| 144 | + {selectedRegistry.registry_slug === 'azure-acr' && ( |
| 145 | + <> |
| 146 | + <div className="mt-4"> |
| 147 | + <label htmlFor="acr-username" className="block text-sm font-medium text-gray-700"> |
| 148 | + ACR Username |
| 149 | + </label> |
| 150 | + <input |
| 151 | + type="text" |
| 152 | + id="acr-username" |
| 153 | + value={acrUsername} |
| 154 | + onChange={(e) => setAcrUsername(e.target.value)} |
| 155 | + className="block w-full border border-gray-300 rounded-md shadow-sm py-1.5 px-3 focus:outline-none focus:ring-teal-500 focus:border-teal-500 sm:text-sm" |
| 156 | + /> |
| 157 | + </div> |
| 158 | + <div className="mt-4"> |
| 159 | + <label htmlFor="acr-password" className="block text-sm font-medium text-gray-700"> |
| 160 | + ACR Password |
| 161 | + </label> |
| 162 | + <input |
| 163 | + type="password" |
| 164 | + id="acr-password" |
| 165 | + value={acrPassword} |
| 166 | + onChange={(e) => setAcrPassword(e.target.value)} |
| 167 | + className="block w-full border border-gray-300 rounded-md shadow-sm py-1.5 px-3 focus:outline-none focus:ring-teal-500 focus:border-teal-500 sm:text-sm" |
| 168 | + /> |
| 169 | + </div> |
| 170 | + </> |
| 171 | + )} |
| 172 | + </div> |
| 173 | + <div className="pl-6 pr-6 mt-4"> |
| 174 | + <button |
| 175 | + onClick={handleSave} |
| 176 | + className="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-teal-600 hover:bg-teal-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-teal-500" |
| 177 | + > |
| 178 | + Save |
| 179 | + </button> |
| 180 | + </div> |
| 181 | + </div> |
| 182 | + </div> |
| 183 | + ) |
| 184 | +} |
0 commit comments