mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
fix: update watchlist form
This commit is contained in:
@@ -15,7 +15,7 @@ const {useToken} = theme;
|
|||||||
export function WatchlistsList({watchlists, onDelete, onUpdateWatchlist, connectors}: {
|
export function WatchlistsList({watchlists, onDelete, onUpdateWatchlist, connectors}: {
|
||||||
watchlists: Watchlist[],
|
watchlists: Watchlist[],
|
||||||
onDelete: () => void,
|
onDelete: () => void,
|
||||||
onUpdateWatchlist: (values: { domains: string[], emailTriggers: string[], token: string }) => void,
|
onUpdateWatchlist: (values: { domains: string[], emailTriggers: string[], token: string }) => Promise<void>,
|
||||||
connectors: (Connector & { id: string })[]
|
connectors: (Connector & { id: string })[]
|
||||||
}) {
|
}) {
|
||||||
const {token} = useToken()
|
const {token} = useToken()
|
||||||
@@ -34,7 +34,8 @@ export function WatchlistsList({watchlists, onDelete, onUpdateWatchlist, connect
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false)
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
const showDrawer = () => {
|
const showDrawer = () => {
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
@@ -42,6 +43,7 @@ export function WatchlistsList({watchlists, onDelete, onUpdateWatchlist, connect
|
|||||||
|
|
||||||
const onClose = () => {
|
const onClose = () => {
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
|
setLoading(false)
|
||||||
};
|
};
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
@@ -85,6 +87,7 @@ export function WatchlistsList({watchlists, onDelete, onUpdateWatchlist, connect
|
|||||||
width='80%'
|
width='80%'
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
open={open}
|
open={open}
|
||||||
|
loading={loading}
|
||||||
styles={{
|
styles={{
|
||||||
body: {
|
body: {
|
||||||
paddingBottom: 80,
|
paddingBottom: 80,
|
||||||
@@ -95,8 +98,8 @@ export function WatchlistsList({watchlists, onDelete, onUpdateWatchlist, connect
|
|||||||
<WatchlistForm
|
<WatchlistForm
|
||||||
form={form}
|
form={form}
|
||||||
onFinish={values => {
|
onFinish={values => {
|
||||||
onUpdateWatchlist(values);
|
setLoading(true)
|
||||||
onClose()
|
onUpdateWatchlist(values).then(onClose).catch(() => setLoading(false))
|
||||||
}}
|
}}
|
||||||
connectors={connectors}
|
connectors={connectors}
|
||||||
isCreation={false}
|
isCreation={false}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export default function WatchlistPage() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const onUpdateWatchlist = (values: {
|
const onUpdateWatchlist = async (values: {
|
||||||
token: string
|
token: string
|
||||||
name?: string
|
name?: string
|
||||||
domains: string[],
|
domains: string[],
|
||||||
@@ -59,9 +59,7 @@ export default function WatchlistPage() {
|
|||||||
}) => {
|
}) => {
|
||||||
const domainsURI = values.domains.map(d => '/api/domains/' + d)
|
const domainsURI = values.domains.map(d => '/api/domains/' + d)
|
||||||
|
|
||||||
console.log(values)
|
return putWatchlist({
|
||||||
|
|
||||||
putWatchlist({
|
|
||||||
token: values.token,
|
token: values.token,
|
||||||
name: values.name,
|
name: values.name,
|
||||||
domains: domainsURI,
|
domains: domainsURI,
|
||||||
@@ -71,7 +69,7 @@ export default function WatchlistPage() {
|
|||||||
refreshWatchlists()
|
refreshWatchlists()
|
||||||
messageApi.success(t`Watchlist updated !`)
|
messageApi.success(t`Watchlist updated !`)
|
||||||
}).catch((e: AxiosError) => {
|
}).catch((e: AxiosError) => {
|
||||||
showErrorAPI(e, messageApi)
|
throw showErrorAPI(e, messageApi)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {Event, request, Watchlist} from "./index";
|
import {request, Watchlist} from "./index";
|
||||||
|
|
||||||
export async function getWatchlists() {
|
export async function getWatchlists() {
|
||||||
const response = await request({
|
const response = await request({
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class WatchListController extends AbstractController
|
|||||||
* This policy guarantees the equal probability of obtaining a domain name if it is requested by several users.
|
* This policy guarantees the equal probability of obtaining a domain name if it is requested by several users.
|
||||||
*/
|
*/
|
||||||
if ($this->getParameter('limited_features')) {
|
if ($this->getParameter('limited_features')) {
|
||||||
if ($watchList->getDomains()->count() >= (int) $this->getParameter('limit_max_watchlist_domains')) {
|
if ($watchList->getDomains()->count() > (int) $this->getParameter('limit_max_watchlist_domains')) {
|
||||||
$this->logger->notice('User {username} tried to create a Watchlist. However, the maximum number of domains has been reached for this Watchlist', [
|
$this->logger->notice('User {username} tried to create a Watchlist. However, the maximum number of domains has been reached for this Watchlist', [
|
||||||
'username' => $user->getUserIdentifier(),
|
'username' => $user->getUserIdentifier(),
|
||||||
]);
|
]);
|
||||||
@@ -78,7 +78,7 @@ class WatchListController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$userWatchLists = $user->getWatchLists();
|
$userWatchLists = $user->getWatchLists();
|
||||||
if ($userWatchLists->count() >= (int) $this->getParameter('limit_max_watchlist')) {
|
if ($userWatchLists->count() > (int) $this->getParameter('limit_max_watchlist')) {
|
||||||
$this->logger->notice('User {username} tried to create a Watchlist. However, the maximum number of Watchlists has been reached.', [
|
$this->logger->notice('User {username} tried to create a Watchlist. However, the maximum number of Watchlists has been reached.', [
|
||||||
'username' => $user->getUserIdentifier(),
|
'username' => $user->getUserIdentifier(),
|
||||||
]);
|
]);
|
||||||
@@ -150,7 +150,7 @@ class WatchListController extends AbstractController
|
|||||||
$watchList->setUser($user);
|
$watchList->setUser($user);
|
||||||
|
|
||||||
if ($this->getParameter('limited_features')) {
|
if ($this->getParameter('limited_features')) {
|
||||||
if ($watchList->getDomains()->count() >= (int) $this->getParameter('limit_max_watchlist_domains')) {
|
if ($watchList->getDomains()->count() > (int) $this->getParameter('limit_max_watchlist_domains')) {
|
||||||
$this->logger->notice('User {username} tried to update a Watchlist. However, the maximum number of domains has been reached for this Watchlist', [
|
$this->logger->notice('User {username} tried to update a Watchlist. However, the maximum number of domains has been reached for this Watchlist', [
|
||||||
'username' => $user->getUserIdentifier(),
|
'username' => $user->getUserIdentifier(),
|
||||||
]);
|
]);
|
||||||
@@ -161,7 +161,7 @@ class WatchListController extends AbstractController
|
|||||||
|
|
||||||
/** @var Domain[] $trackedDomains */
|
/** @var Domain[] $trackedDomains */
|
||||||
$trackedDomains = $userWatchLists
|
$trackedDomains = $userWatchLists
|
||||||
->filter(fn (WatchList $wl) => $wl !== $watchList)
|
->filter(fn (WatchList $wl) => $wl->getToken() !== $watchList->getToken())
|
||||||
->reduce(fn (array $acc, WatchList $wl) => [...$acc, ...$wl->getDomains()->toArray()], []);
|
->reduce(fn (array $acc, WatchList $wl) => [...$acc, ...$wl->getDomains()->toArray()], []);
|
||||||
|
|
||||||
/** @var Domain $domain */
|
/** @var Domain $domain */
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
#[ORM\Entity(repositoryClass: DomainEventRepository::class)]
|
#[ORM\Entity(repositoryClass: DomainEventRepository::class)]
|
||||||
class DomainEvent extends Event
|
class DomainEvent extends Event
|
||||||
{
|
{
|
||||||
#[ORM\ManyToOne(targetEntity: Domain::class, cascade: ['persist'], inversedBy: 'events')]
|
#[ORM\ManyToOne(targetEntity: Domain::class, inversedBy: 'events')]
|
||||||
#[ORM\JoinColumn(referencedColumnName: 'ldh_name', nullable: false)]
|
#[ORM\JoinColumn(referencedColumnName: 'ldh_name', nullable: false)]
|
||||||
private ?Domain $domain = null;
|
private ?Domain $domain = null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user