mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
fix(actions): clear client field when switching action types in filter (#766)
* fix(actions): reset client_id on action swap * render fix: missing useEffect on some cases * removed uneccessary amounts of useEffect
This commit is contained in:
parent
f68ce40c30
commit
b04713234c
1 changed files with 32 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
||||||
import { AlertWarning } from "../../components/alerts";
|
import { AlertWarning } from "../../components/alerts";
|
||||||
import { DownloadClientSelect, NumberField, Select, SwitchGroup, TextField } from "../../components/inputs";
|
import { DownloadClientSelect, NumberField, Select, SwitchGroup, TextField } from "../../components/inputs";
|
||||||
import { ActionContentLayoutOptions, ActionRtorrentRenameOptions, ActionTypeNameMap, ActionTypeOptions } from "../../domain/constants";
|
import { ActionContentLayoutOptions, ActionRtorrentRenameOptions, ActionTypeNameMap, ActionTypeOptions } from "../../domain/constants";
|
||||||
import React, { Fragment, useRef } from "react";
|
import React, { Fragment, useRef, useEffect, useState } from "react";
|
||||||
import { useQuery } from "react-query";
|
import { useQuery } from "react-query";
|
||||||
import { APIClient } from "../../api/APIClient";
|
import { APIClient } from "../../api/APIClient";
|
||||||
import { Field, FieldArray, FieldProps, FormikValues } from "formik";
|
import { Field, FieldArray, FieldProps, FormikValues } from "formik";
|
||||||
|
@ -14,6 +14,7 @@ import { DeleteModal } from "../../components/modals";
|
||||||
import { CollapsableSection } from "./details";
|
import { CollapsableSection } from "./details";
|
||||||
import { CustomTooltip } from "../../components/tooltips/CustomTooltip";
|
import { CustomTooltip } from "../../components/tooltips/CustomTooltip";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
import { useFormikContext } from "formik";
|
||||||
|
|
||||||
interface FilterActionsProps {
|
interface FilterActionsProps {
|
||||||
filter: Filter;
|
filter: Filter;
|
||||||
|
@ -106,6 +107,36 @@ interface TypeFormProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
const TypeForm = ({ action, idx, clients }: TypeFormProps) => {
|
const TypeForm = ({ action, idx, clients }: TypeFormProps) => {
|
||||||
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
|
const resetClientField = (action: Action, idx: number, prevActionType: string): void => {
|
||||||
|
const fieldName = `actions.${idx}.client_id`;
|
||||||
|
|
||||||
|
if (prevActionType !== action.type && (
|
||||||
|
action.type === "QBITTORRENT" ||
|
||||||
|
action.type === "DELUGE_V1" ||
|
||||||
|
action.type === "DELUGE_V2" ||
|
||||||
|
action.type === "RTORRENT" ||
|
||||||
|
action.type === "TRANSMISSION" ||
|
||||||
|
action.type === "PORLA" ||
|
||||||
|
action.type === "RADARR" ||
|
||||||
|
action.type === "SONARR" ||
|
||||||
|
action.type === "LIDARR" ||
|
||||||
|
action.type === "WHISPARR" ||
|
||||||
|
action.type === "READARR" ||
|
||||||
|
action.type === "SABNZBD"
|
||||||
|
)) {
|
||||||
|
setFieldValue(fieldName, ""); // Reset the client_id field value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const [prevActionType, setPrevActionType] = useState<string | null>(null);
|
||||||
|
useEffect(() => {
|
||||||
|
if (prevActionType !== null) {
|
||||||
|
resetClientField(action, idx, prevActionType);
|
||||||
|
}
|
||||||
|
setPrevActionType(action.type);
|
||||||
|
}, [action.type, idx, setFieldValue]);
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case "TEST":
|
case "TEST":
|
||||||
return (
|
return (
|
||||||
|
@ -452,7 +483,6 @@ const TypeForm = ({ action, idx, clients }: TypeFormProps) => {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
case "SABNZBD":
|
case "SABNZBD":
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue