2022-04-25 23:33:32 +02:00
|
|
|
import {
|
|
|
|
|
useMantineTheme,
|
|
|
|
|
Modal,
|
|
|
|
|
Paper,
|
|
|
|
|
Center,
|
|
|
|
|
Group,
|
|
|
|
|
TextInput,
|
|
|
|
|
Image,
|
|
|
|
|
Button,
|
|
|
|
|
Select,
|
|
|
|
|
AspectRatio,
|
|
|
|
|
Box,
|
|
|
|
|
Text,
|
|
|
|
|
Grid,
|
2022-05-04 07:12:22 +02:00
|
|
|
Card,
|
2022-04-25 23:33:32 +02:00
|
|
|
} from '@mantine/core';
|
|
|
|
|
import { useForm } from '@mantine/hooks';
|
|
|
|
|
import { motion } from 'framer-motion';
|
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
import { Apps } from 'tabler-icons-react';
|
2022-05-03 19:52:09 +02:00
|
|
|
import { useConfig } from '../../tools/state';
|
2022-05-02 15:09:39 +02:00
|
|
|
import { ServiceType, ServiceTypeList } from '../../tools/types';
|
2022-04-25 23:33:32 +02:00
|
|
|
|
|
|
|
|
export default function AddItemShelfItem(props: any) {
|
2022-05-03 19:52:09 +02:00
|
|
|
const { config, addService } = useConfig();
|
2022-04-25 23:33:32 +02:00
|
|
|
const [opened, setOpened] = useState(false);
|
|
|
|
|
const theme = useMantineTheme();
|
|
|
|
|
const form = useForm({
|
|
|
|
|
initialValues: {
|
|
|
|
|
type: 'Other',
|
|
|
|
|
name: '',
|
|
|
|
|
icon: '',
|
|
|
|
|
url: '',
|
2022-05-04 07:12:22 +02:00
|
|
|
apiKey: undefined as unknown as string,
|
2022-04-25 23:33:32 +02:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2022-04-30 21:51:37 +02:00
|
|
|
<Modal
|
|
|
|
|
size="xl"
|
|
|
|
|
radius="lg"
|
|
|
|
|
opened={props.opened || opened}
|
|
|
|
|
onClose={() => setOpened(false)}
|
|
|
|
|
title="Add a service"
|
|
|
|
|
>
|
|
|
|
|
<Center>
|
|
|
|
|
<Image
|
|
|
|
|
height={120}
|
|
|
|
|
width={120}
|
|
|
|
|
src={form.values.icon}
|
|
|
|
|
alt="Placeholder"
|
|
|
|
|
withPlaceholder
|
|
|
|
|
/>
|
|
|
|
|
</Center>
|
|
|
|
|
<form
|
|
|
|
|
onSubmit={form.onSubmit(() => {
|
2022-05-03 19:52:09 +02:00
|
|
|
addService(form.values);
|
2022-04-30 21:51:37 +02:00
|
|
|
setOpened(false);
|
|
|
|
|
form.reset();
|
|
|
|
|
})}
|
|
|
|
|
>
|
|
|
|
|
<Group direction="column" grow>
|
|
|
|
|
<TextInput
|
|
|
|
|
required
|
|
|
|
|
label="Service name"
|
|
|
|
|
placeholder="Plex"
|
|
|
|
|
value={form.values.name}
|
|
|
|
|
onChange={(event) => form.setFieldValue('name', event.currentTarget.value)}
|
|
|
|
|
error={form.errors.name && 'Invalid name'}
|
2022-04-25 23:33:32 +02:00
|
|
|
/>
|
|
|
|
|
|
2022-04-30 21:51:37 +02:00
|
|
|
<TextInput
|
|
|
|
|
required
|
|
|
|
|
label="Icon url"
|
|
|
|
|
placeholder="https://i.gifer.com/ANPC.gif"
|
|
|
|
|
value={form.values.icon}
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
form.setFieldValue('icon', event.currentTarget.value);
|
|
|
|
|
}}
|
|
|
|
|
error={form.errors.icon && 'Icon url is invalid'}
|
|
|
|
|
/>
|
|
|
|
|
<TextInput
|
|
|
|
|
required
|
|
|
|
|
label="Service url"
|
|
|
|
|
placeholder="http://localhost:8989"
|
|
|
|
|
value={form.values.url}
|
|
|
|
|
onChange={(event) => form.setFieldValue('url', event.currentTarget.value)}
|
2022-05-04 07:12:22 +02:00
|
|
|
error={form.errors.url && 'Service url is invalid'}
|
2022-04-30 21:51:37 +02:00
|
|
|
/>
|
|
|
|
|
<Select
|
|
|
|
|
label="Select the type of service (used for API calls)"
|
|
|
|
|
defaultValue="Other"
|
|
|
|
|
placeholder="Pick one"
|
|
|
|
|
value={form.values.type}
|
|
|
|
|
required
|
|
|
|
|
searchable
|
|
|
|
|
onChange={(value) => form.setFieldValue('type', value ?? 'Other')}
|
2022-05-02 15:09:39 +02:00
|
|
|
data={ServiceTypeList}
|
2022-04-30 21:51:37 +02:00
|
|
|
/>
|
2022-05-04 07:12:22 +02:00
|
|
|
{(form.values.type === 'Sonarr' || form.values.type === 'Radarr') && (
|
|
|
|
|
<TextInput
|
|
|
|
|
required
|
|
|
|
|
label="API key"
|
|
|
|
|
placeholder="Your API key"
|
|
|
|
|
value={form.values.apiKey}
|
|
|
|
|
onChange={(event) => form.setFieldValue('apiKey', event.currentTarget.value)}
|
|
|
|
|
error={form.errors.apiKey && 'Invalid API key'}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2022-04-30 21:51:37 +02:00
|
|
|
</Group>
|
2022-04-25 23:33:32 +02:00
|
|
|
|
2022-04-30 21:51:37 +02:00
|
|
|
<Group grow position="center" mt="xl">
|
|
|
|
|
<Button type="submit">Add service</Button>
|
|
|
|
|
</Group>
|
|
|
|
|
</form>
|
2022-04-25 23:33:32 +02:00
|
|
|
</Modal>
|
2022-05-02 18:10:56 +02:00
|
|
|
<AspectRatio
|
|
|
|
|
style={{
|
|
|
|
|
minHeight: 120,
|
|
|
|
|
minWidth: 120,
|
|
|
|
|
}}
|
|
|
|
|
ratio={4 / 3}
|
|
|
|
|
>
|
2022-05-04 07:12:22 +02:00
|
|
|
<Card
|
|
|
|
|
style={{
|
|
|
|
|
|
2022-05-02 18:10:56 +02:00
|
|
|
backgroundColor:
|
2022-05-04 07:12:22 +02:00
|
|
|
theme.colorScheme === 'dark' ? theme.colors.dark[5] : theme.colors.gray[1],
|
|
|
|
|
width: 200,
|
|
|
|
|
height: 180,
|
2022-05-02 18:10:56 +02:00
|
|
|
}}
|
2022-05-04 07:12:22 +02:00
|
|
|
radius="md"
|
2022-05-02 18:10:56 +02:00
|
|
|
>
|
|
|
|
|
<Group direction="column" position="center">
|
|
|
|
|
<motion.div whileHover={{ scale: 1.2 }}>
|
|
|
|
|
<Apps style={{ cursor: 'pointer' }} onClick={() => setOpened(true)} size={60} />
|
|
|
|
|
</motion.div>
|
|
|
|
|
<Text>Add Service</Text>
|
|
|
|
|
</Group>
|
2022-05-04 07:12:22 +02:00
|
|
|
</Card>
|
2022-05-02 18:10:56 +02:00
|
|
|
</AspectRatio>
|
2022-04-25 23:33:32 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|