mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
feat: connector on watchlist
This commit is contained in:
@@ -40,6 +40,7 @@ export function ConnectorForm({form, onCreate}: { form: FormInstance, onCreate:
|
|||||||
rules={[{required: true, message: t`Required`}]}
|
rules={[{required: true, message: t`Required`}]}
|
||||||
>
|
>
|
||||||
<Select
|
<Select
|
||||||
|
allowClear
|
||||||
placeholder={t`Please select a Provider`}
|
placeholder={t`Please select a Provider`}
|
||||||
suffixIcon={<BankOutlined/>}
|
suffixIcon={<BankOutlined/>}
|
||||||
options={Object.keys(ConnectorProvider).map((c) => ({
|
options={Object.keys(ConnectorProvider).map((c) => ({
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {Button, Form, FormInstance, Input, Select, Space} from "antd";
|
import {Button, Form, FormInstance, Input, Select, Space} from "antd";
|
||||||
import {t} from "ttag";
|
import {t} from "ttag";
|
||||||
import {MinusCircleOutlined, PlusOutlined, ThunderboltFilled} from "@ant-design/icons";
|
import {ApiOutlined, MinusCircleOutlined, PlusOutlined, ThunderboltFilled} from "@ant-design/icons";
|
||||||
import React, {useState} from "react";
|
import React from "react";
|
||||||
import {EventAction} from "../../utils/api";
|
import {EventAction} from "../../utils/api";
|
||||||
import {Connector} from "../../utils/api/connectors";
|
import {Connector} from "../../utils/api/connectors";
|
||||||
|
|
||||||
@@ -73,13 +73,8 @@ export function WatchlistForm({form, connectors, onCreateWatchlist}: {
|
|||||||
{
|
{
|
||||||
label: t`Send me an email`,
|
label: t`Send me an email`,
|
||||||
value: 'email'
|
value: 'email'
|
||||||
},
|
|
||||||
{
|
|
||||||
label: t`Buy the domain if available`,
|
|
||||||
value: 'buy'
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
const [actionsSelect, setActionsSelect] = useState<{ [key: number]: string }>({})
|
|
||||||
|
|
||||||
return <Form
|
return <Form
|
||||||
{...formItemLayoutWithOutLabel}
|
{...formItemLayoutWithOutLabel}
|
||||||
@@ -186,27 +181,8 @@ export function WatchlistForm({form, connectors, onCreateWatchlist}: {
|
|||||||
noStyle name={[field.name, 'action']}>
|
noStyle name={[field.name, 'action']}>
|
||||||
<Select style={{minWidth: 300}} options={triggerActionItems} showSearch
|
<Select style={{minWidth: 300}} options={triggerActionItems} showSearch
|
||||||
placeholder={t`Then do that`}
|
placeholder={t`Then do that`}
|
||||||
optionFilterProp="label" value={actionsSelect[field.key]}
|
optionFilterProp="label"/>
|
||||||
onChange={(e) => setActionsSelect({...actionsSelect, [field.key]: e})}/>
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
{actionsSelect[field.key] === 'buy' && <Form.Item {...field}
|
|
||||||
validateTrigger={['onChange', 'onBlur']}
|
|
||||||
rules={[{
|
|
||||||
required: true,
|
|
||||||
message: t`Required`
|
|
||||||
}]}
|
|
||||||
noStyle
|
|
||||||
name={[field.name, 'connector']}>
|
|
||||||
<Select style={{minWidth: 500}} showSearch
|
|
||||||
placeholder={t`Connector`}
|
|
||||||
optionFilterProp="label"
|
|
||||||
options={connectors.map(c => ({
|
|
||||||
label: `${c.provider} (${c.id})`,
|
|
||||||
value: c.id
|
|
||||||
}))}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
}
|
|
||||||
</Space>
|
</Space>
|
||||||
|
|
||||||
{fields.length > 1 ? (
|
{fields.length > 1 ? (
|
||||||
@@ -231,6 +207,21 @@ export function WatchlistForm({form, connectors, onCreateWatchlist}: {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Form.List>
|
</Form.List>
|
||||||
|
<Form.Item label={t`Connector`}
|
||||||
|
name='connector'
|
||||||
|
>
|
||||||
|
<Select showSearch
|
||||||
|
allowClear
|
||||||
|
style={{width: '60%'}}
|
||||||
|
placeholder={t`Connector`}
|
||||||
|
suffixIcon={<ApiOutlined/>}
|
||||||
|
optionFilterProp="label"
|
||||||
|
options={connectors.map(c => ({
|
||||||
|
label: `${c.provider} (${c.id})`,
|
||||||
|
value: c.id
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Space>
|
<Space>
|
||||||
<Button type="primary" htmlType="submit">
|
<Button type="primary" htmlType="submit">
|
||||||
|
|||||||
@@ -20,13 +20,14 @@ export default function WatchlistPage() {
|
|||||||
const onCreateWatchlist = (values: {
|
const onCreateWatchlist = (values: {
|
||||||
domains: string[],
|
domains: string[],
|
||||||
triggers: { event: string, action: string, connector?: string }[]
|
triggers: { event: string, action: string, connector?: string }[]
|
||||||
|
connector?: string
|
||||||
}) => {
|
}) => {
|
||||||
const domainsURI = values.domains.map(d => '/api/domains/' + d)
|
const domainsURI = values.domains.map(d => '/api/domains/' + d)
|
||||||
postWatchlist(domainsURI, values.triggers.map(({action, event, connector}) => ({
|
postWatchlist({
|
||||||
action,
|
domains: domainsURI,
|
||||||
event,
|
triggers: values.triggers,
|
||||||
connector: connector !== undefined ? '/api/connectors/' + connector : undefined
|
connector: values.connector !== undefined ? '/api/connectors/' + values.connector : undefined
|
||||||
}))).then((w) => {
|
}).then((w) => {
|
||||||
form.resetFields()
|
form.resetFields()
|
||||||
refreshWatchlists()
|
refreshWatchlists()
|
||||||
messageApi.success(t`Watchlist created !`)
|
messageApi.success(t`Watchlist created !`)
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ export type EventAction =
|
|||||||
| 'enum validation expiration'
|
| 'enum validation expiration'
|
||||||
| string
|
| string
|
||||||
|
|
||||||
|
export type TriggerAction = 'email' | string
|
||||||
|
|
||||||
export interface Event {
|
export interface Event {
|
||||||
action: EventAction
|
action: EventAction
|
||||||
date: string
|
date: string
|
||||||
@@ -62,9 +64,10 @@ export interface User {
|
|||||||
roles: string[]
|
roles: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Watchlist {
|
export interface Watchlist {
|
||||||
domains: string[]
|
domains: string[],
|
||||||
triggers: Event[]
|
triggers: { event: EventAction, action: TriggerAction }[],
|
||||||
|
connector?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig): Promise<R> {
|
export async function request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig): Promise<R> {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Event, EventAction, request, Watchlist} from "./index";
|
import {Event, request, Watchlist} from "./index";
|
||||||
|
|
||||||
export async function getWatchlists() {
|
export async function getWatchlists() {
|
||||||
const response = await request({
|
const response = await request({
|
||||||
@@ -8,24 +8,17 @@ export async function getWatchlists() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getWatchlist(token: string) {
|
export async function getWatchlist(token: string) {
|
||||||
const response = await request<Watchlist>({
|
const response = await request<Watchlist & { token: string }>({
|
||||||
url: 'watchlists/' + token
|
url: 'watchlists/' + token
|
||||||
})
|
})
|
||||||
return response.data
|
return response.data
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function postWatchlist(domains: string[], triggers: {
|
export async function postWatchlist(watchlist: Watchlist) {
|
||||||
action: string,
|
|
||||||
event: EventAction,
|
|
||||||
connector?: string
|
|
||||||
}[]) {
|
|
||||||
const response = await request<{ token: string }>({
|
const response = await request<{ token: string }>({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: 'watchlists',
|
url: 'watchlists',
|
||||||
data: {
|
data: watchlist,
|
||||||
domains,
|
|
||||||
triggers
|
|
||||||
},
|
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": 'application/json'
|
"Content-Type": 'application/json'
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user