-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add server settings for default board, default color scheme and…
… default locale
- Loading branch information
1 parent
0c41241
commit 979794a
Showing
24 changed files
with
439 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
apps/nextjs/src/app/[locale]/manage/settings/_components/appearance-settings-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"use client"; | ||
|
||
import { Group, Text } from "@mantine/core"; | ||
import { IconMoon, IconSun } from "@tabler/icons-react"; | ||
import { SelectWithCustomItems } from "node_modules/@homarr/ui/src/components/select-with-custom-items"; | ||
|
||
import type { ColorScheme } from "@homarr/definitions"; | ||
import { colorSchemes } from "@homarr/definitions"; | ||
import type { ServerSettings } from "@homarr/server-settings"; | ||
|
||
import { CommonSettingsForm } from "./common-form"; | ||
|
||
export const AppearanceSettingsForm = ({ defaultValues }: { defaultValues: ServerSettings["appearance"] }) => { | ||
return ( | ||
<CommonSettingsForm settingKey="appearance" defaultValues={defaultValues}> | ||
{(form) => ( | ||
<> | ||
<SelectWithCustomItems | ||
label="Default color scheme" | ||
data={colorSchemes.map((scheme) => ({ | ||
value: scheme, | ||
label: scheme, | ||
}))} | ||
{...form.getInputProps("defaultColorScheme")} | ||
SelectOption={ApperanceCustomOption} | ||
/> | ||
</> | ||
)} | ||
</CommonSettingsForm> | ||
); | ||
}; | ||
|
||
const appearanceIcons = { | ||
light: IconSun, | ||
dark: IconMoon, | ||
}; | ||
|
||
const ApperanceCustomOption = ({ value, label }: { value: ColorScheme; label: string }) => { | ||
const Icon = appearanceIcons[value]; | ||
|
||
return ( | ||
<Group> | ||
<Icon size={16} stroke={1.5} /> | ||
<Text fz="sm" fw={500}> | ||
{label} | ||
</Text> | ||
</Group> | ||
); | ||
}; |
42 changes: 42 additions & 0 deletions
42
apps/nextjs/src/app/[locale]/manage/settings/_components/board-settings-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use client"; | ||
|
||
import { Group, Text } from "@mantine/core"; | ||
import { IconLayoutDashboard } from "@tabler/icons-react"; | ||
import { SelectWithCustomItems } from "node_modules/@homarr/ui/src/components/select-with-custom-items"; | ||
|
||
import { clientApi } from "@homarr/api/client"; | ||
import type { ServerSettings } from "@homarr/server-settings"; | ||
|
||
import { CommonSettingsForm } from "./common-form"; | ||
|
||
export const BoardSettingsForm = ({ defaultValues }: { defaultValues: ServerSettings["board"] }) => { | ||
const [selectableBoards] = clientApi.board.getPublicBoards.useSuspenseQuery(); | ||
|
||
return ( | ||
<CommonSettingsForm settingKey="board" defaultValues={defaultValues}> | ||
{(form) => ( | ||
<> | ||
<SelectWithCustomItems | ||
label="Global default board" | ||
description="Only public boards are available for selection" | ||
data={selectableBoards.map((board) => ({ | ||
value: board.id, | ||
label: board.name, | ||
image: board.logoImageUrl, | ||
}))} | ||
SelectOption={({ label, image }: { value: string; label: string; image: string | null }) => ( | ||
<Group> | ||
{/* eslint-disable-next-line @next/next/no-img-element */} | ||
{image ? <img width={16} height={16} src={image} alt={label} /> : <IconLayoutDashboard size={16} />} | ||
<Text fz="sm" fw={500}> | ||
{label} | ||
</Text> | ||
</Group> | ||
)} | ||
{...form.getInputProps("defaultBoardId")} | ||
/> | ||
</> | ||
)} | ||
</CommonSettingsForm> | ||
); | ||
}; |
54 changes: 54 additions & 0 deletions
54
apps/nextjs/src/app/[locale]/manage/settings/_components/common-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"use client"; | ||
|
||
import { Button, Group, Stack } from "@mantine/core"; | ||
|
||
import { clientApi } from "@homarr/api/client"; | ||
import { useForm } from "@homarr/form"; | ||
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications"; | ||
import type { ServerSettings } from "@homarr/server-settings"; | ||
|
||
export const CommonSettingsForm = <TKey extends keyof ServerSettings>({ | ||
settingKey, | ||
defaultValues, | ||
children, | ||
}: { | ||
settingKey: TKey; | ||
defaultValues: ServerSettings[TKey]; | ||
children: (form: ReturnType<typeof useForm<ServerSettings[TKey]>>) => React.ReactNode; | ||
}) => { | ||
const { mutateAsync, isPending } = clientApi.serverSettings.saveSettings.useMutation({ | ||
onSuccess() { | ||
showSuccessNotification({ | ||
message: "Settings saved successfully", | ||
}); | ||
}, | ||
onError() { | ||
showErrorNotification({ | ||
message: "Failed to save settings", | ||
}); | ||
}, | ||
}); | ||
const form = useForm({ | ||
initialValues: defaultValues, | ||
}); | ||
|
||
const handleSubmitAsync = async (values: ServerSettings[TKey]) => { | ||
await mutateAsync({ | ||
settingsKey: settingKey, | ||
value: values, | ||
}); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={form.onSubmit((values) => void handleSubmitAsync(values))}> | ||
<Stack gap="sm"> | ||
{children(form)} | ||
<Group justify="end"> | ||
<Button type="submit" loading={isPending}> | ||
Save | ||
</Button> | ||
</Group> | ||
</Stack> | ||
</form> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
apps/nextjs/src/app/[locale]/manage/settings/_components/culture-settings-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use client"; | ||
|
||
import { Group, Text } from "@mantine/core"; | ||
import { SelectWithCustomItems } from "node_modules/@homarr/ui/src/components/select-with-custom-items"; | ||
|
||
import { objectEntries } from "@homarr/common"; | ||
import type { ServerSettings } from "@homarr/server-settings"; | ||
import type { SupportedLanguage } from "@homarr/translation"; | ||
import { localeAttributes } from "@homarr/translation"; | ||
|
||
import { CommonSettingsForm } from "./common-form"; | ||
|
||
export const CultureSettingsForm = ({ defaultValues }: { defaultValues: ServerSettings["culture"] }) => { | ||
return ( | ||
<CommonSettingsForm settingKey="culture" defaultValues={defaultValues}> | ||
{(form) => ( | ||
<> | ||
<SelectWithCustomItems | ||
label="Default locale" | ||
data={objectEntries(localeAttributes).map(([value, { name }]) => ({ | ||
value, | ||
label: name, | ||
}))} | ||
defaultValue={defaultValues.defaultLocale} | ||
SelectOption={({ value, label }: { value: SupportedLanguage; label: string }) => { | ||
const currentConfig = localeAttributes[value]; | ||
|
||
return ( | ||
<Group> | ||
<span className={`fi fi-${currentConfig.flagIcon}`} style={{ borderRadius: 4 }}></span> | ||
<Text fz="sm" fw={500}> | ||
{label} | ||
</Text> | ||
</Group> | ||
); | ||
}} | ||
{...form.getInputProps("defaultLocale")} | ||
/> | ||
</> | ||
)} | ||
</CommonSettingsForm> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.