Update server forms

This commit is contained in:
jeffvli
2022-11-08 04:00:22 -08:00
parent d3e4c7d975
commit d6fe3038e0
3 changed files with 98 additions and 110 deletions
@@ -2,7 +2,6 @@ import { Checkbox, Stack, Group } from '@mantine/core';
import { useForm } from '@mantine/form'; import { useForm } from '@mantine/form';
import { useFocusTrap } from '@mantine/hooks'; import { useFocusTrap } from '@mantine/hooks';
import { closeAllModals } from '@mantine/modals'; import { closeAllModals } from '@mantine/modals';
import { useTranslation } from 'react-i18next';
import { ServerType } from '@/renderer/api/types'; import { ServerType } from '@/renderer/api/types';
import { import {
Button, Button,
@@ -23,7 +22,6 @@ interface AddServerFormProps {
} }
export const AddServerForm = ({ onCancel }: AddServerFormProps) => { export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
const { t } = useTranslation();
const focusTrapRef = useFocusTrap(true); const focusTrapRef = useFocusTrap(true);
const form = useForm({ const form = useForm({
@@ -53,27 +51,23 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
<TextInput <TextInput
data-autofocus data-autofocus
required required
label={t('modal.add_server.name_label')} label="Name"
{...form.getInputProps('name')} {...form.getInputProps('name')}
/> />
<TextInput required label="Url" {...form.getInputProps('url')} />
<TextInput <TextInput
required required
label={t('modal.add_server.url_label')} label="Username"
{...form.getInputProps('url')}
/>
<TextInput
required
label={t('modal.add_server.username_label')}
{...form.getInputProps('username')} {...form.getInputProps('username')}
/> />
<PasswordInput <PasswordInput
required required
label={t('modal.add_server.password_label')} label="Password"
{...form.getInputProps('password')} {...form.getInputProps('password')}
/> />
{form.values.type === ServerType.SUBSONIC && ( {form.values.type === ServerType.SUBSONIC && (
<Checkbox <Checkbox
label={t('modal.add_server.legacy_label')} label="Enable legacy authentication"
{...form.getInputProps('legacyAuth', { type: 'checkbox' })} {...form.getInputProps('legacyAuth', { type: 'checkbox' })}
/> />
)} )}
@@ -86,7 +80,7 @@ export const AddServerForm = ({ onCancel }: AddServerFormProps) => {
type="submit" type="submit"
variant="filled" variant="filled"
> >
{t('modal.add_server.submit_label')} Submit
</Button> </Button>
</Group> </Group>
</Stack> </Stack>
@@ -1,6 +1,5 @@
import { Checkbox, Stack, Group } from '@mantine/core'; import { Checkbox, Stack, Group } from '@mantine/core';
import { useForm } from '@mantine/form'; import { useForm } from '@mantine/form';
import { useTranslation } from 'react-i18next';
import { RiInformationLine } from 'react-icons/ri'; import { RiInformationLine } from 'react-icons/ri';
import { Server, ServerType } from '@/renderer/api/types'; import { Server, ServerType } from '@/renderer/api/types';
import { Button, PasswordInput, TextInput, toast } from '@/renderer/components'; import { Button, PasswordInput, TextInput, toast } from '@/renderer/components';
@@ -12,7 +11,6 @@ interface EditServerFormProps {
} }
export const EditServerForm = ({ server, onCancel }: EditServerFormProps) => { export const EditServerForm = ({ server, onCancel }: EditServerFormProps) => {
const { t } = useTranslation();
const updateServer = useUpdateServer(); const updateServer = useUpdateServer();
const serverDetailsForm = useForm({ const serverDetailsForm = useForm({
@@ -57,7 +55,7 @@ export const EditServerForm = ({ server, onCancel }: EditServerFormProps) => {
<Stack> <Stack>
<TextInput <TextInput
required required
label={t('generic.name')} label="Name"
rightSection={ rightSection={
serverDetailsForm.isDirty('name') && ( serverDetailsForm.isDirty('name') && (
<RiInformationLine color="red" /> <RiInformationLine color="red" />
@@ -67,7 +65,7 @@ export const EditServerForm = ({ server, onCancel }: EditServerFormProps) => {
/> />
<TextInput <TextInput
required required
label={t('generic.url')} label="Url"
rightSection={ rightSection={
serverDetailsForm.isDirty('url') && ( serverDetailsForm.isDirty('url') && (
<RiInformationLine color="red" /> <RiInformationLine color="red" />
@@ -76,7 +74,7 @@ export const EditServerForm = ({ server, onCancel }: EditServerFormProps) => {
{...serverDetailsForm.getInputProps('url')} {...serverDetailsForm.getInputProps('url')}
/> />
<TextInput <TextInput
label={t('generic.username')} label="Username"
rightSection={ rightSection={
serverDetailsForm.isDirty('username') && ( serverDetailsForm.isDirty('username') && (
<RiInformationLine color="red" /> <RiInformationLine color="red" />
@@ -85,12 +83,12 @@ export const EditServerForm = ({ server, onCancel }: EditServerFormProps) => {
{...serverDetailsForm.getInputProps('username')} {...serverDetailsForm.getInputProps('username')}
/> />
<PasswordInput <PasswordInput
label={t('generic.password')} label="Password"
{...serverDetailsForm.getInputProps('password')} {...serverDetailsForm.getInputProps('password')}
/> />
{isSubsonic && ( {isSubsonic && (
<Checkbox <Checkbox
label={t('generic.legacyauth')} label="Enable legacy authentication"
{...serverDetailsForm.getInputProps('legacyAuth', { {...serverDetailsForm.getInputProps('legacyAuth', {
type: 'checkbox', type: 'checkbox',
})} })}
@@ -2,7 +2,7 @@ import { useMemo } from 'react';
import { Stack, Group, Divider } from '@mantine/core'; import { Stack, Group, Divider } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks'; import { useDisclosure } from '@mantine/hooks';
import { useQueryClient } from '@tanstack/react-query'; import { useQueryClient } from '@tanstack/react-query';
import { RiDeleteBin2Fill, RiEdit2Fill } from 'react-icons/ri'; import { RiDeleteBin2Line, RiEdit2Fill } from 'react-icons/ri';
import { queryKeys } from '@/renderer/api/query-keys'; import { queryKeys } from '@/renderer/api/query-keys';
import { Server, TaskType } from '@/renderer/api/types'; import { Server, TaskType } from '@/renderer/api/types';
import { Button, Switch, Text, toast } from '@/renderer/components'; import { Button, Switch, Text, toast } from '@/renderer/components';
@@ -160,7 +160,7 @@ export const ServerListItem = ({ server }: ServerListItemProps) => {
<Button <Button
compact compact
disabled={true || isRunningTask} disabled={true || isRunningTask}
variant="filled" variant="subtle"
onClick={handleQuickScan} onClick={handleQuickScan}
> >
Quick scan Quick scan
@@ -182,20 +182,19 @@ export const ServerListItem = ({ server }: ServerListItemProps) => {
<Text>Username</Text> <Text>Username</Text>
</Stack> </Stack>
<Stack> <Stack>
<Text>{server.url}</Text> <Text size="sm">{server.url}</Text>
<Text>{server.username}</Text> <Text size="sm">{server.username}</Text>
</Stack> </Stack>
</Group> </Group>
<Group> <Group>
{permissions.editServer && ( <Button
<Button disabled={!permissions.editServer}
tooltip={{ label: 'Edit server details' }} tooltip={{ label: 'Edit server details' }}
variant="default" variant="default"
onClick={() => editHandlers.toggle()} onClick={() => editHandlers.toggle()}
> >
<RiEdit2Fill color="white" /> <RiEdit2Fill color="white" />
</Button> </Button>
)}
</Group> </Group>
</Group> </Group>
)} )}
@@ -204,20 +203,22 @@ export const ServerListItem = ({ server }: ServerListItemProps) => {
<Stack> <Stack>
{server.serverFolders?.map((folder) => ( {server.serverFolders?.map((folder) => (
<Group key={folder.id} position="apart"> <Group key={folder.id} position="apart">
<Text>{folder.name}</Text>
<Group> <Group>
{permissions.deleteServerFolder && ( <Button
<Button compact disabled radius="xl" variant="subtle"> compact
<RiDeleteBin2Fill /> disabled={true || !permissions.deleteServerFolder}
</Button> variant="subtle"
)} >
<Switch <RiDeleteBin2Line color="var(--danger-color)" />
checked={folder.enabled} </Button>
onChange={(e) => <Text size="sm">{folder.name}</Text>
handleToggleFolder(folder.id, !e.currentTarget.checked)
}
/>
</Group> </Group>
<Switch
checked={folder.enabled}
onChange={(e) =>
handleToggleFolder(folder.id, !e.currentTarget.checked)
}
/>
</Group> </Group>
))} ))}
</Stack> </Stack>
@@ -233,41 +234,38 @@ export const ServerListItem = ({ server }: ServerListItemProps) => {
<Stack> <Stack>
{serverCredentials?.map((credential) => ( {serverCredentials?.map((credential) => (
<Group key={credential.id} position="apart"> <Group key={credential.id} position="apart">
<Text>{credential.username}</Text>
<Group> <Group>
{permissions.deleteServerCredential && ( <Button
<Button compact
compact disabled={!permissions.deleteServerCredential}
radius="xl" variant="subtle"
variant="subtle" onClick={() => handleDeleteCredential(credential.id)}
onClick={() => handleDeleteCredential(credential.id)} >
> <RiDeleteBin2Line color="var(--danger-color)" />
<RiDeleteBin2Fill /> </Button>
</Button> <Text size="sm">{credential.username}</Text>
)}
<Switch
checked={credential.enabled}
onChange={(e) =>
handleToggleCredential(
credential.id,
!e.currentTarget.checked
)
}
/>
</Group> </Group>
<Switch
checked={credential.enabled}
onChange={(e) =>
handleToggleCredential(
credential.id,
!e.currentTarget.checked
)
}
/>
</Group> </Group>
))} ))}
</Stack> </Stack>
{permissions.createServerCredential && ( <Button
<Button compact
compact disabled={!permissions.createServerCredential}
mt={10} mt={10}
variant="default" variant="subtle"
onClick={() => addCredentialHandlers.open()} onClick={() => addCredentialHandlers.open()}
> >
Add credential Add credential
</Button> </Button>
)}
</> </>
)} )}
</ServerSection> </ServerSection>
@@ -282,61 +280,59 @@ export const ServerListItem = ({ server }: ServerListItemProps) => {
<Stack> <Stack>
{server.serverUrls?.map((serverUrl) => ( {server.serverUrls?.map((serverUrl) => (
<Group key={serverUrl.id} position="apart"> <Group key={serverUrl.id} position="apart">
<Text>{serverUrl.url}</Text>
<Group> <Group>
{permissions.deleteServerUrl && ( <Button
<Button compact
compact disabled={!permissions.deleteServerUrl}
radius="xl" variant="subtle"
variant="subtle" onClick={() => handleDeleteUrl(serverUrl.id)}
onClick={() => handleDeleteUrl(serverUrl.id)} >
> <RiDeleteBin2Line color="var(--danger-color)" />
<RiDeleteBin2Fill /> </Button>
</Button> <Text size="sm">{serverUrl.url}</Text>
)}
<Switch
checked={serverUrl.enabled}
onChange={(e) =>
handleToggleUrl(
serverUrl.id,
!e.currentTarget.checked
)
}
/>
</Group> </Group>
<Switch
checked={serverUrl.enabled}
onChange={(e) =>
handleToggleUrl(serverUrl.id, !e.currentTarget.checked)
}
/>
</Group> </Group>
))} ))}
</Stack> </Stack>
{permissions.createServerUrl && ( <Button
<Button compact
compact disabled={!permissions.createServerUrl}
mt={10} mt={10}
variant="default" variant="subtle"
onClick={() => addUrlHandlers.open()} onClick={() => addUrlHandlers.open()}
> >
Add URL Add url
</Button> </Button>
)}
</> </>
)} )}
</ServerSection> </ServerSection>
<ServerSection title="Danger zone"> <ServerSection title="Danger zone">
<Group position="apart"> <Group position="apart">
<Text>Require user credentials</Text> <Text size="sm">Require user credentials</Text>
<Switch <Switch
checked={server.noCredential} checked={server.noCredential}
disabled={!permissions.isAdmin}
onChange={(e) => onChange={(e) =>
toggleRequiredCredential(e.currentTarget.checked) toggleRequiredCredential(e.currentTarget.checked)
} }
/> />
</Group> </Group>
<Divider my="xl" /> <Divider my="xl" />
{permissions.deleteServer && ( <Button
<Button compact color="red" leftIcon={<RiDeleteBin2Fill />}> compact
Delete server disabled={!permissions.deleteServer}
</Button> leftIcon={<RiDeleteBin2Line color="var(--danger-color)" />}
)} variant="default"
>
Delete server
</Button>
</ServerSection> </ServerSection>
</Stack> </Stack>
</> </>