67 lines
3.6 KiB
TypeScript
Raw Normal View History

2025-01-03 15:40:22 +01:00
import {Card, Divider, message, Popconfirm, Space, theme, Typography} from 'antd'
import {jt, t} from 'ttag'
2024-12-30 23:50:15 +01:00
import {DeleteFilled} from '@ant-design/icons'
import React from 'react'
2024-12-31 13:55:42 +01:00
import type {Connector} from '../../../utils/api/connectors'
2025-02-19 22:21:20 +01:00
import {ConnectorProvider, deleteConnector} from '../../../utils/api/connectors'
2025-02-18 15:41:59 +01:00
import {providersConfig} from "../../../utils/providers"
2025-02-19 22:21:20 +01:00
2024-12-30 23:50:15 +01:00
const {useToken} = theme
2024-08-02 16:17:55 +02:00
2025-01-03 15:40:22 +01:00
export type ConnectorElement = Connector & { id: string, createdAt: string, watchlistCount: number }
2024-07-29 19:37:17 +02:00
export function ConnectorsList({connectors, onDelete}: { connectors: ConnectorElement[], onDelete: () => void }) {
2024-08-02 16:17:55 +02:00
const {token} = useToken()
const [messageApi, contextHolder] = message.useMessage()
2024-12-30 23:50:15 +01:00
const onConnectorDelete = async (connector: ConnectorElement) => await deleteConnector(connector.id)
.then(onDelete)
.catch(() => messageApi.error(t`An error occurred while deleting the Connector. Make sure it is not used in any Watchlist`))
2024-08-02 16:17:55 +02:00
2024-12-30 23:50:15 +01:00
return (
<>
2025-02-19 22:21:20 +01:00
<Divider/>
2025-01-03 15:40:22 +01:00
{connectors.map(connector => {
const createdAt = <Typography.Text strong key={"createdAt"}>
2025-01-03 15:40:22 +01:00
{new Date(connector.createdAt).toLocaleString()}
</Typography.Text>
const {watchlistCount} = connector
2025-01-06 22:58:00 +01:00
const connectorName = Object.keys(ConnectorProvider).find(p => ConnectorProvider[p as keyof typeof ConnectorProvider] === connector.provider)
2025-01-03 15:40:22 +01:00
return <Card
hoverable
key={connector.id}
title={<Space>
2025-01-06 22:58:00 +01:00
{t`Connector ${connectorName}`}<Typography.Text code>{connector.id}</Typography.Text>
2025-01-03 15:40:22 +01:00
</Space>}
size='small'
style={{width: '100%'}}
extra={<Popconfirm
title={t`Delete the Connector`}
description={t`Are you sure to delete this Connector?`}
onConfirm={async () => await onConnectorDelete(connector)}
okText={t`Yes`}
cancelText={t`No`}
><DeleteFilled style={{color: token.colorError}}/>
</Popconfirm>}
>
{contextHolder}
2025-01-03 15:40:22 +01:00
<Typography.Paragraph>{jt`Creation date: ${createdAt}`}</Typography.Paragraph>
<Typography.Paragraph>{t`Used in: ${watchlistCount} Watchlist`}</Typography.Paragraph>
2025-01-06 22:58:00 +01:00
<Card.Meta description={
<>
{t`You can stop using a connector at any time. To delete a connector, you must remove it from each linked Watchlist.
The creation date corresponds to the date on which you consented to the creation of the connector and on which you declared in particular that you fulfilled the conditions of use of the supplier's API, waived the right of withdrawal and were of the minimum age to consent to these conditions.`}
&nbsp;
2025-02-24 22:18:49 +01:00
{providersConfig[connector.provider].tosLink && <Typography.Link href={providersConfig[connector.provider].tosLink}>
{t`The Providers conditions are accessible by following this hyperlink.`}
</Typography.Link>}
2025-01-06 22:58:00 +01:00
</>
}/>
2025-01-03 15:40:22 +01:00
</Card>
}
2024-12-30 23:50:15 +01:00
)}
</>
)
}