2022-12-08 20:42:12 +01:00
|
|
|
import Image from 'next/image';
|
2022-12-05 21:43:47 +01:00
|
|
|
import { createStyles, Flex, Tabs, TextInput } from '@mantine/core';
|
2022-12-04 21:19:40 +01:00
|
|
|
import { UseFormReturnType } from '@mantine/form';
|
|
|
|
|
import { useTranslation } from 'next-i18next';
|
|
|
|
|
import { ServiceType } from '../../../../../../types/service';
|
2022-12-05 21:43:47 +01:00
|
|
|
import { IconSelector } from './IconSelector/IconSelector';
|
2022-12-04 21:19:40 +01:00
|
|
|
|
|
|
|
|
interface AppearanceTabProps {
|
|
|
|
|
form: UseFormReturnType<ServiceType, (values: ServiceType) => ServiceType>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const AppearanceTab = ({ form }: AppearanceTabProps) => {
|
|
|
|
|
const { t } = useTranslation('');
|
2022-12-05 20:04:08 +01:00
|
|
|
const { classes } = useStyles();
|
|
|
|
|
|
2022-12-08 20:42:12 +01:00
|
|
|
const PreviewImage = () => {
|
|
|
|
|
if (form.values.appearance.iconUrl !== undefined && form.values.appearance.iconUrl.length > 0) {
|
2022-12-05 20:04:08 +01:00
|
|
|
// disabled due to too many dynamic targets for next image cache
|
|
|
|
|
// eslint-disable-next-line @next/next/no-img-element
|
2022-12-08 20:42:12 +01:00
|
|
|
return <img className={classes.iconImage} src={form.values.appearance.iconUrl} alt="" />;
|
2022-12-05 20:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-08 20:42:12 +01:00
|
|
|
return (
|
|
|
|
|
<Image
|
|
|
|
|
src="/imgs/logo/logo.png"
|
|
|
|
|
width={20}
|
|
|
|
|
height={20}
|
|
|
|
|
objectFit="contain"
|
|
|
|
|
alt=""
|
|
|
|
|
/>
|
|
|
|
|
);
|
2022-12-05 20:04:08 +01:00
|
|
|
};
|
|
|
|
|
|
2022-12-04 21:19:40 +01:00
|
|
|
return (
|
|
|
|
|
<Tabs.Panel value="appearance" pt="lg">
|
2022-12-05 21:43:47 +01:00
|
|
|
<Flex gap={5}>
|
|
|
|
|
<TextInput
|
|
|
|
|
defaultValue={form.values.appearance.iconUrl}
|
|
|
|
|
className={classes.textInput}
|
2022-12-08 20:42:12 +01:00
|
|
|
icon={<PreviewImage />}
|
2022-12-05 21:43:47 +01:00
|
|
|
label="Service Icon"
|
2022-12-06 20:48:35 +01:00
|
|
|
description="Logo of your service displayed in your dashboard. Must return a body content containg an image"
|
2022-12-05 21:43:47 +01:00
|
|
|
variant="default"
|
|
|
|
|
withAsterisk
|
|
|
|
|
required
|
|
|
|
|
{...form.getInputProps('appearance.iconUrl')}
|
|
|
|
|
/>
|
|
|
|
|
<IconSelector
|
|
|
|
|
onChange={(item) =>
|
|
|
|
|
form.setValues({
|
|
|
|
|
appearance: {
|
|
|
|
|
iconUrl: item.url,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</Flex>
|
2022-12-04 21:19:40 +01:00
|
|
|
</Tabs.Panel>
|
|
|
|
|
);
|
|
|
|
|
};
|
2022-12-05 20:04:08 +01:00
|
|
|
|
|
|
|
|
const useStyles = createStyles(() => ({
|
2022-12-05 21:43:47 +01:00
|
|
|
textInput: {
|
|
|
|
|
flexGrow: 1,
|
|
|
|
|
},
|
2022-12-05 20:04:08 +01:00
|
|
|
iconImage: {
|
|
|
|
|
objectFit: 'contain',
|
|
|
|
|
width: 20,
|
|
|
|
|
height: 20,
|
|
|
|
|
},
|
|
|
|
|
}));
|