refactor: split connector forms

This commit is contained in:
Maël Gangloff
2025-02-18 15:41:59 +01:00
parent d9b5fe31b0
commit a5efa73b21
10 changed files with 480 additions and 383 deletions

View File

@@ -1,62 +1,45 @@
import {ConnectorProvider} from '../api/connectors'
import {Typography} from 'antd'
import {t} from 'ttag'
import React from 'react'
import type {Connector} from '../api/connectors'
import { ConnectorProvider} from '../api/connectors'
import {OvhCloudConnectorForm} from "./forms/OvhCloudConnectorForm"
import type {FormInstance} from "antd"
import type React from "react"
import {GandiConnectorForm} from "./forms/GandiConnectorForm"
import {NamecheapConnectorForm} from "./forms/NamecheapConnectorForm"
import {AutoDnsConnectorForm} from "./forms/AutoDnsConnectorForm"
import {NamecomConnectorForm} from "./forms/NamecomConnectorForm"
export const helpGetTokenLink = (provider?: string) => {
switch (provider) {
case ConnectorProvider.OVHcloud:
return (
<Typography.Link
target='_blank'
href='https://api.ovh.com/createToken/?GET=/order/cart&GET=/order/cart/*&POST=/order/cart&POST=/order/cart/*&DELETE=/order/cart/*&GET=/domain/extensions'
>
{t`Retrieve a set of tokens from your customer account on the Provider's website`}
</Typography.Link>
)
case ConnectorProvider.Gandi:
return (
<Typography.Link target='_blank' href='https://admin.gandi.net/organizations/account/pat'>
{t`Retrieve a Personal Access Token from your customer account on the Provider's website`}
</Typography.Link>
)
case ConnectorProvider.Namecheap:
return (
<Typography.Link target='_blank' href='https://ap.www.namecheap.com/settings/tools/apiaccess/'>
{t`Retreive an API key and whitelist this instance's IP address on Namecheap's website`}
</Typography.Link>
)
case ConnectorProvider.AutoDNS:
return (
<Typography.Link target='_blank' href='https://en.autodns.com/domain-robot-api/'>
{t`Because of some limitations in API of AutoDNS, we suggest to create an dedicated user for API with limited rights`}
</Typography.Link>
)
case ConnectorProvider['Name.com']:
return (
<Typography.Link target='_blank' href='https://www.name.com/account/settings/api'>
{t`Retrieve a set of tokens from your customer account on the Provider's website`}
</Typography.Link>
)
default:
return <></>
}
export type ProviderConfig = {
tosLink: string
tokenLink: string
form: ({form, onCreate}: { form: FormInstance, onCreate: (values: Connector) => void }) => React.ReactElement
}
export const tosHyperlink = (provider?: string) => {
switch (provider) {
case ConnectorProvider.OVHcloud:
return 'https://www.ovhcloud.com/en/terms-and-conditions/contracts/'
case ConnectorProvider.Gandi:
return 'https://www.gandi.net/en/contracts/terms-of-service'
case ConnectorProvider.Namecheap:
return 'https://www.namecheap.com/legal/universal/universal-tos/'
case ConnectorProvider.AutoDNS:
return 'https://www.internetx.com/agb/'
case ConnectorProvider['Name.com']:
return 'https://www.name.com/policies/'
default:
return ''
export const providersConfig: () => Record<ConnectorProvider, ProviderConfig> = () => {
return {
[ConnectorProvider.OVHcloud]: {
tosLink: 'https://www.ovhcloud.com/en/terms-and-conditions/contracts/',
tokenLink: 'https://api.ovh.com/createToken/?GET=/order/cart&GET=/order/cart/*&POST=/order/cart&POST=/order/cart/*&DELETE=/order/cart/*&GET=/domain/extensions',
form: OvhCloudConnectorForm
},
[ConnectorProvider.Gandi]: {
tosLink: 'https://www.gandi.net/en/contracts/terms-of-service',
tokenLink: 'https://admin.gandi.net/organizations/account/pat',
form: GandiConnectorForm
},
[ConnectorProvider.Namecheap]: {
tosLink: 'https://www.namecheap.com/legal/universal/universal-tos/',
tokenLink: 'https://ap.www.namecheap.com/settings/tools/apiaccess/',
form: NamecheapConnectorForm
},
[ConnectorProvider.AutoDNS]: {
tosLink: 'https://www.internetx.com/agb/',
tokenLink: 'https://en.autodns.com/domain-robot-api/',
form: AutoDnsConnectorForm
},
[ConnectorProvider["Name.com"]]: {
tosLink: 'https://www.name.com/policies/',
tokenLink: 'https://www.name.com/account/settings/api',
form: NamecomConnectorForm
}
}
}