Skip to content

Commit

Permalink
feat(theme): autocomplete the config with the default theme values
Browse files Browse the repository at this point in the history
  • Loading branch information
AlasDiablo committed Jul 17, 2024
1 parent 4f58b48 commit 2039c3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/api/models/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const getAvailableThemes = () => {
value,
name: theme.name,
description: theme.description,
defaultVariables: theme.customTemplateVariables,
});
});
return toReturn;
Expand Down
28 changes: 24 additions & 4 deletions src/app/js/admin/configTenant/ConfigTenantForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import CancelButton from '../../lib/components/CancelButton';
import { toast } from '../../../../common/tools/toast';
import { loadConfigTenant } from '.';
import { SaveAs } from '@mui/icons-material';
import _ from 'lodash';

const shake = keyframes`
10%, 90% {
Expand Down Expand Up @@ -61,6 +62,7 @@ export const ConfigTenantForm = ({
const [theme, setTheme] = useState('default');
const [themes, setThemes] = useState([
{
defaultVariables: {},
name: {
fr: 'Classique',
en: 'Classic',
Expand Down Expand Up @@ -132,6 +134,27 @@ export const ConfigTenantForm = ({
setConfigTenant(newConfigTenant);
};

const handleThemeChange = (event) => {
setIsFormModified(true);
setTheme(event.target.value);

try {
const themeValue = themes.find(
(value) => value.value === event.target.value,
);

const clonedConfig = _.cloneDeep(JSON.parse(configTenant));

if (clonedConfig.front) {
clonedConfig.front.theme = themeValue.defaultVariables;
}

setConfigTenant(JSON.stringify(clonedConfig, null, 2));
} catch (_) {
/* empty */
}
};

return (
<Box className="container">
<h1>{polyglot.t('config_tenant')}</h1>
Expand Down Expand Up @@ -213,10 +236,7 @@ export const ConfigTenantForm = ({
width: 'min(505px, 100%)',
}}
sx={{ mb: 2 }}
onChange={(event) => {
setIsFormModified(true);
setTheme(event.target.value);
}}
onChange={handleThemeChange}
>
{themes.map((t) => (
<MenuItem key={t.value} value={t.value}>
Expand Down

0 comments on commit 2039c3e

Please sign in to comment.