Skip to content

Commit

Permalink
feat(user-interface): return default app values
Browse files Browse the repository at this point in the history
  • Loading branch information
ridvanakca authored and barinali committed Aug 28, 2023
1 parent 4d4091a commit 473d272
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/web/src/helpers/nestObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import set from 'lodash/set';

export default function nestObject<T = IJSONObject>(
config: IJSONObject | undefined
): Partial<T> {
if (!config) return {};
): Partial<T> | null {
if (!config || Object.keys(config).length === 0) return null;
const result = {};

for (const key in config) {
Expand Down
11 changes: 9 additions & 2 deletions packages/web/src/pages/UserInterface/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import TextField from 'components/TextField';
import useFormatMessage from 'hooks/useFormatMessage';
import ColorInput from 'components/ColorInput';
import nestObject from 'helpers/nestObject';
import { Skeleton } from '@mui/material';
import { Skeleton, useTheme } from '@mui/material';

type UserInterface = {
palette: {
Expand All @@ -31,6 +31,7 @@ type UserInterface = {

export default function UserInterface(): React.ReactElement {
const formatMessage = useFormatMessage();
const theme = useTheme();
const [updateConfig, { loading }] = useMutation(UPDATE_CONFIG, {
refetchQueries: ['GetConfig'],
});
Expand Down Expand Up @@ -83,7 +84,13 @@ export default function UserInterface(): React.ReactElement {
{!configLoading && (
<Form
onSubmit={handleUserInterfaceUpdate}
defaultValues={nestObject<UserInterface>(config)}
defaultValues={
nestObject<UserInterface>(config) || {
'palette.primary.main': theme.palette.primary.main,
'palette.primary.dark': theme.palette.primary.dark,
'palette.primary.light': theme.palette.primary.light,
}
}
>
<Stack direction="column" gap={2}>
<ColorInput
Expand Down

0 comments on commit 473d272

Please sign in to comment.