2024-09-22 18:33:22 +02:00
import { Alert , Button , Checkbox , Form , FormInstance , Input , Popconfirm , Select , Space , Typography } from "antd" ;
2024-07-30 00:55:36 +02:00
import React , { useState } from "react" ;
2024-08-16 13:56:52 +02:00
import { Connector , ConnectorProvider } from "../../../utils/api/connectors" ;
2024-07-30 00:55:36 +02:00
import { t } from "ttag" ;
import { BankOutlined } from "@ant-design/icons" ;
2024-07-30 17:48:09 +02:00
import {
ovhEndpointList as ovhEndpointListFunction ,
ovhFields as ovhFieldsFunction ,
ovhPricingMode as ovhPricingModeFunction ,
ovhSubsidiaryList as ovhSubsidiaryListFunction
2024-08-16 13:56:52 +02:00
} from "../../../utils/providers/ovh" ;
import { helpGetTokenLink , tosHyperlink } from "../../../utils/providers" ;
2024-07-30 00:55:36 +02:00
const formItemLayoutWithOutLabel = {
wrapperCol : {
xs : { span : 24 , offset : 0 } ,
sm : { span : 20 , offset : 4 } ,
} ,
2024-08-21 02:01:20 +02:00
}
2024-07-29 19:37:17 +02:00
export function ConnectorForm ( { form , onCreate } : { form : FormInstance , onCreate : ( values : Connector ) = > void } ) {
2024-07-30 00:55:36 +02:00
const [ provider , setProvider ] = useState < string > ( )
2024-07-30 17:48:09 +02:00
const ovhFields = ovhFieldsFunction ( )
const ovhEndpointList = ovhEndpointListFunction ( )
const ovhSubsidiaryList = ovhSubsidiaryListFunction ( )
const ovhPricingMode = ovhPricingModeFunction ( )
2024-08-10 00:56:46 +02:00
const [ open , setOpen ] = useState ( false )
const [ ovhPricingModeValue , setOvhPricingModeValue ] = useState < string | undefined > ( )
2024-07-30 16:17:31 +02:00
2024-07-30 00:55:36 +02:00
return < Form
{ . . . formItemLayoutWithOutLabel }
form = { form }
layout = "horizontal"
labelCol = { { span : 6 } }
wrapperCol = { { span : 14 } }
onFinish = { onCreate }
>
< Form.Item
label = { t ` Provider ` }
name = "provider"
2024-07-30 16:17:31 +02:00
help = { helpGetTokenLink ( provider ) }
2024-07-30 00:55:36 +02:00
rules = { [ { required : true , message : t ` Required ` } ] }
>
< Select
2024-07-30 22:03:04 +02:00
allowClear
2024-07-30 00:55:36 +02:00
placeholder = { t ` Please select a Provider ` }
suffixIcon = { < BankOutlined / > }
options = { Object . keys ( ConnectorProvider ) . map ( ( c ) = > ( {
value : ConnectorProvider [ c as keyof typeof ConnectorProvider ] ,
label : (
< >
< BankOutlined / > { " " } { c }
< / >
) ,
} ) ) }
value = { provider }
onChange = { setProvider }
2024-07-30 18:22:20 +02:00
autoFocus
2024-07-30 00:55:36 +02:00
/ >
< / Form.Item >
{
provider === ConnectorProvider . OVH && < >
{
Object . keys ( ovhFields ) . map ( fieldName = > < Form.Item
label = { ovhFields [ fieldName as keyof typeof ovhFields ] }
name = { [ 'authData' , fieldName ] }
rules = { [ { required : true , message : t ` Required ` } ] }
>
2024-07-30 18:22:20 +02:00
< Input autoComplete = 'off' / >
2024-07-30 00:55:36 +02:00
< / Form.Item > )
}
< Form.Item
label = { t ` OVH Endpoint ` }
name = { [ 'authData' , 'apiEndpoint' ] }
rules = { [ { required : true , message : t ` Required ` } ] }
>
< Select options = { ovhEndpointList } optionFilterProp = "label" / >
< / Form.Item >
< Form.Item
label = { t ` OVH subsidiary ` }
name = { [ 'authData' , 'ovhSubsidiary' ] }
rules = { [ { required : true , message : t ` Required ` } ] }
>
< Select options = { ovhSubsidiaryList } optionFilterProp = "label" / >
< / Form.Item >
< Form.Item
label = { t ` OVH pricing mode ` }
name = { [ 'authData' , 'pricingMode' ] }
rules = { [ { required : true , message : t ` Required ` } ] }
>
2024-08-10 00:56:46 +02:00
< Popconfirm
title = { t ` Confirm pricing mode ` }
description = { t ` Are you sure about this setting? This may result in additional charges from the API Provider ` }
onCancel = { ( ) = > {
2024-08-10 01:16:07 +02:00
form . resetFields ( [ 'authData' ] )
setOvhPricingModeValue ( undefined )
2024-08-10 00:56:46 +02:00
setOpen ( false )
} }
onConfirm = { ( ) = > setOpen ( false ) }
open = { open }
>
< Select options = { ovhPricingMode } optionFilterProp = "label" value = { ovhPricingModeValue }
onChange = { ( value : string ) = > {
setOvhPricingModeValue ( value )
2024-08-10 01:16:07 +02:00
form . setFieldValue ( [ 'authData' , 'pricingMode' ] , value )
2024-08-10 00:56:46 +02:00
if ( value !== 'create-default' ) {
setOpen ( true )
}
} } / >
< / Popconfirm >
2024-07-30 00:55:36 +02:00
< / Form.Item >
2024-08-06 03:38:00 +02:00
< / >
}
{
provider === ConnectorProvider . GANDI && < >
< Form.Item
label = { t ` Personal Access Token (PAT) ` }
name = { [ 'authData' , 'token' ] }
rules = { [ { required : true , message : t ` Required ` } ] } >
< Input autoComplete = 'off' / >
< / Form.Item >
< Form.Item
label = { t ` Organization sharing ID ` }
name = { [ 'authData' , 'sharingId' ] }
help = { < Typography.Text
type = 'secondary' > { t ` It indicates the organization that will pay for the ordered product ` } < / Typography.Text > }
required = { false } >
< Input autoComplete = 'off' placeholder = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' / >
< / Form.Item >
< / >
}
2024-09-22 18:33:22 +02:00
{
provider === ConnectorProvider . AUTODNS && < >
< Alert message = { t ` Because of some limitations in API of AutoDNS, we suggest to create an dedicated user for API with limited rights. ` } type = "info" / >
2024-09-22 23:06:18 +02:00
< Alert message = { t ` This provider does not provide a list of supported TLD. Please double check if the domain you want to register is supported. ` } type = "warning" / >
2024-09-22 18:33:22 +02:00
< br / >
< Form.Item
label = { t ` AutoDNS Username ` }
name = { [ 'authData' , 'username' ] }
help = { < Typography.Text
type = 'secondary' > { t ` Attention: AutoDNS do not support 2-Factor Authentication on API Users for automated systems ` } < / Typography.Text > }
rules = { [ { required : true , message : t ` Required ` } ] } >
< Input autoComplete = 'off' required = { true } / >
< / Form.Item >
< Form.Item
label = { t ` AutoDNS Password ` }
name = { [ 'authData' , 'password' ] }
rules = { [ { required : true , message : t ` Required ` } ] }
required = { true } >
< Input.Password autoComplete = 'off' required = { true } placeholder = '' / >
< / Form.Item >
< Form.Item
label = { t ` Domain Contact Handle ID ` }
name = { [ 'authData' , 'contactid' ] }
help = { < Typography.Text
type = 'secondary' > { t ` The Contact ID for ownership of registered Domains. ` } < a href = "https://cloud.autodns.com/contacts/domain" > { t ` You got from this page ` } < / a > < / Typography.Text > }
rules = { [ { required : true , message : t ` Required ` } ] }
required = { true } >
< Input autoComplete = 'off' required = { true } placeholder = '' / >
< / Form.Item >
< Form.Item
label = { t ` Context Value ` }
name = { [ 'authData' , 'context' ] }
help = { < Typography.Text
type = 'secondary' > { t ` If you not sure, use the default value 4 ` } < / Typography.Text > }
required = { false } >
< Input autoComplete = 'off' required = { false } placeholder = '4' / >
< / Form.Item >
< Form.Item
2024-09-22 23:06:18 +02:00
valuePropName = 'checked'
2024-09-22 18:33:22 +02:00
label = { t ` Owner confirmation ` }
name = { [ 'authData' , 'ownerConfirm' ] }
rules = { [ { required : true , message : t ` Required ` } ] }
>
< Checkbox
required = { true } > { t ` Owner confirms his consent of domain order jobs ` } < / Checkbox >
< / Form.Item >
< / >
}
2024-08-06 03:38:00 +02:00
{
provider !== undefined && < >
2024-07-30 14:56:08 +02:00
< Form.Item
valuePropName = "checked"
2024-07-30 16:17:31 +02:00
label = { t ` API Terms of Service ` }
2024-07-30 14:56:08 +02:00
name = { [ 'authData' , 'acceptConditions' ] }
rules = { [ { required : true , message : t ` Required ` } ] }
2024-08-06 11:58:41 +02:00
style = { { marginTop : '3em' } }
2024-07-30 14:56:08 +02:00
>
< Checkbox
2024-07-30 16:17:31 +02:00
required = { true } >
< Typography.Link target = '_blank' href = { tosHyperlink ( provider ) } >
2024-08-08 19:55:22 +02:00
{ t ` I have read and accepted the conditions of use of the Provider API, accessible from this hyperlink ` }
2024-07-30 16:17:31 +02:00
< / Typography.Link >
< / Checkbox >
2024-07-30 14:56:08 +02:00
< / Form.Item >
< Form.Item
valuePropName = "checked"
label = { t ` Legal age ` }
name = { [ 'authData' , 'ownerLegalAge' ] }
rules = { [ { required : true , message : t ` Required ` } ] }
>
< Checkbox
2024-08-08 19:55:22 +02:00
required = { true } > { t ` I am of the minimum age required to consent to these conditions ` } < / Checkbox >
2024-07-30 14:56:08 +02:00
< / Form.Item >
< Form.Item
valuePropName = "checked"
label = { t ` Withdrawal period ` }
name = { [ 'authData' , 'waiveRetractationPeriod' ] }
rules = { [ { required : true , message : t ` Required ` } ] }
>
< Checkbox
2024-08-08 19:55:22 +02:00
required = { true } > { t ` I waive my right of withdrawal regarding the purchase of domain names via the Provider's API ` } < / Checkbox >
2024-07-30 14:56:08 +02:00
< / Form.Item >
2024-07-30 00:55:36 +02:00
< / >
}
2024-08-20 19:15:04 +02:00
< Form.Item style = { { marginTop : '5vh' } } >
2024-07-30 00:55:36 +02:00
< Space >
< Button type = "primary" htmlType = "submit" >
{ t ` Create ` }
< / Button >
< Button type = "default" htmlType = "reset" >
{ t ` Reset ` }
< / Button >
< / Space >
< / Form.Item >
< / Form >
2024-07-29 19:37:17 +02:00
}