Fix: update download client (#23)

* feat: use password fields

* fix: update download client and better logs
This commit is contained in:
Ludvig Lundgren 2021-08-30 23:55:38 +02:00 committed by GitHub
parent d4aa2027c0
commit f78ca85df2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 64 deletions

View file

@ -117,9 +117,14 @@ export enum DOWNLOAD_CLIENT_TYPES {
}
export interface DownloadClient {
id: number;
id?: number;
name: string;
enabled: boolean;
host: string;
port: number;
ssl: boolean;
username: string;
password: string;
type: DownloadClientType;
settings: object;
}

View file

@ -1,12 +1,12 @@
import { Fragment } from "react";
import { SwitchGroup, TextFieldWide } from "../../../components/inputs";
import { NumberFieldWide } from "../../../components/inputs/wide";
import { NumberFieldWide, PasswordFieldWide } from "../../../components/inputs/wide";
import { useField } from "react-final-form";
function FormFieldsDefault() {
return (
<Fragment>
<TextFieldWide name="host" label="Host" />
<TextFieldWide name="host" label="Host" help="Url domain.ltd/client" />
<NumberFieldWide name="port" label="Port" />
@ -15,7 +15,7 @@ function FormFieldsDefault() {
</div>
<TextFieldWide name="username" label="Username" />
<TextFieldWide name="password" label="Password" />
<PasswordFieldWide name="password" label="Password" />
</Fragment>
);
}
@ -24,9 +24,9 @@ function FormFieldsArr() {
const { input } = useField("settings.basic.auth");
return (
<Fragment>
<TextFieldWide name="host" label="Host" />
<TextFieldWide name="host" label="Host" help="Full url like http(s)://domain.ltd/" />
<TextFieldWide name="settings.apikey" label="API key" />
<PasswordFieldWide name="settings.apikey" label="API key" />
<div className="py-6 px-6 space-y-6 sm:py-0 sm:space-y-0 sm:divide-y sm:divide-gray-200">
<SwitchGroup name="settings.basic.auth" label="Basic auth" />
@ -35,7 +35,7 @@ function FormFieldsArr() {
{input.value === true && (
<Fragment>
<TextFieldWide name="settings.basic.username" label="Username" />
<TextFieldWide name="settings.basic.password" label="Password" />
<PasswordFieldWide name="settings.basic.password" label="Password" />
</Fragment>
)}
</Fragment>

View file

@ -15,15 +15,8 @@ interface DownloadLClientSettingsListItemProps {
}
function DownloadClientSettingsListItem({ client, idx }: DownloadLClientSettingsListItemProps) {
const [enabled, setEnabled] = useState(client.enabled)
const [updateClientIsOpen, toggleUpdateClient] = useToggle(false)
const toggleActive = (status: boolean) => {
console.log(status)
setEnabled(status)
// call api
}
return (
<tr key={client.name} className={idx % 2 === 0 ? 'bg-white' : 'bg-gray-50'}>
{updateClientIsOpen &&
@ -32,7 +25,7 @@ function DownloadClientSettingsListItem({ client, idx }: DownloadLClientSettings
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<Switch
checked={client.enabled}
onChange={toggleActive}
onChange={toggleUpdateClient}
className={classNames(
client.enabled ? 'bg-teal-500' : 'bg-gray-200',
'relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-light-blue-500'
@ -49,6 +42,7 @@ function DownloadClientSettingsListItem({ client, idx }: DownloadLClientSettings
</Switch>
</td>
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{client.name}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{client.host}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{DownloadClientTypeNameMap[client.type]}</td>
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<span className="text-indigo-600 hover:text-indigo-900 cursor-pointer" onClick={toggleUpdateClient}>
@ -115,6 +109,12 @@ function DownloadClientSettings() {
>
Name
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"
>
Host
</th>
<th
scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"