import { useMantineTheme, Modal, Center, Group, TextInput, Image, Button, Select, AspectRatio, Text, Card, } from '@mantine/core'; import { useForm } from '@mantine/hooks'; import { motion } from 'framer-motion'; import { useState } from 'react'; import { Apps } from 'tabler-icons-react'; import { useConfig } from '../../tools/state'; import { ServiceTypeList } from '../../tools/types'; export default function AddItemShelfItem(props: any) { const { addService } = useConfig(); const [opened, setOpened] = useState(false); const theme = useMantineTheme(); return ( <> setOpened(false)} title="Add a service" > setOpened(true)} size={60} /> Add Service ); } export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & any) { const { setOpened } = props; const { addService, config, setConfig } = useConfig(); const form = useForm({ initialValues: { type: props.type ?? 'Other', name: props.name ?? '', icon: props.icon ?? '', url: props.url ?? '', apiKey: props.apiKey ?? (undefined as unknown as string), }, }); return ( <>
Placeholder
{ // If service already exists, update it. if (config.services && config.services.find((s) => s.name === form.values.name)) { setConfig({ ...config, services: config.services.map((s) => { if (s.name === form.values.name) { return { ...form.values, }; } return s; }), }); } else { addService(form.values); } setOpened(false); form.reset(); })} > form.setFieldValue('name', event.currentTarget.value)} error={form.errors.name && 'Invalid name'} /> { form.setFieldValue('icon', event.currentTarget.value); }} error={form.errors.icon && 'Icon url is invalid'} /> form.setFieldValue('url', event.currentTarget.value)} error={form.errors.url && 'Service url is invalid'} />