@@ -17,6 +17,7 @@ import {
17
17
SelectTrigger ,
18
18
SelectValue
19
19
} from "@/components/ui/select" ;
20
+ import { internal } from "@/lib/api" ;
20
21
import { useEnvContext } from "@app/hooks/useEnvContext" ;
21
22
import { useDockerSocket } from "@app/hooks/useDockerSocket" ;
22
23
import { useTranslations } from "next-intl" ;
@@ -28,7 +29,9 @@ import { createApiClient } from "@app/lib/api";
28
29
import { build } from "@server/build" ;
29
30
30
31
31
- type ResourceInfoBoxType = { } ;
32
+ type ResourceInfoBoxType = {
33
+ orgs : ResponseOrg [ ] ;
34
+ } ;
32
35
33
36
type ResponseOrg = {
34
37
orgId : string ;
@@ -37,7 +40,7 @@ type ResponseOrg = {
37
40
38
41
39
42
40
- export default function ResourceInfoBox ( { } : ResourceInfoBoxType ) {
43
+ export default function ResourceInfoBox ( { orgs } : ResourceInfoBoxType ) {
41
44
const { resource, authInfo, site } = useResourceContext ( ) ;
42
45
const api = createApiClient ( useEnvContext ( ) ) ;
43
46
@@ -46,33 +49,9 @@ export default function ResourceInfoBox({ }: ResourceInfoBoxType) {
46
49
47
50
let fullUrl = `${ resource . ssl ? "https" : "http" } ://${ resource . fullDomain } ` ;
48
51
49
- const [ availableOrgs , setAvailableOrgs ] = useState < { id : string ; name : string } [ ] > ( [ ] ) ;
50
- const [ selectedOrg , setSelectedOrg ] = useState ( "" ) ;
52
+ const [ selectedOrg , setSelectedOrg ] = useState < string | undefined > ( undefined ) ;
51
53
const [ isLoading , setIsLoading ] = useState ( false ) ;
52
54
53
- useEffect ( ( ) => {
54
- const fetchOrgs = async ( ) => {
55
- try {
56
- const res = await fetch ( "/api/orgs" ) ;
57
- if ( ! res . ok ) throw new Error ( "Failed to load orgs" ) ;
58
- const allOrgs : ResponseOrg [ ] = await res . json ( ) ;
59
-
60
- const orgs = allOrgs
61
- . filter ( ( org ) => org . orgId !== resource . orgId )
62
- . map ( ( org ) => ( {
63
- id : org . orgId ,
64
- name : org . name
65
- } ) ) ;
66
-
67
- setAvailableOrgs ( orgs ) ;
68
- } catch ( err ) {
69
- console . error ( "Error fetching orgs:" , err ) ;
70
- }
71
- } ;
72
-
73
- fetchOrgs ( ) ;
74
- } , [ resource . orgId ] ) ;
75
-
76
55
const handleMove = async ( ) => {
77
56
if ( ! selectedOrg ) return ;
78
57
@@ -220,43 +199,43 @@ export default function ResourceInfoBox({ }: ResourceInfoBoxType) {
220
199
</ InfoSection >
221
200
222
201
< InfoSection >
223
- { /* <InfoSectionTitle>{t("visibility")}</InfoSectionTitle> */ }
224
202
< InfoSectionContent >
225
- { availableOrgs . length > 0 && (
226
- < div className = "flex flex-col gap-2" >
227
- < Select
228
- value = { selectedOrg }
229
- onValueChange = { setSelectedOrg }
230
- >
231
- < SelectTrigger className = "w-full" >
232
- < SelectValue placeholder = "Select target organization" />
233
- </ SelectTrigger >
234
- < SelectContent >
235
- { availableOrgs . map ( ( org ) => (
236
- < SelectItem key = { org . id } value = { org . id } >
237
- { org . name }
238
- </ SelectItem >
239
- ) ) }
240
- </ SelectContent >
241
- </ Select >
242
-
243
- < Button
244
- size = "sm"
245
- onClick = { handleMove }
246
- disabled = { ! selectedOrg || isLoading }
247
- variant = "default"
248
- >
249
- { isLoading ? (
250
- < >
251
- < RotateCw className = "w-4 h-4 animate-spin mr-2" />
252
- Moving...
253
- </ >
254
- ) : (
255
- "Move Resource"
256
- ) }
257
- </ Button >
258
- </ div >
259
- ) }
203
+ < div className = "flex flex-col gap-2" >
204
+ < Select onValueChange = { setSelectedOrg } >
205
+ < SelectTrigger className = "w-full" >
206
+ < SelectValue
207
+ placeholder = {
208
+ orgs . length === 0
209
+ ? "No sites available"
210
+ : "Select target site"
211
+ }
212
+ />
213
+ </ SelectTrigger >
214
+ < SelectContent >
215
+ { orgs . map ( ( org ) => (
216
+ < SelectItem key = { org . orgId } value = { org . orgId } >
217
+ { org . name }
218
+ </ SelectItem >
219
+ ) ) }
220
+ </ SelectContent >
221
+ </ Select >
222
+
223
+ < Button
224
+ size = "sm"
225
+ onClick = { handleMove }
226
+ disabled = { ! selectedOrg || isLoading }
227
+ variant = "default"
228
+ >
229
+ { isLoading ? (
230
+ < >
231
+ < RotateCw className = "w-4 h-4 animate-spin mr-2" />
232
+ Moving...
233
+ </ >
234
+ ) : (
235
+ "Move Resource"
236
+ ) }
237
+ </ Button >
238
+ </ div >
260
239
</ InfoSectionContent >
261
240
</ InfoSection >
262
241
</ InfoSections >
0 commit comments