@@ -3,9 +3,13 @@ import { useAuth } from '@clerk/nextjs';
3
3
import { useState } from 'react' ;
4
4
import type { ChangeEvent , Dispatch , SetStateAction } from 'react' ;
5
5
import { Input } from './ui/input' ;
6
+ import { TenantPicker } from './tenant-picker' ;
7
+ import type { Tenant } from './tenant.env' ;
6
8
7
-
8
- export function ExtractStartForm ( ) {
9
+ type ExtractStartFormProps = {
10
+ TENANTS : Tenant [ ] | undefined
11
+ }
12
+ export function ExtractStartForm ( { TENANTS } : ExtractStartFormProps ) {
9
13
const { getToken } = useAuth ( ) ;
10
14
const currentDate = new Date ( ) ;
11
15
currentDate . setMonth ( currentDate . getMonth ( ) - 6 ) ;
@@ -18,20 +22,22 @@ export function ExtractStartForm() {
18
22
const [ to , setTo ] = useState ( new Date ( ) . toISOString ( ) . slice ( 0 , 10 ) ) ;
19
23
const [ status , setStatus ] = useState ( '---' ) ;
20
24
const [ body , setBody ] = useState ( '' ) ;
25
+ const [ tenantId , setTenantId ] = useState ( ( TENANTS || [ ] ) [ 0 ] ?. id || - 1 ) ;
21
26
22
27
const handleInputChange = ( stateSetter : Dispatch < SetStateAction < any > > ) => ( ev : ChangeEvent < HTMLInputElement > ) => stateSetter ( ev . target . value ) ;
23
28
24
29
const handleSelectChange = ( ev : ChangeEvent < HTMLSelectElement > ) => setSourceControl ( ev . target . value ) ;
25
30
26
31
const handleSubmit = async ( ) => {
27
32
if ( ! process . env . NEXT_PUBLIC_EXTRACT_API_URL ) return console . error ( 'Missing ENV variable: NEXT_PUBLIC_EXTRACT_API_URL' ) ;
33
+ if ( tenantId === - 1 ) return console . error ( `Invalid ENV variable: TENANTS` ) ;
28
34
setStatus ( '...' ) ;
29
35
setBody ( '' ) ;
30
36
31
37
const token = await getToken ( { template : 'dashboard' } ) ;
32
38
if ( ! token ) return ;
33
39
34
- const requestBody = JSON . stringify ( { repositoryId, repositoryName, namespaceName, sourceControl, from : new Date ( from ) , to : new Date ( to ) } ) ;
40
+ const requestBody = JSON . stringify ( { repositoryId, repositoryName, namespaceName, sourceControl, from : new Date ( from ) , to : new Date ( to ) , tenantId } ) ;
35
41
36
42
const res = await fetch ( process . env . NEXT_PUBLIC_EXTRACT_API_URL , {
37
43
method : 'post' ,
@@ -81,6 +87,12 @@ export function ExtractStartForm() {
81
87
< td > < input type = 'date' value = { from } onChange = { handleInputChange ( setFrom ) } className = 'flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50' /> </ td >
82
88
< td > < input type = 'date' value = { to } onChange = { handleInputChange ( setTo ) } className = 'flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50' /> </ td >
83
89
</ tr >
90
+ < tr >
91
+ < td > tenant:</ td >
92
+ < td >
93
+ < TenantPicker tenants = { TENANTS } setTenantId = { setTenantId } />
94
+ </ td >
95
+ </ tr >
84
96
</ tbody >
85
97
</ table >
86
98
< button onClick = { ( ) => void handleSubmit ( ) } > Submit</ button >
0 commit comments