2024-11-20 17:56:59 -05:00
|
|
|
import type { BrandingOptions } from '@jellyfin/sdk/lib/generated-client/models/branding-options';
|
|
|
|
import { getConfigurationApi } from '@jellyfin/sdk/lib/utils/api/configuration-api';
|
|
|
|
import Alert from '@mui/material/Alert';
|
|
|
|
import Box from '@mui/material/Box';
|
|
|
|
import Button from '@mui/material/Button';
|
|
|
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
|
|
import Stack from '@mui/material/Stack';
|
|
|
|
import Switch from '@mui/material/Switch';
|
|
|
|
import TextField from '@mui/material/TextField';
|
|
|
|
import Typography from '@mui/material/Typography';
|
2025-02-06 05:22:40 +03:00
|
|
|
import React, { useCallback, useState } from 'react';
|
|
|
|
import { type ActionFunctionArgs, Form, useActionData, useNavigation } from 'react-router-dom';
|
2024-11-20 17:56:59 -05:00
|
|
|
|
|
|
|
import { getBrandingOptionsQuery, QUERY_KEY, useBrandingOptions } from 'apps/dashboard/features/branding/api/useBrandingOptions';
|
|
|
|
import Loading from 'components/loading/LoadingComponent';
|
|
|
|
import Page from 'components/Page';
|
|
|
|
import ServerConnections from 'components/ServerConnections';
|
|
|
|
import globalize from 'lib/globalize';
|
|
|
|
import { queryClient } from 'utils/query/queryClient';
|
2024-12-17 23:38:03 +03:00
|
|
|
import { ActionData } from 'types/actionData';
|
2024-11-20 17:56:59 -05:00
|
|
|
|
|
|
|
const BRANDING_CONFIG_KEY = 'branding';
|
|
|
|
const BrandingOption = {
|
|
|
|
CustomCss: 'CustomCss',
|
|
|
|
LoginDisclaimer: 'LoginDisclaimer',
|
|
|
|
SplashscreenEnabled: 'SplashscreenEnabled'
|
|
|
|
};
|
|
|
|
|
|
|
|
export const action = async ({ request }: ActionFunctionArgs) => {
|
|
|
|
const api = ServerConnections.getCurrentApi();
|
|
|
|
if (!api) throw new Error('No Api instance available');
|
|
|
|
|
|
|
|
const formData = await request.formData();
|
|
|
|
const data = Object.fromEntries(formData);
|
|
|
|
|
|
|
|
const brandingOptions: BrandingOptions = {
|
|
|
|
CustomCss: data.CustomCss?.toString(),
|
|
|
|
LoginDisclaimer: data.LoginDisclaimer?.toString(),
|
|
|
|
SplashscreenEnabled: data.SplashscreenEnabled?.toString() === 'on'
|
|
|
|
};
|
|
|
|
|
|
|
|
await getConfigurationApi(api)
|
|
|
|
.updateNamedConfiguration({
|
|
|
|
key: BRANDING_CONFIG_KEY,
|
|
|
|
body: JSON.stringify(brandingOptions)
|
|
|
|
});
|
|
|
|
|
|
|
|
void queryClient.invalidateQueries({
|
|
|
|
queryKey: [ QUERY_KEY ]
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
isSaved: true
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export const loader = () => {
|
|
|
|
return queryClient.ensureQueryData(
|
|
|
|
getBrandingOptionsQuery(ServerConnections.getCurrentApi()));
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Component = () => {
|
2025-02-06 05:22:40 +03:00
|
|
|
const navigation = useNavigation();
|
2024-11-20 17:56:59 -05:00
|
|
|
const actionData = useActionData() as ActionData | undefined;
|
2025-02-06 05:22:40 +03:00
|
|
|
const isSubmitting = navigation.state === 'submitting';
|
2024-11-20 17:56:59 -05:00
|
|
|
|
|
|
|
const {
|
|
|
|
data: defaultBrandingOptions,
|
|
|
|
isPending
|
|
|
|
} = useBrandingOptions();
|
|
|
|
const [ brandingOptions, setBrandingOptions ] = useState(defaultBrandingOptions || {});
|
|
|
|
|
|
|
|
const setSplashscreenEnabled = useCallback((_: React.ChangeEvent<HTMLInputElement>, isEnabled: boolean) => {
|
|
|
|
setBrandingOptions({
|
|
|
|
...brandingOptions,
|
|
|
|
[BrandingOption.SplashscreenEnabled]: isEnabled
|
|
|
|
});
|
|
|
|
}, [ brandingOptions ]);
|
|
|
|
|
|
|
|
const setBrandingOption = useCallback((event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>) => {
|
|
|
|
if (Object.keys(BrandingOption).includes(event.target.name)) {
|
|
|
|
setBrandingOptions({
|
|
|
|
...brandingOptions,
|
|
|
|
[event.target.name]: event.target.value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [ brandingOptions ]);
|
|
|
|
|
|
|
|
if (isPending) return <Loading />;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page
|
|
|
|
id='brandingPage'
|
2025-02-06 05:22:40 +03:00
|
|
|
title={globalize.translate('HeaderBranding')}
|
2024-11-20 17:56:59 -05:00
|
|
|
className='mainAnimatedPage type-interior'
|
|
|
|
>
|
|
|
|
<Box className='content-primary'>
|
2025-02-06 05:22:40 +03:00
|
|
|
<Form method='POST'>
|
2024-11-20 17:56:59 -05:00
|
|
|
<Stack spacing={3}>
|
|
|
|
<Typography variant='h1'>
|
|
|
|
{globalize.translate('HeaderBranding')}
|
|
|
|
</Typography>
|
|
|
|
|
|
|
|
{!isSubmitting && actionData?.isSaved && (
|
|
|
|
<Alert severity='success'>
|
|
|
|
{globalize.translate('SettingsSaved')}
|
|
|
|
</Alert>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<FormControlLabel
|
|
|
|
control={
|
|
|
|
<Switch
|
|
|
|
name={BrandingOption.SplashscreenEnabled}
|
|
|
|
checked={brandingOptions?.SplashscreenEnabled}
|
|
|
|
onChange={setSplashscreenEnabled}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
label={globalize.translate('EnableSplashScreen')}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<TextField
|
|
|
|
fullWidth
|
|
|
|
multiline
|
2024-11-21 14:07:08 -05:00
|
|
|
minRows={5}
|
2024-11-20 17:56:59 -05:00
|
|
|
maxRows={5}
|
|
|
|
name={BrandingOption.LoginDisclaimer}
|
|
|
|
label={globalize.translate('LabelLoginDisclaimer')}
|
|
|
|
helperText={globalize.translate('LabelLoginDisclaimerHelp')}
|
|
|
|
value={brandingOptions?.LoginDisclaimer}
|
|
|
|
onChange={setBrandingOption}
|
2025-03-26 10:33:35 +01:00
|
|
|
slotProps={{
|
|
|
|
input: {
|
|
|
|
className: 'textarea-mono'
|
|
|
|
}
|
|
|
|
}}
|
2024-11-20 17:56:59 -05:00
|
|
|
/>
|
|
|
|
|
|
|
|
<TextField
|
|
|
|
fullWidth
|
|
|
|
multiline
|
2024-11-21 14:07:08 -05:00
|
|
|
minRows={5}
|
2024-11-20 17:56:59 -05:00
|
|
|
maxRows={20}
|
|
|
|
name={BrandingOption.CustomCss}
|
|
|
|
label={globalize.translate('LabelCustomCss')}
|
|
|
|
helperText={globalize.translate('LabelCustomCssHelp')}
|
|
|
|
value={brandingOptions?.CustomCss}
|
|
|
|
onChange={setBrandingOption}
|
2025-03-26 10:33:35 +01:00
|
|
|
slotProps={{
|
|
|
|
input: {
|
|
|
|
className: 'textarea-mono'
|
|
|
|
}
|
|
|
|
}}
|
2024-11-20 17:56:59 -05:00
|
|
|
/>
|
|
|
|
|
|
|
|
<Button
|
|
|
|
type='submit'
|
|
|
|
size='large'
|
|
|
|
>
|
|
|
|
{globalize.translate('Save')}
|
|
|
|
</Button>
|
|
|
|
</Stack>
|
|
|
|
</Form>
|
|
|
|
</Box>
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Component.displayName = 'BrandingPage';
|