Merge branch 'dev' into ajnart/fix-duplicate-users
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -52,3 +52,6 @@ db.sqlite
|
|||||||
|
|
||||||
# logs
|
# logs
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
|
apps/tasks/tasks.cjs
|
||||||
|
apps/websocket/wssServer.cjs
|
||||||
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -6,6 +6,7 @@
|
|||||||
],
|
],
|
||||||
"typescript.tsdk": "node_modules\\typescript\\lib",
|
"typescript.tsdk": "node_modules\\typescript\\lib",
|
||||||
"js/ts.implicitProjectConfig.experimentalDecorators": true,
|
"js/ts.implicitProjectConfig.experimentalDecorators": true,
|
||||||
|
"prettier.configPath": "./tooling/prettier/index.mjs",
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"superjson",
|
"superjson",
|
||||||
"homarr",
|
"homarr",
|
||||||
|
|||||||
@@ -10,19 +10,9 @@ const config = {
|
|||||||
eslint: { ignoreDuringBuilds: true },
|
eslint: { ignoreDuringBuilds: true },
|
||||||
typescript: { ignoreBuildErrors: true },
|
typescript: { ignoreBuildErrors: true },
|
||||||
experimental: {
|
experimental: {
|
||||||
optimizePackageImports: [
|
optimizePackageImports: ["@mantine/core", "@mantine/hooks", "@tabler/icons-react"],
|
||||||
"@mantine/core",
|
|
||||||
"@mantine/hooks",
|
|
||||||
"@tabler/icons-react",
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
transpilePackages: [
|
transpilePackages: ["@homarr/ui", "@homarr/notifications", "@homarr/modals", "@homarr/spotlight", "@homarr/widgets"],
|
||||||
"@homarr/ui",
|
|
||||||
"@homarr/notifications",
|
|
||||||
"@homarr/modals",
|
|
||||||
"@homarr/spotlight",
|
|
||||||
"@homarr/widgets",
|
|
||||||
],
|
|
||||||
images: {
|
images: {
|
||||||
domains: ["cdn.jsdelivr.net"],
|
domains: ["cdn.jsdelivr.net"],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -29,15 +29,16 @@
|
|||||||
"@homarr/ui": "workspace:^0.1.0",
|
"@homarr/ui": "workspace:^0.1.0",
|
||||||
"@homarr/validation": "workspace:^0.1.0",
|
"@homarr/validation": "workspace:^0.1.0",
|
||||||
"@homarr/widgets": "workspace:^0.1.0",
|
"@homarr/widgets": "workspace:^0.1.0",
|
||||||
"@mantine/colors-generator": "^7.9.1",
|
"@mantine/colors-generator": "^7.9.2",
|
||||||
"@mantine/hooks": "^7.9.1",
|
"@mantine/hooks": "^7.9.2",
|
||||||
"@mantine/modals": "^7.9.1",
|
"@mantine/modals": "^7.9.2",
|
||||||
"@mantine/tiptap": "^7.9.1",
|
"@mantine/tiptap": "^7.9.2",
|
||||||
|
"@homarr/server-settings": "workspace:^0.1.0",
|
||||||
"@t3-oss/env-nextjs": "^0.10.1",
|
"@t3-oss/env-nextjs": "^0.10.1",
|
||||||
"@tanstack/react-query": "^5.36.2",
|
"@tanstack/react-query": "^5.37.1",
|
||||||
"@tanstack/react-query-devtools": "^5.36.2",
|
"@tanstack/react-query-devtools": "^5.37.1",
|
||||||
"@tanstack/react-query-next-experimental": "5.36.2",
|
"@tanstack/react-query-next-experimental": "5.37.1",
|
||||||
"@trpc/client": "11.0.0-rc.373",
|
"@trpc/client": "11.0.0-rc.374",
|
||||||
"@trpc/next": "next",
|
"@trpc/next": "next",
|
||||||
"@trpc/react-query": "next",
|
"@trpc/react-query": "next",
|
||||||
"@trpc/server": "next",
|
"@trpc/server": "next",
|
||||||
@@ -47,13 +48,14 @@
|
|||||||
"chroma-js": "^2.4.2",
|
"chroma-js": "^2.4.2",
|
||||||
"dayjs": "^1.11.11",
|
"dayjs": "^1.11.11",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.4.5",
|
||||||
|
"flag-icons": "^7.2.1",
|
||||||
"glob": "^10.3.15",
|
"glob": "^10.3.15",
|
||||||
"jotai": "^2.8.0",
|
"jotai": "^2.8.0",
|
||||||
"next": "^14.2.3",
|
"next": "^14.2.3",
|
||||||
"postcss-preset-mantine": "^1.15.0",
|
"postcss-preset-mantine": "^1.15.0",
|
||||||
"react": "18.3.1",
|
"react": "18.3.1",
|
||||||
"react-dom": "18.3.1",
|
"react-dom": "18.3.1",
|
||||||
"sass": "^1.77.1",
|
"sass": "^1.77.2",
|
||||||
"superjson": "2.2.1",
|
"superjson": "2.2.1",
|
||||||
"use-deep-compare-effect": "^1.8.1"
|
"use-deep-compare-effect": "^1.8.1"
|
||||||
},
|
},
|
||||||
@@ -68,7 +70,7 @@
|
|||||||
"concurrently": "^8.2.2",
|
"concurrently": "^8.2.2",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"prettier": "^3.2.5",
|
"prettier": "^3.2.5",
|
||||||
"tsx": "4.10.3",
|
"tsx": "4.10.5",
|
||||||
"typescript": "^5.4.5"
|
"typescript": "^5.4.5"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ import type { PropsWithChildren } from "react";
|
|||||||
import { defaultLocale } from "@homarr/translation";
|
import { defaultLocale } from "@homarr/translation";
|
||||||
import { I18nProviderClient } from "@homarr/translation/client";
|
import { I18nProviderClient } from "@homarr/translation/client";
|
||||||
|
|
||||||
export const NextInternationalProvider = ({
|
export const NextInternationalProvider = ({ children, locale }: PropsWithChildren<{ locale: string }>) => {
|
||||||
children,
|
|
||||||
locale,
|
|
||||||
}: PropsWithChildren<{ locale: string }>) => {
|
|
||||||
return (
|
return (
|
||||||
<I18nProviderClient locale={locale} fallback={defaultLocale}>
|
<I18nProviderClient locale={locale} fallback={defaultLocale}>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ interface AuthProviderProps {
|
|||||||
session: Session | null;
|
session: Session | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AuthProvider = ({
|
export const AuthProvider = ({ children, session }: PropsWithChildren<AuthProviderProps>) => {
|
||||||
children,
|
|
||||||
session,
|
|
||||||
}: PropsWithChildren<AuthProviderProps>) => {
|
|
||||||
return <SessionProvider session={session}>{children}</SessionProvider>;
|
return <SessionProvider session={session}>{children}</SessionProvider>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,12 +5,7 @@ import { useState } from "react";
|
|||||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||||
import { ReactQueryStreamedHydration } from "@tanstack/react-query-next-experimental";
|
import { ReactQueryStreamedHydration } from "@tanstack/react-query-next-experimental";
|
||||||
import {
|
import { createWSClient, loggerLink, unstable_httpBatchStreamLink, wsLink } from "@trpc/client";
|
||||||
createWSClient,
|
|
||||||
loggerLink,
|
|
||||||
unstable_httpBatchStreamLink,
|
|
||||||
wsLink,
|
|
||||||
} from "@trpc/client";
|
|
||||||
import superjson from "superjson";
|
import superjson from "superjson";
|
||||||
|
|
||||||
import type { AppRouter } from "@homarr/api";
|
import type { AppRouter } from "@homarr/api";
|
||||||
@@ -37,8 +32,7 @@ export function TRPCReactProvider(props: PropsWithChildren) {
|
|||||||
links: [
|
links: [
|
||||||
loggerLink({
|
loggerLink({
|
||||||
enabled: (opts) =>
|
enabled: (opts) =>
|
||||||
process.env.NODE_ENV === "development" ||
|
process.env.NODE_ENV === "development" || (opts.direction === "down" && opts.result instanceof Error),
|
||||||
(opts.direction === "down" && opts.result instanceof Error),
|
|
||||||
}),
|
}),
|
||||||
(args) => {
|
(args) => {
|
||||||
return ({ op, next }) => {
|
return ({ op, next }) => {
|
||||||
@@ -69,9 +63,7 @@ export function TRPCReactProvider(props: PropsWithChildren) {
|
|||||||
return (
|
return (
|
||||||
<clientApi.Provider client={trpcClient} queryClient={queryClient}>
|
<clientApi.Provider client={trpcClient} queryClient={queryClient}>
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<ReactQueryStreamedHydration transformer={superjson}>
|
<ReactQueryStreamedHydration transformer={superjson}>{props.children}</ReactQueryStreamedHydration>
|
||||||
{props.children}
|
|
||||||
</ReactQueryStreamedHydration>
|
|
||||||
<ReactQueryDevtools initialIsOpen={false} />
|
<ReactQueryDevtools initialIsOpen={false} />
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
</clientApi.Provider>
|
</clientApi.Provider>
|
||||||
|
|||||||
@@ -4,11 +4,8 @@ import { useRouter } from "next/navigation";
|
|||||||
import { Button, PasswordInput, Stack, TextInput } from "@mantine/core";
|
import { Button, PasswordInput, Stack, TextInput } from "@mantine/core";
|
||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useForm, zodResolver } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
import type { z } from "@homarr/validation";
|
import type { z } from "@homarr/validation";
|
||||||
import { validation } from "@homarr/validation";
|
import { validation } from "@homarr/validation";
|
||||||
@@ -24,18 +21,15 @@ export const RegistrationForm = ({ invite }: RegistrationFormProps) => {
|
|||||||
const t = useScopedI18n("user");
|
const t = useScopedI18n("user");
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { mutate, isPending } = clientApi.user.register.useMutation();
|
const { mutate, isPending } = clientApi.user.register.useMutation();
|
||||||
const form = useForm<FormType>({
|
const form = useZodForm(validation.user.registration, {
|
||||||
validate: zodResolver(validation.user.registration),
|
|
||||||
initialValues: {
|
initialValues: {
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
confirmPassword: "",
|
confirmPassword: "",
|
||||||
},
|
},
|
||||||
validateInputOnBlur: true,
|
|
||||||
validateInputOnChange: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = (values: FormType) => {
|
const handleSubmit = (values: z.infer<typeof validation.user.registration>) => {
|
||||||
mutate(
|
mutate(
|
||||||
{
|
{
|
||||||
...values,
|
...values,
|
||||||
@@ -69,11 +63,7 @@ export const RegistrationForm = ({ invite }: RegistrationFormProps) => {
|
|||||||
<Stack gap="xl">
|
<Stack gap="xl">
|
||||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||||
<Stack gap="lg">
|
<Stack gap="lg">
|
||||||
<TextInput
|
<TextInput label={t("field.username.label")} autoComplete="off" {...form.getInputProps("username")} />
|
||||||
label={t("field.username.label")}
|
|
||||||
autoComplete="off"
|
|
||||||
{...form.getInputProps("username")}
|
|
||||||
/>
|
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
label={t("field.password.label")}
|
label={t("field.password.label")}
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
@@ -93,5 +83,3 @@ export const RegistrationForm = ({ invite }: RegistrationFormProps) => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
type FormType = z.infer<typeof validation.user.registration>;
|
|
||||||
|
|||||||
@@ -18,18 +18,12 @@ interface InviteUsagePageProps {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function InviteUsagePage({
|
export default async function InviteUsagePage({ params, searchParams }: InviteUsagePageProps) {
|
||||||
params,
|
|
||||||
searchParams,
|
|
||||||
}: InviteUsagePageProps) {
|
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
if (session) notFound();
|
if (session) notFound();
|
||||||
|
|
||||||
const invite = await db.query.invites.findFirst({
|
const invite = await db.query.invites.findFirst({
|
||||||
where: and(
|
where: and(eq(invites.id, params.id), eq(invites.token, searchParams.token)),
|
||||||
eq(invites.id, params.id),
|
|
||||||
eq(invites.token, searchParams.token),
|
|
||||||
),
|
|
||||||
columns: {
|
columns: {
|
||||||
id: true,
|
id: true,
|
||||||
token: true,
|
token: true,
|
||||||
|
|||||||
@@ -2,22 +2,12 @@
|
|||||||
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import {
|
import { Alert, Button, PasswordInput, rem, Stack, TextInput } from "@mantine/core";
|
||||||
Alert,
|
|
||||||
Button,
|
|
||||||
PasswordInput,
|
|
||||||
rem,
|
|
||||||
Stack,
|
|
||||||
TextInput,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import { IconAlertTriangle } from "@tabler/icons-react";
|
import { IconAlertTriangle } from "@tabler/icons-react";
|
||||||
|
|
||||||
import { signIn } from "@homarr/auth/client";
|
import { signIn } from "@homarr/auth/client";
|
||||||
import { useForm, zodResolver } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
import type { z } from "@homarr/validation";
|
import type { z } from "@homarr/validation";
|
||||||
import { validation } from "@homarr/validation";
|
import { validation } from "@homarr/validation";
|
||||||
@@ -27,15 +17,14 @@ export const LoginForm = () => {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [error, setError] = useState<string>();
|
const [error, setError] = useState<string>();
|
||||||
const form = useForm<FormType>({
|
const form = useZodForm(validation.user.signIn, {
|
||||||
validate: zodResolver(validation.user.signIn),
|
|
||||||
initialValues: {
|
initialValues: {
|
||||||
name: "",
|
name: "",
|
||||||
password: "",
|
password: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmitAsync = async (values: FormType) => {
|
const handleSubmitAsync = async (values: z.infer<typeof validation.user.signIn>) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setError(undefined);
|
setError(undefined);
|
||||||
await signIn("credentials", {
|
await signIn("credentials", {
|
||||||
@@ -66,18 +55,10 @@ export const LoginForm = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap="xl">
|
<Stack gap="xl">
|
||||||
<form
|
<form onSubmit={form.onSubmit((values) => void handleSubmitAsync(values))}>
|
||||||
onSubmit={form.onSubmit((values) => void handleSubmitAsync(values))}
|
|
||||||
>
|
|
||||||
<Stack gap="lg">
|
<Stack gap="lg">
|
||||||
<TextInput
|
<TextInput label={t("field.username.label")} {...form.getInputProps("name")} />
|
||||||
label={t("field.username.label")}
|
<PasswordInput label={t("field.password.label")} {...form.getInputProps("password")} />
|
||||||
{...form.getInputProps("name")}
|
|
||||||
/>
|
|
||||||
<PasswordInput
|
|
||||||
label={t("field.password.label")}
|
|
||||||
{...form.getInputProps("password")}
|
|
||||||
/>
|
|
||||||
<Button type="submit" fullWidth loading={isLoading}>
|
<Button type="submit" fullWidth loading={isLoading}>
|
||||||
{t("action.login.label")}
|
{t("action.login.label")}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -92,5 +73,3 @@ export const LoginForm = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
type FormType = z.infer<typeof validation.user.signIn>;
|
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ import { createBoardContentPage } from "../_creator";
|
|||||||
|
|
||||||
export default createBoardContentPage<{ locale: string }>({
|
export default createBoardContentPage<{ locale: string }>({
|
||||||
async getInitialBoardAsync() {
|
async getInitialBoardAsync() {
|
||||||
return await api.board.getDefaultBoard();
|
return await api.board.getHomeBoard();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -18,9 +18,7 @@ export const updateBoardName = (name: string | null) => {
|
|||||||
boardName = name;
|
boardName = name;
|
||||||
};
|
};
|
||||||
|
|
||||||
type UpdateCallback = (
|
type UpdateCallback = (prev: RouterOutputs["board"]["getHomeBoard"]) => RouterOutputs["board"]["getHomeBoard"];
|
||||||
prev: RouterOutputs["board"]["getDefaultBoard"],
|
|
||||||
) => RouterOutputs["board"]["getDefaultBoard"];
|
|
||||||
|
|
||||||
export const useUpdateBoard = () => {
|
export const useUpdateBoard = () => {
|
||||||
const utils = clientApi.useUtils();
|
const utils = clientApi.useUtils();
|
||||||
@@ -46,9 +44,7 @@ export const ClientBoard = () => {
|
|||||||
const board = useRequiredBoard();
|
const board = useRequiredBoard();
|
||||||
const isReady = useIsBoardReady();
|
const isReady = useIsBoardReady();
|
||||||
|
|
||||||
const sortedSections = board.sections.sort(
|
const sortedSections = board.sections.sort((sectionA, sectionB) => sectionA.position - sectionB.position);
|
||||||
(sectionA, sectionB) => sectionA.position - sectionB.position,
|
|
||||||
);
|
|
||||||
|
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
@@ -61,24 +57,12 @@ export const ClientBoard = () => {
|
|||||||
loaderProps={{ size: "lg" }}
|
loaderProps={{ size: "lg" }}
|
||||||
h={fullHeightWithoutHeaderAndFooter}
|
h={fullHeightWithoutHeaderAndFooter}
|
||||||
/>
|
/>
|
||||||
<Stack
|
<Stack ref={ref} h="100%" style={{ visibility: isReady ? "visible" : "hidden" }}>
|
||||||
ref={ref}
|
|
||||||
h="100%"
|
|
||||||
style={{ visibility: isReady ? "visible" : "hidden" }}
|
|
||||||
>
|
|
||||||
{sortedSections.map((section) =>
|
{sortedSections.map((section) =>
|
||||||
section.kind === "empty" ? (
|
section.kind === "empty" ? (
|
||||||
<BoardEmptySection
|
<BoardEmptySection key={section.id} section={section} mainRef={ref} />
|
||||||
key={section.id}
|
|
||||||
section={section}
|
|
||||||
mainRef={ref}
|
|
||||||
/>
|
|
||||||
) : (
|
) : (
|
||||||
<BoardCategorySection
|
<BoardCategorySection key={section.id} section={section} mainRef={ref} />
|
||||||
key={section.id}
|
|
||||||
section={section}
|
|
||||||
mainRef={ref}
|
|
||||||
/>
|
|
||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import type { PropsWithChildren } from "react";
|
import type { PropsWithChildren } from "react";
|
||||||
import {
|
import { createContext, useCallback, useContext, useEffect, useState } from "react";
|
||||||
createContext,
|
|
||||||
useCallback,
|
|
||||||
useContext,
|
|
||||||
useEffect,
|
|
||||||
useState,
|
|
||||||
} from "react";
|
|
||||||
import { usePathname } from "next/navigation";
|
import { usePathname } from "next/navigation";
|
||||||
|
|
||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
@@ -16,7 +10,7 @@ import { clientApi } from "@homarr/api/client";
|
|||||||
import { updateBoardName } from "./_client";
|
import { updateBoardName } from "./_client";
|
||||||
|
|
||||||
const BoardContext = createContext<{
|
const BoardContext = createContext<{
|
||||||
board: RouterOutputs["board"]["getDefaultBoard"];
|
board: RouterOutputs["board"]["getHomeBoard"];
|
||||||
isReady: boolean;
|
isReady: boolean;
|
||||||
markAsReady: (id: string) => void;
|
markAsReady: (id: string) => void;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
@@ -52,18 +46,12 @@ export const BoardProvider = ({
|
|||||||
}, [pathname, utils, initialBoard.name]);
|
}, [pathname, utils, initialBoard.name]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setReadySections((previous) =>
|
setReadySections((previous) => previous.filter((id) => data.sections.some((section) => section.id === id)));
|
||||||
previous.filter((id) =>
|
|
||||||
data.sections.some((section) => section.id === id),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [data.sections.length, setReadySections]);
|
}, [data.sections.length, setReadySections]);
|
||||||
|
|
||||||
const markAsReady = useCallback((id: string) => {
|
const markAsReady = useCallback((id: string) => {
|
||||||
setReadySections((previous) =>
|
setReadySections((previous) => (previous.includes(id) ? previous : [...previous, id]));
|
||||||
previous.includes(id) ? previous : [...previous, id],
|
|
||||||
);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
|
|
||||||
import { capitalize } from "@homarr/common";
|
|
||||||
|
|
||||||
// Placed here because gridstack styles are used for board content
|
// Placed here because gridstack styles are used for board content
|
||||||
import "~/styles/gridstack.scss";
|
import "~/styles/gridstack.scss";
|
||||||
|
|
||||||
|
import { getI18n } from "@homarr/translation/server";
|
||||||
|
|
||||||
|
import { createMetaTitle } from "~/metadata";
|
||||||
import { createBoardLayout } from "../_layout-creator";
|
import { createBoardLayout } from "../_layout-creator";
|
||||||
import type { Board } from "../_types";
|
import type { Board } from "../_types";
|
||||||
import { ClientBoard } from "./_client";
|
import { ClientBoard } from "./_client";
|
||||||
@@ -17,9 +18,7 @@ interface Props<TParams extends Params> {
|
|||||||
getInitialBoardAsync: (params: TParams) => Promise<Board>;
|
getInitialBoardAsync: (params: TParams) => Promise<Board>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createBoardContentPage = <
|
export const createBoardContentPage = <TParams extends Record<string, unknown>>({
|
||||||
TParams extends Record<string, unknown>,
|
|
||||||
>({
|
|
||||||
getInitialBoardAsync: getInitialBoard,
|
getInitialBoardAsync: getInitialBoard,
|
||||||
}: Props<TParams>) => {
|
}: Props<TParams>) => {
|
||||||
return {
|
return {
|
||||||
@@ -31,16 +30,13 @@ export const createBoardContentPage = <
|
|||||||
page: () => {
|
page: () => {
|
||||||
return <ClientBoard />;
|
return <ClientBoard />;
|
||||||
},
|
},
|
||||||
generateMetadataAsync: async ({
|
generateMetadataAsync: async ({ params }: { params: TParams }): Promise<Metadata> => {
|
||||||
params,
|
|
||||||
}: {
|
|
||||||
params: TParams;
|
|
||||||
}): Promise<Metadata> => {
|
|
||||||
try {
|
try {
|
||||||
const board = await getInitialBoard(params);
|
const board = await getInitialBoard(params);
|
||||||
|
const t = await getI18n();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: board.metaTitle ?? `${capitalize(board.name)} board | Homarr`,
|
title: board.metaTitle ?? createMetaTitle(t("board.content.metaTitle", { boardName: board.name })),
|
||||||
icons: {
|
icons: {
|
||||||
icon: board.faviconImageUrl ? board.faviconImageUrl : undefined,
|
icon: board.faviconImageUrl ? board.faviconImageUrl : undefined,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useRequiredBoard } from "./_context";
|
||||||
|
|
||||||
|
export const CustomCss = () => {
|
||||||
|
const board = useRequiredBoard();
|
||||||
|
|
||||||
|
return <style>{board.customCss}</style>;
|
||||||
|
};
|
||||||
@@ -16,10 +16,7 @@ import { useAtom, useAtomValue } from "jotai";
|
|||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useModalAction } from "@homarr/modals";
|
import { useModalAction } from "@homarr/modals";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
import { revalidatePathActionAsync } from "~/app/revalidatePathAction";
|
import { revalidatePathActionAsync } from "~/app/revalidatePathAction";
|
||||||
@@ -54,8 +51,7 @@ export const BoardContentHeaderActions = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const AddMenu = () => {
|
const AddMenu = () => {
|
||||||
const { openModal: openCategoryEditModal } =
|
const { openModal: openCategoryEditModal } = useModalAction(CategoryEditModal);
|
||||||
useModalAction(CategoryEditModal);
|
|
||||||
const { openModal: openItemSelectModal } = useModalAction(ItemSelectModal);
|
const { openModal: openItemSelectModal } = useModalAction(ItemSelectModal);
|
||||||
const { addCategoryToEnd } = useCategoryActions();
|
const { addCategoryToEnd } = useCategoryActions();
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
@@ -95,22 +91,14 @@ const AddMenu = () => {
|
|||||||
</HeaderButton>
|
</HeaderButton>
|
||||||
</Menu.Target>
|
</Menu.Target>
|
||||||
<Menu.Dropdown style={{ transform: "translate(-3px, 0)" }}>
|
<Menu.Dropdown style={{ transform: "translate(-3px, 0)" }}>
|
||||||
<Menu.Item
|
<Menu.Item leftSection={<IconBox size={20} />} onClick={handleSelectItem}>
|
||||||
leftSection={<IconBox size={20} />}
|
|
||||||
onClick={handleSelectItem}
|
|
||||||
>
|
|
||||||
{t("item.action.create")}
|
{t("item.action.create")}
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
<Menu.Item leftSection={<IconPackageImport size={20} />}>
|
<Menu.Item leftSection={<IconPackageImport size={20} />}>{t("item.action.import")}</Menu.Item>
|
||||||
{t("item.action.import")}
|
|
||||||
</Menu.Item>
|
|
||||||
|
|
||||||
<Menu.Divider />
|
<Menu.Divider />
|
||||||
|
|
||||||
<Menu.Item
|
<Menu.Item leftSection={<IconBoxAlignTop size={20} />} onClick={handleAddCategory}>
|
||||||
leftSection={<IconBoxAlignTop size={20} />}
|
|
||||||
onClick={handleAddCategory}
|
|
||||||
>
|
|
||||||
{t("section.category.action.create")}
|
{t("section.category.action.create")}
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
</Menu.Dropdown>
|
</Menu.Dropdown>
|
||||||
@@ -123,24 +111,23 @@ const EditModeMenu = () => {
|
|||||||
const board = useRequiredBoard();
|
const board = useRequiredBoard();
|
||||||
const utils = clientApi.useUtils();
|
const utils = clientApi.useUtils();
|
||||||
const t = useScopedI18n("board.action.edit");
|
const t = useScopedI18n("board.action.edit");
|
||||||
const { mutate: saveBoard, isPending } =
|
const { mutate: saveBoard, isPending } = clientApi.board.saveBoard.useMutation({
|
||||||
clientApi.board.saveBoard.useMutation({
|
onSuccess() {
|
||||||
onSuccess() {
|
showSuccessNotification({
|
||||||
showSuccessNotification({
|
title: t("notification.success.title"),
|
||||||
title: t("notification.success.title"),
|
message: t("notification.success.message"),
|
||||||
message: t("notification.success.message"),
|
});
|
||||||
});
|
void utils.board.getBoardByName.invalidate({ name: board.name });
|
||||||
void utils.board.getBoardByName.invalidate({ name: board.name });
|
void revalidatePathActionAsync(`/boards/${board.name}`);
|
||||||
void revalidatePathActionAsync(`/boards/${board.name}`);
|
setEditMode(false);
|
||||||
setEditMode(false);
|
},
|
||||||
},
|
onError() {
|
||||||
onError() {
|
showErrorNotification({
|
||||||
showErrorNotification({
|
title: t("notification.error.title"),
|
||||||
title: t("notification.error.title"),
|
message: t("notification.error.message"),
|
||||||
message: t("notification.error.message"),
|
});
|
||||||
});
|
},
|
||||||
},
|
});
|
||||||
});
|
|
||||||
|
|
||||||
const toggle = useCallback(() => {
|
const toggle = useCallback(() => {
|
||||||
if (isEditMode) return saveBoard(board);
|
if (isEditMode) return saveBoard(board);
|
||||||
@@ -149,11 +136,7 @@ const EditModeMenu = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<HeaderButton onClick={toggle} loading={isPending}>
|
<HeaderButton onClick={toggle} loading={isPending}>
|
||||||
{isEditMode ? (
|
{isEditMode ? <IconPencilOff stroke={1.5} /> : <IconPencil stroke={1.5} />}
|
||||||
<IconPencilOff stroke={1.5} />
|
|
||||||
) : (
|
|
||||||
<IconPencil stroke={1.5} />
|
|
||||||
)}
|
|
||||||
</HeaderButton>
|
</HeaderButton>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,9 +22,7 @@ export const BoardMantineProvider = ({ children }: PropsWithChildren) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const generateColors = (hex: string) => {
|
export const generateColors = (hex: string) => {
|
||||||
const lightnessForColors = [
|
const lightnessForColors = [-0.25, -0.2, -0.15, -0.1, -0.05, 0, 0.05, 0.1, 0.15, 0.2] as const;
|
||||||
-0.25, -0.2, -0.15, -0.1, -0.05, 0, 0.05, 0.1, 0.15, 0.2,
|
|
||||||
] as const;
|
|
||||||
const rgbaColors = lightnessForColors.map((lightness) => {
|
const rgbaColors = lightnessForColors.map((lightness) => {
|
||||||
if (lightness < 0) {
|
if (lightness < 0) {
|
||||||
return lighten(hex, -lightness);
|
return lighten(hex, -lightness);
|
||||||
|
|||||||
@@ -44,11 +44,7 @@ export const AccessSettingsContent = ({ board, initialPermissions }: Props) => {
|
|||||||
<Tabs.List grow>
|
<Tabs.List grow>
|
||||||
<TabItem value="user" count={counts.user} icon={IconUser} />
|
<TabItem value="user" count={counts.user} icon={IconUser} />
|
||||||
<TabItem value="group" count={counts.group} icon={IconUsersGroup} />
|
<TabItem value="group" count={counts.group} icon={IconUsersGroup} />
|
||||||
<TabItem
|
<TabItem value="inherited" count={initialPermissions.inherited.length} icon={IconUserDown} />
|
||||||
value="inherited"
|
|
||||||
count={initialPermissions.inherited.length}
|
|
||||||
icon={IconUserDown}
|
|
||||||
/>
|
|
||||||
</Tabs.List>
|
</Tabs.List>
|
||||||
|
|
||||||
<Tabs.Panel value="user">
|
<Tabs.Panel value="user">
|
||||||
|
|||||||
@@ -1,21 +1,8 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import type { SelectProps } from "@mantine/core";
|
import type { SelectProps } from "@mantine/core";
|
||||||
import {
|
import { Button, Flex, Group, Select, TableTd, TableTr, Text } from "@mantine/core";
|
||||||
Button,
|
import { IconCheck, IconEye, IconPencil, IconSettings } from "@tabler/icons-react";
|
||||||
Flex,
|
|
||||||
Group,
|
|
||||||
Select,
|
|
||||||
TableTd,
|
|
||||||
TableTr,
|
|
||||||
Text,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import {
|
|
||||||
IconCheck,
|
|
||||||
IconEye,
|
|
||||||
IconPencil,
|
|
||||||
IconSettings,
|
|
||||||
} from "@tabler/icons-react";
|
|
||||||
|
|
||||||
import type { BoardPermission } from "@homarr/definitions";
|
import type { BoardPermission } from "@homarr/definitions";
|
||||||
import { boardPermissions } from "@homarr/definitions";
|
import { boardPermissions } from "@homarr/definitions";
|
||||||
@@ -38,12 +25,7 @@ interface BoardAccessSelectRowProps {
|
|||||||
onCountChange: OnCountChange;
|
onCountChange: OnCountChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BoardAccessSelectRow = ({
|
export const BoardAccessSelectRow = ({ itemContent, permission, index, onCountChange }: BoardAccessSelectRowProps) => {
|
||||||
itemContent,
|
|
||||||
permission,
|
|
||||||
index,
|
|
||||||
onCountChange,
|
|
||||||
}: BoardAccessSelectRowProps) => {
|
|
||||||
const tRoot = useI18n();
|
const tRoot = useI18n();
|
||||||
const tPermissions = useScopedI18n("board.setting.section.access.permission");
|
const tPermissions = useScopedI18n("board.setting.section.access.permission");
|
||||||
const form = useFormContext();
|
const form = useFormContext();
|
||||||
@@ -61,11 +43,7 @@ export const BoardAccessSelectRow = ({
|
|||||||
<TableTr>
|
<TableTr>
|
||||||
<TableTd w={{ sm: 128, lg: 256 }}>{itemContent}</TableTd>
|
<TableTd w={{ sm: 128, lg: 256 }}>{itemContent}</TableTd>
|
||||||
<TableTd>
|
<TableTd>
|
||||||
<Flex
|
<Flex direction={{ base: "column", xs: "row" }} align={{ base: "end", xs: "center" }} wrap="nowrap">
|
||||||
direction={{ base: "column", xs: "row" }}
|
|
||||||
align={{ base: "end", xs: "center" }}
|
|
||||||
wrap="nowrap"
|
|
||||||
>
|
|
||||||
<Select
|
<Select
|
||||||
allowDeselect={false}
|
allowDeselect={false}
|
||||||
flex="1"
|
flex="1"
|
||||||
@@ -93,10 +71,7 @@ interface BoardAccessDisplayRowProps {
|
|||||||
permission: BoardPermission | "board-full";
|
permission: BoardPermission | "board-full";
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BoardAccessDisplayRow = ({
|
export const BoardAccessDisplayRow = ({ itemContent, permission }: BoardAccessDisplayRowProps) => {
|
||||||
itemContent,
|
|
||||||
permission,
|
|
||||||
}: BoardAccessDisplayRowProps) => {
|
|
||||||
const tPermissions = useScopedI18n("board.setting.section.access.permission");
|
const tPermissions = useScopedI18n("board.setting.section.access.permission");
|
||||||
const Icon = icons[permission];
|
const Icon = icons[permission];
|
||||||
|
|
||||||
@@ -106,10 +81,7 @@ export const BoardAccessDisplayRow = ({
|
|||||||
<TableTd>
|
<TableTd>
|
||||||
<Group gap={0}>
|
<Group gap={0}>
|
||||||
<Flex w={34} h={34} align="center" justify="center">
|
<Flex w={34} h={34} align="center" justify="center">
|
||||||
<Icon
|
<Icon size="1rem" color="var(--input-section-color, var(--mantine-color-dimmed))" />
|
||||||
size="1rem"
|
|
||||||
color="var(--input-section-color, var(--mantine-color-dimmed))"
|
|
||||||
/>
|
|
||||||
</Flex>
|
</Flex>
|
||||||
<Text size="sm">{tPermissions(`item.${permission}.label`)}</Text>
|
<Text size="sm">{tPermissions(`item.${permission}.label`)}</Text>
|
||||||
</Group>
|
</Group>
|
||||||
@@ -131,9 +103,7 @@ const RenderOption: SelectProps["renderOption"] = ({ option, checked }) => {
|
|||||||
<Group flex="1" gap="xs" wrap="nowrap">
|
<Group flex="1" gap="xs" wrap="nowrap">
|
||||||
<Icon {...iconProps} />
|
<Icon {...iconProps} />
|
||||||
{option.label}
|
{option.label}
|
||||||
{checked && (
|
{checked && <IconCheck style={{ marginInlineStart: "auto" }} {...iconProps} />}
|
||||||
<IconCheck style={{ marginInlineStart: "auto" }} {...iconProps} />
|
|
||||||
)}
|
|
||||||
</Group>
|
</Group>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ export interface BoardAccessFormType {
|
|||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const [FormProvider, useFormContext, useForm] =
|
export const [FormProvider, useFormContext, useForm] = createFormContext<BoardAccessFormType>();
|
||||||
createFormContext<BoardAccessFormType>();
|
|
||||||
|
|
||||||
export type OnCountChange = (callback: (prev: number) => number) => void;
|
export type OnCountChange = (callback: (prev: number) => number) => void;
|
||||||
|
|||||||
@@ -1,16 +1,6 @@
|
|||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import {
|
import { Anchor, Button, Group, Stack, Table, TableTbody, TableTh, TableThead, TableTr } from "@mantine/core";
|
||||||
Anchor,
|
|
||||||
Button,
|
|
||||||
Group,
|
|
||||||
Stack,
|
|
||||||
Table,
|
|
||||||
TableTbody,
|
|
||||||
TableTh,
|
|
||||||
TableThead,
|
|
||||||
TableTr,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import { IconPlus } from "@tabler/icons-react";
|
import { IconPlus } from "@tabler/icons-react";
|
||||||
|
|
||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
@@ -24,30 +14,21 @@ import { FormProvider, useForm } from "./form";
|
|||||||
import { GroupSelectModal } from "./group-select-modal";
|
import { GroupSelectModal } from "./group-select-modal";
|
||||||
import type { FormProps } from "./user-access";
|
import type { FormProps } from "./user-access";
|
||||||
|
|
||||||
export const GroupsForm = ({
|
export const GroupsForm = ({ board, initialPermissions, onCountChange }: FormProps) => {
|
||||||
board,
|
const { mutate, isPending } = clientApi.board.saveGroupBoardPermissions.useMutation();
|
||||||
initialPermissions,
|
|
||||||
onCountChange,
|
|
||||||
}: FormProps) => {
|
|
||||||
const { mutate, isPending } =
|
|
||||||
clientApi.board.saveGroupBoardPermissions.useMutation();
|
|
||||||
const utils = clientApi.useUtils();
|
const utils = clientApi.useUtils();
|
||||||
const [groups, setGroups] = useState<Map<string, Group>>(
|
const [groups, setGroups] = useState<Map<string, Group>>(
|
||||||
new Map(
|
new Map(initialPermissions.groupPermissions.map(({ group }) => [group.id, group])),
|
||||||
initialPermissions.groupPermissions.map(({ group }) => [group.id, group]),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
const { openModal } = useModalAction(GroupSelectModal);
|
const { openModal } = useModalAction(GroupSelectModal);
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const tPermissions = useScopedI18n("board.setting.section.access.permission");
|
const tPermissions = useScopedI18n("board.setting.section.access.permission");
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
items: initialPermissions.groupPermissions.map(
|
items: initialPermissions.groupPermissions.map(({ group, permission }) => ({
|
||||||
({ group, permission }) => ({
|
itemId: group.id,
|
||||||
itemId: group.id,
|
permission,
|
||||||
permission,
|
})),
|
||||||
}),
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -92,9 +73,7 @@ export const GroupsForm = ({
|
|||||||
<Table>
|
<Table>
|
||||||
<TableThead>
|
<TableThead>
|
||||||
<TableTr>
|
<TableTr>
|
||||||
<TableTh style={{ whiteSpace: "nowrap" }}>
|
<TableTh style={{ whiteSpace: "nowrap" }}>{tPermissions("field.group.label")}</TableTh>
|
||||||
{tPermissions("field.group.label")}
|
|
||||||
</TableTh>
|
|
||||||
<TableTh>{tPermissions("field.permission.label")}</TableTh>
|
<TableTh>{tPermissions("field.permission.label")}</TableTh>
|
||||||
</TableTr>
|
</TableTr>
|
||||||
</TableThead>
|
</TableThead>
|
||||||
@@ -102,9 +81,7 @@ export const GroupsForm = ({
|
|||||||
{form.values.items.map((row, index) => (
|
{form.values.items.map((row, index) => (
|
||||||
<BoardAccessSelectRow
|
<BoardAccessSelectRow
|
||||||
key={row.itemId}
|
key={row.itemId}
|
||||||
itemContent={
|
itemContent={<GroupItemContent group={groups.get(row.itemId)!} />}
|
||||||
<GroupItemContent group={groups.get(row.itemId)!} />
|
|
||||||
}
|
|
||||||
permission={row.permission}
|
permission={row.permission}
|
||||||
index={index}
|
index={index}
|
||||||
onCountChange={onCountChange}
|
onCountChange={onCountChange}
|
||||||
@@ -114,11 +91,7 @@ export const GroupsForm = ({
|
|||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
<Group justify="space-between">
|
<Group justify="space-between">
|
||||||
<Button
|
<Button rightSection={<IconPlus size="1rem" />} variant="light" onClick={handleAddUser}>
|
||||||
rightSection={<IconPlus size="1rem" />}
|
|
||||||
variant="light"
|
|
||||||
onClick={handleAddUser}
|
|
||||||
>
|
|
||||||
{t("common.action.add")}
|
{t("common.action.add")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" loading={isPending} color="teal">
|
<Button type="submit" loading={isPending} color="teal">
|
||||||
@@ -133,16 +106,10 @@ export const GroupsForm = ({
|
|||||||
|
|
||||||
export const GroupItemContent = ({ group }: { group: Group }) => {
|
export const GroupItemContent = ({ group }: { group: Group }) => {
|
||||||
return (
|
return (
|
||||||
<Anchor
|
<Anchor component={Link} href={`/manage/users/groups/${group.id}`} size="sm" style={{ whiteSpace: "nowrap" }}>
|
||||||
component={Link}
|
|
||||||
href={`/manage/users/groups/${group.id}`}
|
|
||||||
size="sm"
|
|
||||||
style={{ whiteSpace: "nowrap" }}
|
|
||||||
>
|
|
||||||
{group.name}
|
{group.name}
|
||||||
</Anchor>
|
</Anchor>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
type Group =
|
type Group = RouterOutputs["board"]["getBoardPermissions"]["groupPermissions"][0]["group"];
|
||||||
RouterOutputs["board"]["getBoardPermissions"]["groupPermissions"][0]["group"];
|
|
||||||
|
|||||||
@@ -16,59 +16,52 @@ interface GroupSelectFormType {
|
|||||||
groupId: string;
|
groupId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GroupSelectModal = createModal<InnerProps>(
|
export const GroupSelectModal = createModal<InnerProps>(({ actions, innerProps }) => {
|
||||||
({ actions, innerProps }) => {
|
const t = useI18n();
|
||||||
const t = useI18n();
|
const { data: groups, isPending } = clientApi.group.selectable.useQuery();
|
||||||
const { data: groups, isPending } = clientApi.group.selectable.useQuery();
|
const [loading, setLoading] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const form = useForm<GroupSelectFormType>();
|
||||||
const form = useForm<GroupSelectFormType>();
|
const handleSubmitAsync = async (values: GroupSelectFormType) => {
|
||||||
const handleSubmitAsync = async (values: GroupSelectFormType) => {
|
const currentGroup = groups?.find((group) => group.id === values.groupId);
|
||||||
const currentGroup = groups?.find((group) => group.id === values.groupId);
|
if (!currentGroup) return;
|
||||||
if (!currentGroup) return;
|
setLoading(true);
|
||||||
setLoading(true);
|
await innerProps.onSelect({
|
||||||
await innerProps.onSelect({
|
id: currentGroup.id,
|
||||||
id: currentGroup.id,
|
name: currentGroup.name,
|
||||||
name: currentGroup.name,
|
});
|
||||||
});
|
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
actions.closeModal();
|
actions.closeModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmLabel = innerProps.confirmLabel ?? t("common.action.add");
|
const confirmLabel = innerProps.confirmLabel ?? t("common.action.add");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form
|
<form onSubmit={form.onSubmit((values) => void handleSubmitAsync(values))}>
|
||||||
onSubmit={form.onSubmit((values) => void handleSubmitAsync(values))}
|
<Stack>
|
||||||
>
|
<Select
|
||||||
<Stack>
|
{...form.getInputProps("groupId")}
|
||||||
<Select
|
label={t("group.action.select.label")}
|
||||||
{...form.getInputProps("groupId")}
|
clearable
|
||||||
label={t("group.action.select.label")}
|
searchable
|
||||||
clearable
|
leftSection={isPending ? <Loader size="xs" /> : undefined}
|
||||||
searchable
|
nothingFoundMessage={t("group.action.select.notFound")}
|
||||||
leftSection={isPending ? <Loader size="xs" /> : undefined}
|
limit={5}
|
||||||
nothingFoundMessage={t("group.action.select.notFound")}
|
data={groups
|
||||||
limit={5}
|
?.filter((group) => !innerProps.presentGroupIds.includes(group.id))
|
||||||
data={groups
|
.map((group) => ({ value: group.id, label: group.name }))}
|
||||||
?.filter(
|
/>
|
||||||
(group) => !innerProps.presentGroupIds.includes(group.id),
|
<Group justify="end">
|
||||||
)
|
<Button variant="default" onClick={actions.closeModal}>
|
||||||
.map((group) => ({ value: group.id, label: group.name }))}
|
{t("common.action.cancel")}
|
||||||
/>
|
</Button>
|
||||||
<Group justify="end">
|
<Button type="submit" loading={loading}>
|
||||||
<Button variant="default" onClick={actions.closeModal}>
|
{confirmLabel}
|
||||||
{t("common.action.cancel")}
|
</Button>
|
||||||
</Button>
|
</Group>
|
||||||
<Button type="submit" loading={loading}>
|
</Stack>
|
||||||
{confirmLabel}
|
</form>
|
||||||
</Button>
|
);
|
||||||
</Group>
|
}).withOptions({
|
||||||
</Stack>
|
defaultTitle: (t) => t("board.setting.section.access.permission.groupSelect.title"),
|
||||||
</form>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
).withOptions({
|
|
||||||
defaultTitle: (t) =>
|
|
||||||
t("board.setting.section.access.permission.groupSelect.title"),
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
import {
|
import { Stack, Table, TableTbody, TableTh, TableThead, TableTr } from "@mantine/core";
|
||||||
Stack,
|
|
||||||
Table,
|
|
||||||
TableTbody,
|
|
||||||
TableTh,
|
|
||||||
TableThead,
|
|
||||||
TableTr,
|
|
||||||
} from "@mantine/core";
|
|
||||||
|
|
||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
import { getPermissionsWithChildren } from "@homarr/definitions";
|
import { getPermissionsWithChildren } from "@homarr/definitions";
|
||||||
@@ -41,9 +34,7 @@ export const InheritTable = ({ initialPermissions }: InheritTableProps) => {
|
|||||||
const boardPermission =
|
const boardPermission =
|
||||||
permission in mapPermissions
|
permission in mapPermissions
|
||||||
? mapPermissions[permission as keyof typeof mapPermissions]
|
? mapPermissions[permission as keyof typeof mapPermissions]
|
||||||
: getPermissionsWithChildren([permission]).includes(
|
: getPermissionsWithChildren([permission]).includes("board-full-access")
|
||||||
"board-full-access",
|
|
||||||
)
|
|
||||||
? "board-full"
|
? "board-full"
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,6 @@
|
|||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import {
|
import { Anchor, Box, Button, Group, Stack, Table, TableTbody, TableTh, TableThead, TableTr } from "@mantine/core";
|
||||||
Anchor,
|
|
||||||
Box,
|
|
||||||
Button,
|
|
||||||
Group,
|
|
||||||
Stack,
|
|
||||||
Table,
|
|
||||||
TableTbody,
|
|
||||||
TableTh,
|
|
||||||
TableThead,
|
|
||||||
TableTr,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import { IconPlus } from "@tabler/icons-react";
|
import { IconPlus } from "@tabler/icons-react";
|
||||||
|
|
||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
@@ -21,10 +10,7 @@ import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
|||||||
import { UserAvatar } from "@homarr/ui";
|
import { UserAvatar } from "@homarr/ui";
|
||||||
|
|
||||||
import type { Board } from "../../../_types";
|
import type { Board } from "../../../_types";
|
||||||
import {
|
import { BoardAccessDisplayRow, BoardAccessSelectRow } from "./board-access-table-rows";
|
||||||
BoardAccessDisplayRow,
|
|
||||||
BoardAccessSelectRow,
|
|
||||||
} from "./board-access-table-rows";
|
|
||||||
import type { BoardAccessFormType, OnCountChange } from "./form";
|
import type { BoardAccessFormType, OnCountChange } from "./form";
|
||||||
import { FormProvider, useForm } from "./form";
|
import { FormProvider, useForm } from "./form";
|
||||||
import { UserSelectModal } from "./user-select-modal";
|
import { UserSelectModal } from "./user-select-modal";
|
||||||
@@ -35,18 +21,11 @@ export interface FormProps {
|
|||||||
onCountChange: OnCountChange;
|
onCountChange: OnCountChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UsersForm = ({
|
export const UsersForm = ({ board, initialPermissions, onCountChange }: FormProps) => {
|
||||||
board,
|
const { mutate, isPending } = clientApi.board.saveUserBoardPermissions.useMutation();
|
||||||
initialPermissions,
|
|
||||||
onCountChange,
|
|
||||||
}: FormProps) => {
|
|
||||||
const { mutate, isPending } =
|
|
||||||
clientApi.board.saveUserBoardPermissions.useMutation();
|
|
||||||
const utils = clientApi.useUtils();
|
const utils = clientApi.useUtils();
|
||||||
const [users, setUsers] = useState<Map<string, User>>(
|
const [users, setUsers] = useState<Map<string, User>>(
|
||||||
new Map(
|
new Map(initialPermissions.userPermissions.map(({ user }) => [user.id, user])),
|
||||||
initialPermissions.userPermissions.map(({ user }) => [user.id, user]),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
const { openModal } = useModalAction(UserSelectModal);
|
const { openModal } = useModalAction(UserSelectModal);
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
@@ -81,9 +60,7 @@ export const UsersForm = ({
|
|||||||
const presentUserIds = form.values.items.map(({ itemId: id }) => id);
|
const presentUserIds = form.values.items.map(({ itemId: id }) => id);
|
||||||
|
|
||||||
openModal({
|
openModal({
|
||||||
presentUserIds: board.creatorId
|
presentUserIds: board.creatorId ? presentUserIds.concat(board.creatorId) : presentUserIds,
|
||||||
? presentUserIds.concat(board.creatorId)
|
|
||||||
: presentUserIds,
|
|
||||||
onSelect: (user) => {
|
onSelect: (user) => {
|
||||||
setUsers((prev) => new Map(prev).set(user.id, user));
|
setUsers((prev) => new Map(prev).set(user.id, user));
|
||||||
form.setFieldValue("items", [
|
form.setFieldValue("items", [
|
||||||
@@ -111,17 +88,12 @@ export const UsersForm = ({
|
|||||||
</TableThead>
|
</TableThead>
|
||||||
<TableTbody>
|
<TableTbody>
|
||||||
{board.creator && (
|
{board.creator && (
|
||||||
<BoardAccessDisplayRow
|
<BoardAccessDisplayRow itemContent={<UserItemContent user={board.creator} />} permission="board-full" />
|
||||||
itemContent={<UserItemContent user={board.creator} />}
|
|
||||||
permission="board-full"
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
{form.values.items.map((row, index) => (
|
{form.values.items.map((row, index) => (
|
||||||
<BoardAccessSelectRow
|
<BoardAccessSelectRow
|
||||||
key={row.itemId}
|
key={row.itemId}
|
||||||
itemContent={
|
itemContent={<UserItemContent user={users.get(row.itemId)!} />}
|
||||||
<UserItemContent user={users.get(row.itemId)!} />
|
|
||||||
}
|
|
||||||
permission={row.permission}
|
permission={row.permission}
|
||||||
index={index}
|
index={index}
|
||||||
onCountChange={onCountChange}
|
onCountChange={onCountChange}
|
||||||
@@ -131,11 +103,7 @@ export const UsersForm = ({
|
|||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
<Group justify="space-between">
|
<Group justify="space-between">
|
||||||
<Button
|
<Button rightSection={<IconPlus size="1rem" />} variant="light" onClick={handleAddUser}>
|
||||||
rightSection={<IconPlus size="1rem" />}
|
|
||||||
variant="light"
|
|
||||||
onClick={handleAddUser}
|
|
||||||
>
|
|
||||||
{t("common.action.add")}
|
{t("common.action.add")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" loading={isPending} color="teal">
|
<Button type="submit" loading={isPending} color="teal">
|
||||||
@@ -154,12 +122,7 @@ const UserItemContent = ({ user }: { user: User }) => {
|
|||||||
<Box visibleFrom="xs">
|
<Box visibleFrom="xs">
|
||||||
<UserAvatar user={user} size="sm" />
|
<UserAvatar user={user} size="sm" />
|
||||||
</Box>
|
</Box>
|
||||||
<Anchor
|
<Anchor component={Link} href={`/manage/users/${user.id}`} size="sm" style={{ whiteSpace: "nowrap" }}>
|
||||||
component={Link}
|
|
||||||
href={`/manage/users/${user.id}`}
|
|
||||||
size="sm"
|
|
||||||
style={{ whiteSpace: "nowrap" }}
|
|
||||||
>
|
|
||||||
{user.name}
|
{user.name}
|
||||||
</Anchor>
|
</Anchor>
|
||||||
</Group>
|
</Group>
|
||||||
|
|||||||
@@ -12,11 +12,7 @@ import { UserAvatar } from "@homarr/ui";
|
|||||||
|
|
||||||
interface InnerProps {
|
interface InnerProps {
|
||||||
presentUserIds: string[];
|
presentUserIds: string[];
|
||||||
onSelect: (props: {
|
onSelect: (props: { id: string; name: string; image: string }) => void | Promise<void>;
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
image: string;
|
|
||||||
}) => void | Promise<void>;
|
|
||||||
confirmLabel?: string;
|
confirmLabel?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,68 +20,59 @@ interface UserSelectFormType {
|
|||||||
userId: string;
|
userId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UserSelectModal = createModal<InnerProps>(
|
export const UserSelectModal = createModal<InnerProps>(({ actions, innerProps }) => {
|
||||||
({ actions, innerProps }) => {
|
const t = useI18n();
|
||||||
const t = useI18n();
|
const { data: users, isPending } = clientApi.user.selectable.useQuery();
|
||||||
const { data: users, isPending } = clientApi.user.selectable.useQuery();
|
const [loading, setLoading] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const form = useForm<UserSelectFormType>();
|
||||||
const form = useForm<UserSelectFormType>();
|
const handleSubmitAsync = async (values: UserSelectFormType) => {
|
||||||
const handleSubmitAsync = async (values: UserSelectFormType) => {
|
const currentUser = users?.find((user) => user.id === values.userId);
|
||||||
const currentUser = users?.find((user) => user.id === values.userId);
|
if (!currentUser) return;
|
||||||
if (!currentUser) return;
|
setLoading(true);
|
||||||
setLoading(true);
|
await innerProps.onSelect({
|
||||||
await innerProps.onSelect({
|
id: currentUser.id,
|
||||||
id: currentUser.id,
|
name: currentUser.name ?? "",
|
||||||
name: currentUser.name ?? "",
|
image: currentUser.image ?? "",
|
||||||
image: currentUser.image ?? "",
|
});
|
||||||
});
|
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
actions.closeModal();
|
actions.closeModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmLabel = innerProps.confirmLabel ?? t("common.action.add");
|
const confirmLabel = innerProps.confirmLabel ?? t("common.action.add");
|
||||||
const currentUser = users?.find((user) => user.id === form.values.userId);
|
const currentUser = users?.find((user) => user.id === form.values.userId);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form
|
<form onSubmit={form.onSubmit((values) => void handleSubmitAsync(values))}>
|
||||||
onSubmit={form.onSubmit((values) => void handleSubmitAsync(values))}
|
<Stack>
|
||||||
>
|
<Select
|
||||||
<Stack>
|
{...form.getInputProps("userId")}
|
||||||
<Select
|
label={t("user.action.select.label")}
|
||||||
{...form.getInputProps("userId")}
|
searchable
|
||||||
label={t("user.action.select.label")}
|
clearable
|
||||||
searchable
|
leftSection={
|
||||||
clearable
|
isPending ? <Loader size="xs" /> : currentUser ? <UserAvatar user={currentUser} size="xs" /> : undefined
|
||||||
leftSection={
|
}
|
||||||
isPending ? (
|
nothingFoundMessage={t("user.action.select.notFound")}
|
||||||
<Loader size="xs" />
|
renderOption={createRenderOption(users ?? [])}
|
||||||
) : currentUser ? (
|
limit={5}
|
||||||
<UserAvatar user={currentUser} size="xs" />
|
data={users
|
||||||
) : undefined
|
?.filter((user) => !innerProps.presentUserIds.includes(user.id))
|
||||||
}
|
.map((user) => ({ value: user.id, label: user.name ?? "" }))}
|
||||||
nothingFoundMessage={t("user.action.select.notFound")}
|
/>
|
||||||
renderOption={createRenderOption(users ?? [])}
|
<Group justify="end">
|
||||||
limit={5}
|
<Button variant="default" onClick={actions.closeModal}>
|
||||||
data={users
|
{t("common.action.cancel")}
|
||||||
?.filter((user) => !innerProps.presentUserIds.includes(user.id))
|
</Button>
|
||||||
.map((user) => ({ value: user.id, label: user.name ?? "" }))}
|
<Button type="submit" loading={loading}>
|
||||||
/>
|
{confirmLabel}
|
||||||
<Group justify="end">
|
</Button>
|
||||||
<Button variant="default" onClick={actions.closeModal}>
|
</Group>
|
||||||
{t("common.action.cancel")}
|
</Stack>
|
||||||
</Button>
|
</form>
|
||||||
<Button type="submit" loading={loading}>
|
);
|
||||||
{confirmLabel}
|
}).withOptions({
|
||||||
</Button>
|
defaultTitle: (t) => t("board.setting.section.access.permission.userSelect.title"),
|
||||||
</Group>
|
|
||||||
</Stack>
|
|
||||||
</form>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
).withOptions({
|
|
||||||
defaultTitle: (t) =>
|
|
||||||
t("board.setting.section.access.permission.userSelect.title"),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const iconProps = {
|
const iconProps = {
|
||||||
@@ -95,9 +82,7 @@ const iconProps = {
|
|||||||
size: "1rem",
|
size: "1rem",
|
||||||
};
|
};
|
||||||
|
|
||||||
const createRenderOption = (
|
const createRenderOption = (users: RouterOutputs["user"]["selectable"]): SelectProps["renderOption"] =>
|
||||||
users: RouterOutputs["user"]["selectable"],
|
|
||||||
): SelectProps["renderOption"] =>
|
|
||||||
function InnerRenderRoot({ option, checked }) {
|
function InnerRenderRoot({ option, checked }) {
|
||||||
const user = users.find((user) => user.id === option.value);
|
const user = users.find((user) => user.id === option.value);
|
||||||
if (!user) return null;
|
if (!user) return null;
|
||||||
@@ -106,9 +91,7 @@ const createRenderOption = (
|
|||||||
<Group flex="1" gap="xs">
|
<Group flex="1" gap="xs">
|
||||||
<UserAvatar user={user} size="xs" />
|
<UserAvatar user={user} size="xs" />
|
||||||
{option.label}
|
{option.label}
|
||||||
{checked && (
|
{checked && <IconCheck style={{ marginInlineStart: "auto" }} {...iconProps} />}
|
||||||
<IconCheck style={{ marginInlineStart: "auto" }} {...iconProps} />
|
|
||||||
)}
|
|
||||||
</Group>
|
</Group>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,16 +2,13 @@
|
|||||||
|
|
||||||
import { Button, Grid, Group, Stack, TextInput } from "@mantine/core";
|
import { Button, Grid, Group, Stack, TextInput } from "@mantine/core";
|
||||||
|
|
||||||
import {
|
import { backgroundImageAttachments, backgroundImageRepeats, backgroundImageSizes } from "@homarr/definitions";
|
||||||
backgroundImageAttachments,
|
import { useZodForm } from "@homarr/form";
|
||||||
backgroundImageRepeats,
|
|
||||||
backgroundImageSizes,
|
|
||||||
} from "@homarr/definitions";
|
|
||||||
import { useForm } from "@homarr/form";
|
|
||||||
import type { TranslationObject } from "@homarr/translation";
|
import type { TranslationObject } from "@homarr/translation";
|
||||||
import { useI18n } from "@homarr/translation/client";
|
import { useI18n } from "@homarr/translation/client";
|
||||||
import type { SelectItemWithDescriptionBadge } from "@homarr/ui";
|
import type { SelectItemWithDescriptionBadge } from "@homarr/ui";
|
||||||
import { SelectWithDescriptionBadge } from "@homarr/ui";
|
import { SelectWithDescriptionBadge } from "@homarr/ui";
|
||||||
|
import { validation } from "@homarr/validation";
|
||||||
|
|
||||||
import type { Board } from "../../_types";
|
import type { Board } from "../../_types";
|
||||||
import { useSavePartialSettingsMutation } from "./_shared";
|
import { useSavePartialSettingsMutation } from "./_shared";
|
||||||
@@ -21,9 +18,8 @@ interface Props {
|
|||||||
}
|
}
|
||||||
export const BackgroundSettingsContent = ({ board }: Props) => {
|
export const BackgroundSettingsContent = ({ board }: Props) => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const { mutate: savePartialSettings, isPending } =
|
const { mutate: savePartialSettings, isPending } = useSavePartialSettingsMutation(board);
|
||||||
useSavePartialSettingsMutation(board);
|
const form = useZodForm(validation.board.savePartialSettings, {
|
||||||
const form = useForm({
|
|
||||||
initialValues: {
|
initialValues: {
|
||||||
backgroundImageUrl: board.backgroundImageUrl ?? "",
|
backgroundImageUrl: board.backgroundImageUrl ?? "",
|
||||||
backgroundImageAttachment: board.backgroundImageAttachment,
|
backgroundImageAttachment: board.backgroundImageAttachment,
|
||||||
@@ -36,14 +32,8 @@ export const BackgroundSettingsContent = ({ board }: Props) => {
|
|||||||
"backgroundImageAttachment",
|
"backgroundImageAttachment",
|
||||||
backgroundImageAttachments,
|
backgroundImageAttachments,
|
||||||
);
|
);
|
||||||
const backgroundImageSizeData = useBackgroundOptionData(
|
const backgroundImageSizeData = useBackgroundOptionData("backgroundImageSize", backgroundImageSizes);
|
||||||
"backgroundImageSize",
|
const backgroundImageRepeatData = useBackgroundOptionData("backgroundImageRepeat", backgroundImageRepeats);
|
||||||
backgroundImageSizes,
|
|
||||||
);
|
|
||||||
const backgroundImageRepeatData = useBackgroundOptionData(
|
|
||||||
"backgroundImageRepeat",
|
|
||||||
backgroundImageRepeats,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
@@ -95,13 +85,9 @@ export const BackgroundSettingsContent = ({ board }: Props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
type BackgroundImageKey =
|
type BackgroundImageKey = "backgroundImageAttachment" | "backgroundImageSize" | "backgroundImageRepeat";
|
||||||
| "backgroundImageAttachment"
|
|
||||||
| "backgroundImageSize"
|
|
||||||
| "backgroundImageRepeat";
|
|
||||||
|
|
||||||
type inferOptions<TKey extends BackgroundImageKey> =
|
type inferOptions<TKey extends BackgroundImageKey> = TranslationObject["board"]["field"][TKey]["option"];
|
||||||
TranslationObject["board"]["field"][TKey]["option"];
|
|
||||||
|
|
||||||
const useBackgroundOptionData = <
|
const useBackgroundOptionData = <
|
||||||
TKey extends BackgroundImageKey,
|
TKey extends BackgroundImageKey,
|
||||||
@@ -119,9 +105,7 @@ const useBackgroundOptionData = <
|
|||||||
(value) =>
|
(value) =>
|
||||||
({
|
({
|
||||||
label: t(`board.field.${key}.option.${value as string}.label` as never),
|
label: t(`board.field.${key}.option.${value as string}.label` as never),
|
||||||
description: t(
|
description: t(`board.field.${key}.option.${value as string}.description` as never),
|
||||||
`board.field.${key}.option.${value as string}.description` as never,
|
|
||||||
),
|
|
||||||
value: value as string,
|
value: value as string,
|
||||||
badge:
|
badge:
|
||||||
data.defaultValue === value
|
data.defaultValue === value
|
||||||
|
|||||||
@@ -17,8 +17,9 @@ import {
|
|||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { useDisclosure } from "@mantine/hooks";
|
import { useDisclosure } from "@mantine/hooks";
|
||||||
|
|
||||||
import { useForm } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import { useI18n } from "@homarr/translation/client";
|
import { useI18n } from "@homarr/translation/client";
|
||||||
|
import { validation } from "@homarr/validation";
|
||||||
|
|
||||||
import type { Board } from "../../_types";
|
import type { Board } from "../../_types";
|
||||||
import { generateColors } from "../../(content)/_theme";
|
import { generateColors } from "../../(content)/_theme";
|
||||||
@@ -33,7 +34,7 @@ const hexRegex = /^#[0-9a-fA-F]{6}$/;
|
|||||||
const progressPercentageLabel = (value: number) => `${value}%`;
|
const progressPercentageLabel = (value: number) => `${value}%`;
|
||||||
|
|
||||||
export const ColorSettingsContent = ({ board }: Props) => {
|
export const ColorSettingsContent = ({ board }: Props) => {
|
||||||
const form = useForm({
|
const form = useZodForm(validation.board.savePartialSettings, {
|
||||||
initialValues: {
|
initialValues: {
|
||||||
primaryColor: board.primaryColor,
|
primaryColor: board.primaryColor,
|
||||||
secondaryColor: board.secondaryColor,
|
secondaryColor: board.secondaryColor,
|
||||||
@@ -43,8 +44,7 @@ export const ColorSettingsContent = ({ board }: Props) => {
|
|||||||
const [showPreview, { toggle }] = useDisclosure(false);
|
const [showPreview, { toggle }] = useDisclosure(false);
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const theme = useMantineTheme();
|
const theme = useMantineTheme();
|
||||||
const { mutate: savePartialSettings, isPending } =
|
const { mutate: savePartialSettings, isPending } = useSavePartialSettingsMutation(board);
|
||||||
useSavePartialSettingsMutation(board);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
@@ -76,11 +76,7 @@ export const ColorSettingsContent = ({ board }: Props) => {
|
|||||||
/>
|
/>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={12}>
|
<Grid.Col span={12}>
|
||||||
<Anchor onClick={toggle}>
|
<Anchor onClick={toggle}>{showPreview ? t("common.preview.hide") : t("common.preview.show")}</Anchor>
|
||||||
{showPreview
|
|
||||||
? t("common.preview.hide")
|
|
||||||
: t("common.preview.show")}
|
|
||||||
</Anchor>
|
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={12}>
|
<Grid.Col span={12}>
|
||||||
<Collapse in={showPreview}>
|
<Collapse in={showPreview}>
|
||||||
@@ -114,15 +110,13 @@ export const ColorSettingsContent = ({ board }: Props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface ColorsPreviewProps {
|
interface ColorsPreviewProps {
|
||||||
previewColor: string;
|
previewColor: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ColorsPreview = ({ previewColor }: ColorsPreviewProps) => {
|
const ColorsPreview = ({ previewColor }: ColorsPreviewProps) => {
|
||||||
const theme = useMantineTheme();
|
const theme = useMantineTheme();
|
||||||
|
|
||||||
const colors = hexRegex.test(previewColor)
|
const colors = previewColor && hexRegex.test(previewColor) ? generateColors(previewColor) : generateColors("#000000");
|
||||||
? generateColors(previewColor)
|
|
||||||
: generateColors("#000000");
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Group gap={0} wrap="nowrap">
|
<Group gap={0} wrap="nowrap">
|
||||||
|
|||||||
@@ -1,7 +1,91 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
// TODO: add some sort of store (maybe directory on GitHub)
|
import { Alert, Button, Group, Input, Stack } from "@mantine/core";
|
||||||
|
import { highlight, languages } from "prismjs";
|
||||||
|
import Editor from "react-simple-code-editor";
|
||||||
|
|
||||||
export const CustomCssSettingsContent = () => {
|
import "~/styles/prismjs.scss";
|
||||||
return null;
|
|
||||||
|
import { IconInfoCircle } from "@tabler/icons-react";
|
||||||
|
|
||||||
|
import { useForm } from "@homarr/form";
|
||||||
|
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
|
import type { Board } from "../../_types";
|
||||||
|
import { useSavePartialSettingsMutation } from "./_shared";
|
||||||
|
import classes from "./customcss.module.css";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
board: Board;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CustomCssSettingsContent = ({ board }: Props) => {
|
||||||
|
const t = useI18n();
|
||||||
|
const customCssT = useScopedI18n("board.field.customCss");
|
||||||
|
const { mutate: savePartialSettings, isPending } = useSavePartialSettingsMutation(board);
|
||||||
|
const form = useForm({
|
||||||
|
initialValues: {
|
||||||
|
customCss: board.customCss ?? "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form
|
||||||
|
onSubmit={form.onSubmit((values) => {
|
||||||
|
savePartialSettings({
|
||||||
|
id: board.id,
|
||||||
|
...values,
|
||||||
|
});
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<Stack>
|
||||||
|
<CustomCssInput {...form.getInputProps("customCss")} />
|
||||||
|
|
||||||
|
<Alert variant="light" color="cyan" title={customCssT("customClassesAlert.title")} icon={<IconInfoCircle />}>
|
||||||
|
{customCssT("customClassesAlert.description")}
|
||||||
|
</Alert>
|
||||||
|
|
||||||
|
<Group justify="end">
|
||||||
|
<Button type="submit" loading={isPending} color="teal">
|
||||||
|
{t("common.action.saveChanges")}
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
interface CustomCssInputProps {
|
||||||
|
value?: string;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CustomCssInput = ({ value, onChange }: CustomCssInputProps) => {
|
||||||
|
const customCssT = useScopedI18n("board.field.customCss");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Input.Wrapper
|
||||||
|
label={customCssT("label")}
|
||||||
|
labelProps={{
|
||||||
|
htmlFor: "custom-css",
|
||||||
|
}}
|
||||||
|
description={customCssT("description")}
|
||||||
|
inputWrapperOrder={["label", "description", "input", "error"]}
|
||||||
|
>
|
||||||
|
<div className={classes.codeEditorRoot}>
|
||||||
|
<Editor
|
||||||
|
textareaId="custom-css"
|
||||||
|
onValueChange={onChange}
|
||||||
|
value={value ?? ""}
|
||||||
|
highlight={(code) => highlight(code, languages.extend("css", {}), "css")}
|
||||||
|
padding={10}
|
||||||
|
style={{
|
||||||
|
fontFamily: '"Fira code", "Fira Mono", monospace',
|
||||||
|
fontSize: 12,
|
||||||
|
minHeight: 250,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Input.Wrapper>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ export const DangerZoneSettingsContent = () => {
|
|||||||
const { openModal } = useModalAction(BoardRenameModal);
|
const { openModal } = useModalAction(BoardRenameModal);
|
||||||
const { mutate: changeVisibility, isPending: isChangeVisibilityPending } =
|
const { mutate: changeVisibility, isPending: isChangeVisibilityPending } =
|
||||||
clientApi.board.changeBoardVisibility.useMutation();
|
clientApi.board.changeBoardVisibility.useMutation();
|
||||||
const { mutate: deleteBoard, isPending: isDeletePending } =
|
const { mutate: deleteBoard, isPending: isDeletePending } = clientApi.board.deleteBoard.useMutation();
|
||||||
clientApi.board.deleteBoard.useMutation();
|
|
||||||
const utils = clientApi.useUtils();
|
const utils = clientApi.useUtils();
|
||||||
const visibility = board.isPublic ? "public" : "private";
|
const visibility = board.isPublic ? "public" : "private";
|
||||||
|
|
||||||
@@ -37,12 +36,8 @@ export const DangerZoneSettingsContent = () => {
|
|||||||
|
|
||||||
const onVisibilityClick = useCallback(() => {
|
const onVisibilityClick = useCallback(() => {
|
||||||
openConfirmModal({
|
openConfirmModal({
|
||||||
title: t(
|
title: t(`section.dangerZone.action.visibility.confirm.${visibility}.title`),
|
||||||
`section.dangerZone.action.visibility.confirm.${visibility}.title`,
|
children: t(`section.dangerZone.action.visibility.confirm.${visibility}.description`),
|
||||||
),
|
|
||||||
children: t(
|
|
||||||
`section.dangerZone.action.visibility.confirm.${visibility}.description`,
|
|
||||||
),
|
|
||||||
onConfirm: () => {
|
onConfirm: () => {
|
||||||
changeVisibility(
|
changeVisibility(
|
||||||
{
|
{
|
||||||
@@ -52,7 +47,7 @@ export const DangerZoneSettingsContent = () => {
|
|||||||
{
|
{
|
||||||
onSettled() {
|
onSettled() {
|
||||||
void utils.board.getBoardByName.invalidate({ name: board.name });
|
void utils.board.getBoardByName.invalidate({ name: board.name });
|
||||||
void utils.board.getDefaultBoard.invalidate();
|
void utils.board.getHomeBoard.invalidate();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -64,7 +59,7 @@ export const DangerZoneSettingsContent = () => {
|
|||||||
changeVisibility,
|
changeVisibility,
|
||||||
t,
|
t,
|
||||||
utils.board.getBoardByName,
|
utils.board.getBoardByName,
|
||||||
utils.board.getDefaultBoard,
|
utils.board.getHomeBoard,
|
||||||
visibility,
|
visibility,
|
||||||
openConfirmModal,
|
openConfirmModal,
|
||||||
]);
|
]);
|
||||||
@@ -98,12 +93,8 @@ export const DangerZoneSettingsContent = () => {
|
|||||||
<Divider />
|
<Divider />
|
||||||
<DangerZoneRow
|
<DangerZoneRow
|
||||||
label={t("section.dangerZone.action.visibility.label")}
|
label={t("section.dangerZone.action.visibility.label")}
|
||||||
description={t(
|
description={t(`section.dangerZone.action.visibility.description.${visibility}`)}
|
||||||
`section.dangerZone.action.visibility.description.${visibility}`,
|
buttonText={t(`section.dangerZone.action.visibility.button.${visibility}`)}
|
||||||
)}
|
|
||||||
buttonText={t(
|
|
||||||
`section.dangerZone.action.visibility.button.${visibility}`,
|
|
||||||
)}
|
|
||||||
onClick={onVisibilityClick}
|
onClick={onVisibilityClick}
|
||||||
isPending={isChangeVisibilityPending}
|
isPending={isChangeVisibilityPending}
|
||||||
/>
|
/>
|
||||||
@@ -127,13 +118,7 @@ interface DangerZoneRowProps {
|
|||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DangerZoneRow = ({
|
const DangerZoneRow = ({ label, description, buttonText, onClick, isPending }: DangerZoneRowProps) => {
|
||||||
label,
|
|
||||||
description,
|
|
||||||
buttonText,
|
|
||||||
onClick,
|
|
||||||
isPending,
|
|
||||||
}: DangerZoneRowProps) => {
|
|
||||||
return (
|
return (
|
||||||
<Group justify="space-between" px="md" className={classes.dangerZoneGroup}>
|
<Group justify="space-between" px="md" className={classes.dangerZoneGroup}>
|
||||||
<Stack gap={0}>
|
<Stack gap={0}>
|
||||||
@@ -143,12 +128,7 @@ const DangerZoneRow = ({
|
|||||||
<Text size="sm">{description}</Text>
|
<Text size="sm">{description}</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Group justify="end" w={{ base: "100%", xs: "auto" }}>
|
<Group justify="end" w={{ base: "100%", xs: "auto" }}>
|
||||||
<Button
|
<Button variant="subtle" color="red" loading={isPending} onClick={onClick}>
|
||||||
variant="subtle"
|
|
||||||
color="red"
|
|
||||||
loading={isPending}
|
|
||||||
onClick={onClick}
|
|
||||||
>
|
|
||||||
{buttonText}
|
{buttonText}
|
||||||
</Button>
|
</Button>
|
||||||
</Group>
|
</Group>
|
||||||
|
|||||||
@@ -1,25 +1,15 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import {
|
import { Button, Grid, Group, Loader, Stack, TextInput, Tooltip } from "@mantine/core";
|
||||||
Button,
|
import { useDebouncedValue, useDocumentTitle, useFavicon } from "@mantine/hooks";
|
||||||
Grid,
|
|
||||||
Group,
|
|
||||||
Loader,
|
|
||||||
Stack,
|
|
||||||
TextInput,
|
|
||||||
Tooltip,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import {
|
|
||||||
useDebouncedValue,
|
|
||||||
useDocumentTitle,
|
|
||||||
useFavicon,
|
|
||||||
} from "@mantine/hooks";
|
|
||||||
import { IconAlertTriangle } from "@tabler/icons-react";
|
import { IconAlertTriangle } from "@tabler/icons-react";
|
||||||
|
|
||||||
import { useForm } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import { useI18n } from "@homarr/translation/client";
|
import { useI18n } from "@homarr/translation/client";
|
||||||
|
import { validation } from "@homarr/validation";
|
||||||
|
|
||||||
|
import { createMetaTitle } from "~/metadata";
|
||||||
import type { Board } from "../../_types";
|
import type { Board } from "../../_types";
|
||||||
import { useUpdateBoard } from "../../(content)/_client";
|
import { useUpdateBoard } from "../../(content)/_client";
|
||||||
import { useSavePartialSettingsMutation } from "./_shared";
|
import { useSavePartialSettingsMutation } from "./_shared";
|
||||||
@@ -36,22 +26,31 @@ export const GeneralSettingsContent = ({ board }: Props) => {
|
|||||||
});
|
});
|
||||||
const { updateBoard } = useUpdateBoard();
|
const { updateBoard } = useUpdateBoard();
|
||||||
|
|
||||||
const { mutate: savePartialSettings, isPending } =
|
const { mutate: savePartialSettings, isPending } = useSavePartialSettingsMutation(board);
|
||||||
useSavePartialSettingsMutation(board);
|
const form = useZodForm(
|
||||||
const form = useForm({
|
validation.board.savePartialSettings
|
||||||
initialValues: {
|
.pick({
|
||||||
pageTitle: board.pageTitle ?? "",
|
pageTitle: true,
|
||||||
logoImageUrl: board.logoImageUrl ?? "",
|
logoImageUrl: true,
|
||||||
metaTitle: board.metaTitle ?? "",
|
metaTitle: true,
|
||||||
faviconImageUrl: board.faviconImageUrl ?? "",
|
faviconImageUrl: true,
|
||||||
|
})
|
||||||
|
.required(),
|
||||||
|
{
|
||||||
|
initialValues: {
|
||||||
|
pageTitle: board.pageTitle ?? "",
|
||||||
|
logoImageUrl: board.logoImageUrl ?? "",
|
||||||
|
metaTitle: board.metaTitle ?? "",
|
||||||
|
faviconImageUrl: board.faviconImageUrl ?? "",
|
||||||
|
},
|
||||||
|
onValuesChange({ pageTitle }) {
|
||||||
|
updateBoard((previous) => ({
|
||||||
|
...previous,
|
||||||
|
pageTitle,
|
||||||
|
}));
|
||||||
|
},
|
||||||
},
|
},
|
||||||
onValuesChange({ pageTitle }) {
|
);
|
||||||
updateBoard((previous) => ({
|
|
||||||
...previous,
|
|
||||||
pageTitle,
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const metaTitleStatus = useMetaTitlePreview(form.values.metaTitle);
|
const metaTitleStatus = useMetaTitlePreview(form.values.metaTitle);
|
||||||
const faviconStatus = useFaviconPreview(form.values.faviconImageUrl);
|
const faviconStatus = useFaviconPreview(form.values.faviconImageUrl);
|
||||||
@@ -94,7 +93,7 @@ export const GeneralSettingsContent = ({ board }: Props) => {
|
|||||||
<Grid.Col span={{ xs: 12, md: 6 }}>
|
<Grid.Col span={{ xs: 12, md: 6 }}>
|
||||||
<TextInput
|
<TextInput
|
||||||
label={t("board.field.metaTitle.label")}
|
label={t("board.field.metaTitle.label")}
|
||||||
placeholder="Default Board | Homarr"
|
placeholder={createMetaTitle(t("board.content.metaTitle", { boardName: board.name }))}
|
||||||
rightSection={<PendingOrInvalidIndicator {...metaTitleStatus} />}
|
rightSection={<PendingOrInvalidIndicator {...metaTitleStatus} />}
|
||||||
{...form.getInputProps("metaTitle")}
|
{...form.getInputProps("metaTitle")}
|
||||||
/>
|
/>
|
||||||
@@ -126,22 +125,12 @@ export const GeneralSettingsContent = ({ board }: Props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const PendingOrInvalidIndicator = ({
|
const PendingOrInvalidIndicator = ({ isPending, isInvalid }: { isPending: boolean; isInvalid?: boolean }) => {
|
||||||
isPending,
|
|
||||||
isInvalid,
|
|
||||||
}: {
|
|
||||||
isPending: boolean;
|
|
||||||
isInvalid?: boolean;
|
|
||||||
}) => {
|
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
|
|
||||||
if (isInvalid) {
|
if (isInvalid) {
|
||||||
return (
|
return (
|
||||||
<Tooltip
|
<Tooltip multiline w={220} label={t("board.setting.section.general.unrecognizedLink")}>
|
||||||
multiline
|
|
||||||
w={220}
|
|
||||||
label={t("board.setting.section.general.unrecognizedLink")}
|
|
||||||
>
|
|
||||||
<IconAlertTriangle size="1rem" color="red" />
|
<IconAlertTriangle size="1rem" color="red" />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
);
|
);
|
||||||
@@ -183,8 +172,7 @@ const useMetaTitlePreview = (title: string | null) => {
|
|||||||
|
|
||||||
const validFaviconExtensions = ["ico", "png", "svg", "gif"];
|
const validFaviconExtensions = ["ico", "png", "svg", "gif"];
|
||||||
const isValidUrl = (url: string) =>
|
const isValidUrl = (url: string) =>
|
||||||
url.includes("/") &&
|
url.includes("/") && validFaviconExtensions.some((extension) => url.endsWith(`.${extension}`));
|
||||||
validFaviconExtensions.some((extension) => url.endsWith(`.${extension}`));
|
|
||||||
|
|
||||||
const useFaviconPreview = (url: string | null) => {
|
const useFaviconPreview = (url: string | null) => {
|
||||||
const [faviconDebounced] = useDebouncedValue(url ?? "", 500);
|
const [faviconDebounced] = useDebouncedValue(url ?? "", 500);
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
import { Button, Grid, Group, Input, Slider, Stack } from "@mantine/core";
|
import { Button, Grid, Group, Input, Slider, Stack } from "@mantine/core";
|
||||||
|
|
||||||
import { useForm } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import { useI18n } from "@homarr/translation/client";
|
import { useI18n } from "@homarr/translation/client";
|
||||||
|
import { validation } from "@homarr/validation";
|
||||||
|
|
||||||
import type { Board } from "../../_types";
|
import type { Board } from "../../_types";
|
||||||
import { useSavePartialSettingsMutation } from "./_shared";
|
import { useSavePartialSettingsMutation } from "./_shared";
|
||||||
@@ -13,9 +14,8 @@ interface Props {
|
|||||||
}
|
}
|
||||||
export const LayoutSettingsContent = ({ board }: Props) => {
|
export const LayoutSettingsContent = ({ board }: Props) => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const { mutate: savePartialSettings, isPending } =
|
const { mutate: savePartialSettings, isPending } = useSavePartialSettingsMutation(board);
|
||||||
useSavePartialSettingsMutation(board);
|
const form = useZodForm(validation.board.savePartialSettings.pick({ columnCount: true }).required(), {
|
||||||
const form = useForm({
|
|
||||||
initialValues: {
|
initialValues: {
|
||||||
columnCount: board.columnCount,
|
columnCount: board.columnCount,
|
||||||
},
|
},
|
||||||
@@ -34,13 +34,7 @@ export const LayoutSettingsContent = ({ board }: Props) => {
|
|||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Col span={{ sm: 12, md: 6 }}>
|
<Grid.Col span={{ sm: 12, md: 6 }}>
|
||||||
<Input.Wrapper label={t("board.field.columnCount.label")}>
|
<Input.Wrapper label={t("board.field.columnCount.label")}>
|
||||||
<Slider
|
<Slider mt="xs" min={1} max={24} step={1} {...form.getInputProps("columnCount")} />
|
||||||
mt="xs"
|
|
||||||
min={1}
|
|
||||||
max={24}
|
|
||||||
step={1}
|
|
||||||
{...form.getInputProps("columnCount")}
|
|
||||||
/>
|
|
||||||
</Input.Wrapper>
|
</Input.Wrapper>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export const useSavePartialSettingsMutation = (board: Board) => {
|
|||||||
return clientApi.board.savePartialBoardSettings.useMutation({
|
return clientApi.board.savePartialBoardSettings.useMutation({
|
||||||
onSettled() {
|
onSettled() {
|
||||||
void utils.board.getBoardByName.invalidate({ name: board.name });
|
void utils.board.getBoardByName.invalidate({ name: board.name });
|
||||||
void utils.board.getDefaultBoard.invalidate();
|
void utils.board.getHomeBoard.invalidate();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
.codeEditorFooter {
|
||||||
|
border-bottom-left-radius: var(--mantine-radius-sm);
|
||||||
|
border-bottom-right-radius: var(--mantine-radius-sm);
|
||||||
|
background-color: light-dark(var(--mantine-color-gray-1), var(--mantine-color-dark-7));
|
||||||
|
}
|
||||||
|
|
||||||
|
.codeEditorRoot {
|
||||||
|
margin-top: 4px;
|
||||||
|
border-color: light-dark(var(--mantine-color-gray-4), var(--mantine-color-dark-4));
|
||||||
|
border-width: 1px;
|
||||||
|
border-style: solid;
|
||||||
|
border-radius: var(--mantine-radius-sm);
|
||||||
|
}
|
||||||
|
|
||||||
|
.codeEditor {
|
||||||
|
background-color: light-dark(white, var(--mantine-color-dark-6));
|
||||||
|
font-size: var(--mantine-font-size-xs);
|
||||||
|
}
|
||||||
|
|
||||||
|
.codeEditor ::placeholder {
|
||||||
|
color: light-dark(var(--mantine-color-gray-5), var(--mantine-color-dark-3));
|
||||||
|
}
|
||||||
@@ -1,14 +1,6 @@
|
|||||||
import type { PropsWithChildren } from "react";
|
import type { PropsWithChildren } from "react";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import {
|
import { AccordionControl, AccordionItem, AccordionPanel, Container, Stack, Text, Title } from "@mantine/core";
|
||||||
AccordionControl,
|
|
||||||
AccordionItem,
|
|
||||||
AccordionPanel,
|
|
||||||
Container,
|
|
||||||
Stack,
|
|
||||||
Text,
|
|
||||||
Title,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import {
|
import {
|
||||||
IconAlertTriangle,
|
IconAlertTriangle,
|
||||||
IconBrush,
|
IconBrush,
|
||||||
@@ -69,10 +61,7 @@ const getBoardAndPermissionsAsync = async (params: Props["params"]) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function BoardSettingsPage({
|
export default async function BoardSettingsPage({ params, searchParams }: Props) {
|
||||||
params,
|
|
||||||
searchParams,
|
|
||||||
}: Props) {
|
|
||||||
const { board, permissions } = await getBoardAndPermissionsAsync(params);
|
const { board, permissions } = await getBoardAndPermissionsAsync(params);
|
||||||
const { hasFullAccess } = await getBoardPermissionsAsync(board);
|
const { hasFullAccess } = await getBoardPermissionsAsync(board);
|
||||||
const t = await getScopedI18n("board.setting");
|
const t = await getScopedI18n("board.setting");
|
||||||
@@ -81,10 +70,7 @@ export default async function BoardSettingsPage({
|
|||||||
<Container>
|
<Container>
|
||||||
<Stack>
|
<Stack>
|
||||||
<Title>{t("title", { boardName: capitalize(board.name) })}</Title>
|
<Title>{t("title", { boardName: capitalize(board.name) })}</Title>
|
||||||
<ActiveTabAccordion
|
<ActiveTabAccordion variant="separated" defaultValue={searchParams.tab ?? "general"}>
|
||||||
variant="separated"
|
|
||||||
defaultValue={searchParams.tab ?? "general"}
|
|
||||||
>
|
|
||||||
<AccordionItemFor value="general" icon={IconSettings}>
|
<AccordionItemFor value="general" icon={IconSettings}>
|
||||||
<GeneralSettingsContent board={board} />
|
<GeneralSettingsContent board={board} />
|
||||||
</AccordionItemFor>
|
</AccordionItemFor>
|
||||||
@@ -98,22 +84,14 @@ export default async function BoardSettingsPage({
|
|||||||
<ColorSettingsContent board={board} />
|
<ColorSettingsContent board={board} />
|
||||||
</AccordionItemFor>
|
</AccordionItemFor>
|
||||||
<AccordionItemFor value="customCss" icon={IconFileTypeCss}>
|
<AccordionItemFor value="customCss" icon={IconFileTypeCss}>
|
||||||
<CustomCssSettingsContent />
|
<CustomCssSettingsContent board={board} />
|
||||||
</AccordionItemFor>
|
</AccordionItemFor>
|
||||||
{hasFullAccess && (
|
{hasFullAccess && (
|
||||||
<>
|
<>
|
||||||
<AccordionItemFor value="access" icon={IconUser}>
|
<AccordionItemFor value="access" icon={IconUser}>
|
||||||
<AccessSettingsContent
|
<AccessSettingsContent board={board} initialPermissions={permissions} />
|
||||||
board={board}
|
|
||||||
initialPermissions={permissions}
|
|
||||||
/>
|
|
||||||
</AccordionItemFor>
|
</AccordionItemFor>
|
||||||
<AccordionItemFor
|
<AccordionItemFor value="dangerZone" icon={IconAlertTriangle} danger noPadding>
|
||||||
value="dangerZone"
|
|
||||||
icon={IconAlertTriangle}
|
|
||||||
danger
|
|
||||||
noPadding
|
|
||||||
>
|
|
||||||
<DangerZoneSettingsContent />
|
<DangerZoneSettingsContent />
|
||||||
</AccordionItemFor>
|
</AccordionItemFor>
|
||||||
</>
|
</>
|
||||||
@@ -131,13 +109,7 @@ type AccordionItemForProps = PropsWithChildren<{
|
|||||||
noPadding?: boolean;
|
noPadding?: boolean;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
const AccordionItemFor = async ({
|
const AccordionItemFor = async ({ value, children, icon: Icon, danger, noPadding }: AccordionItemForProps) => {
|
||||||
value,
|
|
||||||
children,
|
|
||||||
icon: Icon,
|
|
||||||
danger,
|
|
||||||
noPadding,
|
|
||||||
}: AccordionItemForProps) => {
|
|
||||||
const t = await getScopedI18n("board.setting.section");
|
const t = await getScopedI18n("board.setting.section");
|
||||||
return (
|
return (
|
||||||
<AccordionItem
|
<AccordionItem
|
||||||
@@ -158,13 +130,7 @@ const AccordionItemFor = async ({
|
|||||||
{t(`${value}.title`)}
|
{t(`${value}.title`)}
|
||||||
</Text>
|
</Text>
|
||||||
</AccordionControl>
|
</AccordionControl>
|
||||||
<AccordionPanel
|
<AccordionPanel styles={noPadding ? { content: { paddingRight: 0, paddingLeft: 0 } } : undefined}>
|
||||||
styles={
|
|
||||||
noPadding
|
|
||||||
? { content: { paddingRight: 0, paddingLeft: 0 } }
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</AccordionPanel>
|
</AccordionPanel>
|
||||||
</AccordionItem>
|
</AccordionItem>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { ClientShell } from "~/components/layout/shell";
|
|||||||
import type { Board } from "./_types";
|
import type { Board } from "./_types";
|
||||||
import { BoardProvider } from "./(content)/_context";
|
import { BoardProvider } from "./(content)/_context";
|
||||||
import type { Params } from "./(content)/_creator";
|
import type { Params } from "./(content)/_creator";
|
||||||
|
import { CustomCss } from "./(content)/_custom-css";
|
||||||
import { BoardMantineProvider } from "./(content)/_theme";
|
import { BoardMantineProvider } from "./(content)/_theme";
|
||||||
|
|
||||||
interface CreateBoardLayoutProps<TParams extends Params> {
|
interface CreateBoardLayoutProps<TParams extends Params> {
|
||||||
@@ -41,12 +42,10 @@ export const createBoardLayout = <TParams extends Params>({
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GlobalItemServerDataRunner
|
<GlobalItemServerDataRunner board={initialBoard} shouldRun={isBoardContentPage}>
|
||||||
board={initialBoard}
|
|
||||||
shouldRun={isBoardContentPage}
|
|
||||||
>
|
|
||||||
<BoardProvider initialBoard={initialBoard}>
|
<BoardProvider initialBoard={initialBoard}>
|
||||||
<BoardMantineProvider>
|
<BoardMantineProvider>
|
||||||
|
<CustomCss />
|
||||||
<ClientShell hasNavigation={false}>
|
<ClientShell hasNavigation={false}>
|
||||||
<MainHeader
|
<MainHeader
|
||||||
logo={<BoardLogoWithTitle size="md" hideTitleOnMobile />}
|
logo={<BoardLogoWithTitle size="md" hideTitleOnMobile />}
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
import type { WidgetKind } from "@homarr/definitions";
|
import type { WidgetKind } from "@homarr/definitions";
|
||||||
|
|
||||||
export type Board = RouterOutputs["board"]["getDefaultBoard"];
|
export type Board = RouterOutputs["board"]["getHomeBoard"];
|
||||||
export type Section = Board["sections"][number];
|
export type Section = Board["sections"][number];
|
||||||
export type Item = Section["items"][number];
|
export type Item = Section["items"][number];
|
||||||
|
|
||||||
export type CategorySection = Extract<Section, { kind: "category" }>;
|
export type CategorySection = Extract<Section, { kind: "category" }>;
|
||||||
export type EmptySection = Extract<Section, { kind: "empty" }>;
|
export type EmptySection = Extract<Section, { kind: "empty" }>;
|
||||||
|
|
||||||
export type ItemOfKind<TKind extends WidgetKind> = Extract<
|
export type ItemOfKind<TKind extends WidgetKind> = Extract<Item, { kind: TKind }>;
|
||||||
Item,
|
|
||||||
{ kind: TKind }
|
|
||||||
>;
|
|
||||||
|
|||||||
@@ -5,14 +5,12 @@ type PropsWithChildren = Required<React.PropsWithChildren>;
|
|||||||
export const composeWrappers = (
|
export const composeWrappers = (
|
||||||
wrappers: React.FunctionComponent<PropsWithChildren>[],
|
wrappers: React.FunctionComponent<PropsWithChildren>[],
|
||||||
): React.FunctionComponent<PropsWithChildren> => {
|
): React.FunctionComponent<PropsWithChildren> => {
|
||||||
return wrappers
|
return wrappers.reverse().reduce((Acc, Current): React.FunctionComponent<PropsWithChildren> => {
|
||||||
.reverse()
|
// eslint-disable-next-line react/display-name
|
||||||
.reduce((Acc, Current): React.FunctionComponent<PropsWithChildren> => {
|
return (props) => (
|
||||||
// eslint-disable-next-line react/display-name
|
<Current>
|
||||||
return (props) => (
|
<Acc {...props} />
|
||||||
<Current>
|
</Current>
|
||||||
<Acc {...props} />
|
);
|
||||||
</Current>
|
});
|
||||||
);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,11 +4,8 @@ import { useRouter } from "next/navigation";
|
|||||||
import { Button, PasswordInput, Stack, TextInput } from "@mantine/core";
|
import { Button, PasswordInput, Stack, TextInput } from "@mantine/core";
|
||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useForm, zodResolver } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
import type { z } from "@homarr/validation";
|
import type { z } from "@homarr/validation";
|
||||||
import { validation } from "@homarr/validation";
|
import { validation } from "@homarr/validation";
|
||||||
@@ -16,12 +13,8 @@ import { validation } from "@homarr/validation";
|
|||||||
export const InitUserForm = () => {
|
export const InitUserForm = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const t = useScopedI18n("user");
|
const t = useScopedI18n("user");
|
||||||
const { mutateAsync, error, isPending } =
|
const { mutateAsync, error, isPending } = clientApi.user.initUser.useMutation();
|
||||||
clientApi.user.initUser.useMutation();
|
const form = useZodForm(validation.user.init, {
|
||||||
const form = useForm<FormType>({
|
|
||||||
validate: zodResolver(validation.user.init),
|
|
||||||
validateInputOnBlur: true,
|
|
||||||
validateInputOnChange: true,
|
|
||||||
initialValues: {
|
initialValues: {
|
||||||
username: "",
|
username: "",
|
||||||
password: "",
|
password: "",
|
||||||
@@ -56,18 +49,9 @@ export const InitUserForm = () => {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Stack gap="lg">
|
<Stack gap="lg">
|
||||||
<TextInput
|
<TextInput label={t("field.username.label")} {...form.getInputProps("username")} />
|
||||||
label={t("field.username.label")}
|
<PasswordInput label={t("field.password.label")} {...form.getInputProps("password")} />
|
||||||
{...form.getInputProps("username")}
|
<PasswordInput label={t("field.passwordConfirm.label")} {...form.getInputProps("confirmPassword")} />
|
||||||
/>
|
|
||||||
<PasswordInput
|
|
||||||
label={t("field.password.label")}
|
|
||||||
{...form.getInputProps("password")}
|
|
||||||
/>
|
|
||||||
<PasswordInput
|
|
||||||
label={t("field.passwordConfirm.label")}
|
|
||||||
{...form.getInputProps("confirmPassword")}
|
|
||||||
/>
|
|
||||||
<Button type="submit" fullWidth loading={isPending}>
|
<Button type="submit" fullWidth loading={isPending}>
|
||||||
{t("action.create")}
|
{t("action.create")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -48,10 +48,7 @@ export const viewport: Viewport = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Layout(props: {
|
export default function Layout(props: { children: React.ReactNode; params: { locale: string } }) {
|
||||||
children: React.ReactNode;
|
|
||||||
params: { locale: string };
|
|
||||||
}) {
|
|
||||||
const colorScheme = "dark";
|
const colorScheme = "dark";
|
||||||
|
|
||||||
const StackedProvider = composeWrappers([
|
const StackedProvider = composeWrappers([
|
||||||
@@ -61,9 +58,7 @@ export default function Layout(props: {
|
|||||||
},
|
},
|
||||||
(innerProps) => <JotaiProvider {...innerProps} />,
|
(innerProps) => <JotaiProvider {...innerProps} />,
|
||||||
(innerProps) => <TRPCReactProvider {...innerProps} />,
|
(innerProps) => <TRPCReactProvider {...innerProps} />,
|
||||||
(innerProps) => (
|
(innerProps) => <NextInternationalProvider {...innerProps} locale={props.params.locale} />,
|
||||||
<NextInternationalProvider {...innerProps} locale={props.params.locale} />
|
|
||||||
),
|
|
||||||
(innerProps) => (
|
(innerProps) => (
|
||||||
<MantineProvider
|
<MantineProvider
|
||||||
{...innerProps}
|
{...innerProps}
|
||||||
|
|||||||
@@ -48,13 +48,7 @@ export const HeroBanner = () => {
|
|||||||
<Title>Homarr Dashboard</Title>
|
<Title>Homarr Dashboard</Title>
|
||||||
</Group>
|
</Group>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Box
|
<Box className={classes.scrollContainer} w={"30%"} top={0} right={0} pos="absolute">
|
||||||
className={classes.scrollContainer}
|
|
||||||
w={"30%"}
|
|
||||||
top={0}
|
|
||||||
right={0}
|
|
||||||
pos="absolute"
|
|
||||||
>
|
|
||||||
<Grid>
|
<Grid>
|
||||||
{Array(countIconGroups)
|
{Array(countIconGroups)
|
||||||
.fill(0)
|
.fill(0)
|
||||||
@@ -67,24 +61,12 @@ export const HeroBanner = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{arrayInChunks[columnIndex]?.map((icon, index) => (
|
{arrayInChunks[columnIndex]?.map((icon, index) => (
|
||||||
<Image
|
<Image key={`grid-column-${columnIndex}-scroll-1-${index}`} src={icon} radius="md" w={50} h={50} />
|
||||||
key={`grid-column-${columnIndex}-scroll-1-${index}`}
|
|
||||||
src={icon}
|
|
||||||
radius="md"
|
|
||||||
w={50}
|
|
||||||
h={50}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{/* This is used for making the animation seem seamless */}
|
{/* This is used for making the animation seem seamless */}
|
||||||
{arrayInChunks[columnIndex]?.map((icon, index) => (
|
{arrayInChunks[columnIndex]?.map((icon, index) => (
|
||||||
<Image
|
<Image key={`grid-column-${columnIndex}-scroll-2-${index}`} src={icon} radius="md" w={50} h={50} />
|
||||||
key={`grid-column-${columnIndex}-scroll-2-${index}`}
|
|
||||||
src={icon}
|
|
||||||
radius="md"
|
|
||||||
w={50}
|
|
||||||
h={50}
|
|
||||||
/>
|
|
||||||
))}
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
</GridCol>
|
</GridCol>
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
.contributorCard {
|
.contributorCard {
|
||||||
background-color: light-dark(
|
background-color: light-dark(var(--mantine-color-gray-1), var(--mantine-color-dark-5));
|
||||||
var(--mantine-color-gray-1),
|
|
||||||
var(--mantine-color-dark-5)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { setStaticParamsLocale } from "next-international/server";
|
|||||||
|
|
||||||
import { getScopedI18n, getStaticParams } from "@homarr/translation/server";
|
import { getScopedI18n, getStaticParams } from "@homarr/translation/server";
|
||||||
|
|
||||||
|
import { createMetaTitle } from "~/metadata";
|
||||||
import { getPackageAttributesAsync } from "~/versions/package-reader";
|
import { getPackageAttributesAsync } from "~/versions/package-reader";
|
||||||
import contributorsData from "../../../../../../../static-data/contributors.json";
|
import contributorsData from "../../../../../../../static-data/contributors.json";
|
||||||
import translatorsData from "../../../../../../../static-data/translators.json";
|
import translatorsData from "../../../../../../../static-data/translators.json";
|
||||||
@@ -29,10 +30,9 @@ import classes from "./about.module.css";
|
|||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const t = await getScopedI18n("management");
|
const t = await getScopedI18n("management");
|
||||||
const metaTitle = `${t("metaTitle")} • Homarr`;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: metaTitle,
|
title: createMetaTitle(t("metaTitle")),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,9 +55,7 @@ export default async function AboutPage({ params: { locale } }: PageProps) {
|
|||||||
<Title order={1} tt="uppercase">
|
<Title order={1} tt="uppercase">
|
||||||
Homarr
|
Homarr
|
||||||
</Title>
|
</Title>
|
||||||
<Title order={2}>
|
<Title order={2}>{t("version", { version: attributes.version })}</Title>
|
||||||
{t("version", { version: attributes.version })}
|
|
||||||
</Title>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</Group>
|
</Group>
|
||||||
</Center>
|
</Center>
|
||||||
@@ -150,20 +148,10 @@ interface GenericContributorLinkCardProps {
|
|||||||
image: string;
|
image: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const GenericContributorLinkCard = ({
|
const GenericContributorLinkCard = ({ name, image, link }: GenericContributorLinkCardProps) => {
|
||||||
name,
|
|
||||||
image,
|
|
||||||
link,
|
|
||||||
}: GenericContributorLinkCardProps) => {
|
|
||||||
return (
|
return (
|
||||||
<AspectRatio ratio={1}>
|
<AspectRatio ratio={1}>
|
||||||
<Card
|
<Card className={classes.contributorCard} component="a" href={link} target="_blank" w={100}>
|
||||||
className={classes.contributorCard}
|
|
||||||
component="a"
|
|
||||||
href={link}
|
|
||||||
target="_blank"
|
|
||||||
w={100}
|
|
||||||
>
|
|
||||||
<Stack align="center">
|
<Stack align="center">
|
||||||
<Avatar src={image} alt={name} size={40} display="block" />
|
<Avatar src={image} alt={name} size={40} display="block" />
|
||||||
<Text lineClamp={1} size="sm">
|
<Text lineClamp={1} size="sm">
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import { IconTrash } from "@tabler/icons-react";
|
|||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useConfirmModal } from "@homarr/modals";
|
import { useConfirmModal } from "@homarr/modals";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
import { revalidatePathActionAsync } from "../../../revalidatePathAction";
|
import { revalidatePathActionAsync } from "../../../revalidatePathAction";
|
||||||
@@ -52,13 +49,7 @@ export const AppDeleteButton = ({ app }: AppDeleteButtonProps) => {
|
|||||||
}, [app, mutate, t, openConfirmModal]);
|
}, [app, mutate, t, openConfirmModal]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ActionIcon
|
<ActionIcon loading={isPending} variant="subtle" color="red" onClick={onClick} aria-label="Delete app">
|
||||||
loading={isPending}
|
|
||||||
variant="subtle"
|
|
||||||
color="red"
|
|
||||||
onClick={onClick}
|
|
||||||
aria-label="Delete app"
|
|
||||||
>
|
|
||||||
<IconTrash color="red" size={16} stroke={1.5} />
|
<IconTrash color="red" size={16} stroke={1.5} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Button, Group, Stack, Textarea, TextInput } from "@mantine/core";
|
import { Button, Group, Stack, Textarea, TextInput } from "@mantine/core";
|
||||||
|
|
||||||
import { useForm, zodResolver } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import type { TranslationFunction } from "@homarr/translation";
|
import type { TranslationFunction } from "@homarr/translation";
|
||||||
import { useI18n } from "@homarr/translation/client";
|
import { useI18n } from "@homarr/translation/client";
|
||||||
import type { z } from "@homarr/validation";
|
import type { z } from "@homarr/validation";
|
||||||
@@ -21,30 +21,23 @@ interface AppFormProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const AppForm = (props: AppFormProps) => {
|
export const AppForm = (props: AppFormProps) => {
|
||||||
const { submitButtonTranslation, handleSubmit, initialValues, isPending } =
|
const { submitButtonTranslation, handleSubmit, initialValues, isPending } = props;
|
||||||
props;
|
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
|
|
||||||
const form = useForm({
|
const form = useZodForm(validation.app.manage, {
|
||||||
initialValues: initialValues ?? {
|
initialValues: initialValues ?? {
|
||||||
name: "",
|
name: "",
|
||||||
description: "",
|
description: "",
|
||||||
iconUrl: "",
|
iconUrl: "",
|
||||||
href: "",
|
href: "",
|
||||||
},
|
},
|
||||||
validate: zodResolver(validation.app.manage),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||||
<Stack>
|
<Stack>
|
||||||
<TextInput {...form.getInputProps("name")} withAsterisk label="Name" />
|
<TextInput {...form.getInputProps("name")} withAsterisk label="Name" />
|
||||||
<IconPicker
|
<IconPicker initialValue={initialValues?.iconUrl} {...form.getInputProps("iconUrl")} />
|
||||||
initialValue={initialValues?.iconUrl}
|
|
||||||
onChange={(iconUrl) => {
|
|
||||||
form.setFieldValue("iconUrl", iconUrl);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Textarea {...form.getInputProps("description")} label="Description" />
|
<Textarea {...form.getInputProps("description")} label="Description" />
|
||||||
<TextInput {...form.getInputProps("href")} label="URL" />
|
<TextInput {...form.getInputProps("href")} label="URL" />
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ import { useRouter } from "next/navigation";
|
|||||||
|
|
||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import type { TranslationFunction } from "@homarr/translation";
|
import type { TranslationFunction } from "@homarr/translation";
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
import type { validation, z } from "@homarr/validation";
|
import type { validation, z } from "@homarr/validation";
|
||||||
@@ -52,10 +49,7 @@ export const AppEditForm = ({ app }: AppEditFormProps) => {
|
|||||||
[mutate, app.id],
|
[mutate, app.id],
|
||||||
);
|
);
|
||||||
|
|
||||||
const submitButtonTranslation = useCallback(
|
const submitButtonTranslation = useCallback((t: TranslationFunction) => t("common.action.save"), []);
|
||||||
(t: TranslationFunction) => t("common.action.save"),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppForm
|
<AppForm
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import { useCallback } from "react";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import type { TranslationFunction } from "@homarr/translation";
|
import type { TranslationFunction } from "@homarr/translation";
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
import type { validation, z } from "@homarr/validation";
|
import type { validation, z } from "@homarr/validation";
|
||||||
@@ -44,16 +41,9 @@ export const AppNewForm = () => {
|
|||||||
[mutate],
|
[mutate],
|
||||||
);
|
);
|
||||||
|
|
||||||
const submitButtonTranslation = useCallback(
|
const submitButtonTranslation = useCallback((t: TranslationFunction) => t("common.action.create"), []);
|
||||||
(t: TranslationFunction) => t("common.action.create"),
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppForm
|
<AppForm submitButtonTranslation={submitButtonTranslation} handleSubmit={handleSubmit} isPending={isPending} />
|
||||||
submitButtonTranslation={submitButtonTranslation}
|
|
||||||
handleSubmit={handleSubmit}
|
|
||||||
isPending={isPending}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -107,9 +107,7 @@ const AppNoResults = async () => {
|
|||||||
<Text fw={500} size="lg">
|
<Text fw={500} size="lg">
|
||||||
{t("app.page.list.noResults.title")}
|
{t("app.page.list.noResults.title")}
|
||||||
</Text>
|
</Text>
|
||||||
<Anchor href="/manage/apps/new">
|
<Anchor href="/manage/apps/new">{t("app.page.list.noResults.description")}</Anchor>
|
||||||
{t("app.page.list.noResults.description")}
|
|
||||||
</Anchor>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Menu } from "@mantine/core";
|
import { Menu } from "@mantine/core";
|
||||||
import { IconSettings, IconTrash } from "@tabler/icons-react";
|
import { IconHome, IconSettings, IconTrash } from "@tabler/icons-react";
|
||||||
|
|
||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
@@ -21,18 +21,11 @@ const iconProps = {
|
|||||||
interface BoardCardMenuDropdownProps {
|
interface BoardCardMenuDropdownProps {
|
||||||
board: Pick<
|
board: Pick<
|
||||||
RouterOutputs["board"]["getAllBoards"][number],
|
RouterOutputs["board"]["getAllBoards"][number],
|
||||||
| "id"
|
"id" | "name" | "creator" | "userPermissions" | "groupPermissions" | "isPublic"
|
||||||
| "name"
|
|
||||||
| "creator"
|
|
||||||
| "userPermissions"
|
|
||||||
| "groupPermissions"
|
|
||||||
| "isPublic"
|
|
||||||
>;
|
>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BoardCardMenuDropdown = ({
|
export const BoardCardMenuDropdown = ({ board }: BoardCardMenuDropdownProps) => {
|
||||||
board,
|
|
||||||
}: BoardCardMenuDropdownProps) => {
|
|
||||||
const t = useScopedI18n("management.page.board.action");
|
const t = useScopedI18n("management.page.board.action");
|
||||||
const tCommon = useScopedI18n("common");
|
const tCommon = useScopedI18n("common");
|
||||||
|
|
||||||
@@ -40,7 +33,13 @@ export const BoardCardMenuDropdown = ({
|
|||||||
|
|
||||||
const { openConfirmModal } = useConfirmModal();
|
const { openConfirmModal } = useConfirmModal();
|
||||||
|
|
||||||
const { mutateAsync, isPending } = clientApi.board.deleteBoard.useMutation({
|
const setHomeBoardMutation = clientApi.board.setHomeBoard.useMutation({
|
||||||
|
onSettled: async () => {
|
||||||
|
// Revalidate all as it's part of the user settings, /boards page and board manage page
|
||||||
|
await revalidatePathActionAsync("/");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const deleteBoardMutation = clientApi.board.deleteBoard.useMutation({
|
||||||
onSettled: async () => {
|
onSettled: async () => {
|
||||||
await revalidatePathActionAsync("/manage/boards");
|
await revalidatePathActionAsync("/manage/boards");
|
||||||
},
|
},
|
||||||
@@ -54,23 +53,33 @@ export const BoardCardMenuDropdown = ({
|
|||||||
}),
|
}),
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
await mutateAsync({
|
await deleteBoardMutation.mutateAsync({
|
||||||
id: board.id,
|
id: board.id,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}, [board.id, board.name, mutateAsync, openConfirmModal, t]);
|
}, [board.id, board.name, deleteBoardMutation, openConfirmModal, t]);
|
||||||
|
|
||||||
|
const handleSetHomeBoard = useCallback(async () => {
|
||||||
|
await setHomeBoardMutation.mutateAsync({ id: board.id });
|
||||||
|
}, [board.id, setHomeBoardMutation]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Menu.Dropdown>
|
<Menu.Dropdown>
|
||||||
|
<Menu.Item onClick={handleSetHomeBoard} leftSection={<IconHome {...iconProps} />}>
|
||||||
|
{t("setHomeBoard.label")}
|
||||||
|
</Menu.Item>
|
||||||
{hasChangeAccess && (
|
{hasChangeAccess && (
|
||||||
<Menu.Item
|
<>
|
||||||
component={Link}
|
<Menu.Divider />
|
||||||
href={`/boards/${board.name}/settings`}
|
<Menu.Item
|
||||||
leftSection={<IconSettings {...iconProps} />}
|
component={Link}
|
||||||
>
|
href={`/boards/${board.name}/settings`}
|
||||||
{t("settings.label")}
|
leftSection={<IconSettings {...iconProps} />}
|
||||||
</Menu.Item>
|
>
|
||||||
|
{t("settings.label")}
|
||||||
|
</Menu.Item>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{hasFullAccess && (
|
{hasFullAccess && (
|
||||||
<>
|
<>
|
||||||
@@ -80,7 +89,7 @@ export const BoardCardMenuDropdown = ({
|
|||||||
c="red.7"
|
c="red.7"
|
||||||
leftSection={<IconTrash {...iconProps} />}
|
leftSection={<IconTrash {...iconProps} />}
|
||||||
onClick={handleDeletion}
|
onClick={handleDeletion}
|
||||||
disabled={isPending}
|
disabled={deleteBoardMutation.isPending}
|
||||||
>
|
>
|
||||||
{t("delete.label")}
|
{t("delete.label")}
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
|
|||||||
@@ -37,11 +37,7 @@ export const CreateBoardButton = ({ boardNames }: CreateBoardButtonProps) => {
|
|||||||
}, [mutateAsync, boardNames, openModal]);
|
}, [mutateAsync, boardNames, openModal]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button leftSection={<IconCategoryPlus size="1rem" />} onClick={onClick} loading={isPending}>
|
||||||
leftSection={<IconCategoryPlus size="1rem" />}
|
|
||||||
onClick={onClick}
|
|
||||||
loading={isPending}
|
|
||||||
>
|
|
||||||
{t("management.page.board.action.new.label")}
|
{t("management.page.board.action.new.label")}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import {
|
import {
|
||||||
ActionIcon,
|
ActionIcon,
|
||||||
|
Badge,
|
||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
CardSection,
|
CardSection,
|
||||||
@@ -13,7 +14,7 @@ import {
|
|||||||
Title,
|
Title,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { IconDotsVertical, IconLock, IconWorld } from "@tabler/icons-react";
|
import { IconDotsVertical, IconHomeFilled, IconLock, IconWorld } from "@tabler/icons-react";
|
||||||
|
|
||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
import { api } from "@homarr/api/server";
|
import { api } from "@homarr/api/server";
|
||||||
@@ -53,8 +54,7 @@ interface BoardCardProps {
|
|||||||
|
|
||||||
const BoardCard = async ({ board }: BoardCardProps) => {
|
const BoardCard = async ({ board }: BoardCardProps) => {
|
||||||
const t = await getScopedI18n("management.page.board");
|
const t = await getScopedI18n("management.page.board");
|
||||||
const { hasChangeAccess: isMenuVisible } =
|
const { hasChangeAccess: isMenuVisible } = await getBoardPermissionsAsync(board);
|
||||||
await getBoardPermissionsAsync(board);
|
|
||||||
const visibility = board.isPublic ? "public" : "private";
|
const visibility = board.isPublic ? "public" : "private";
|
||||||
const VisibilityIcon = board.isPublic ? IconWorld : IconLock;
|
const VisibilityIcon = board.isPublic ? IconWorld : IconLock;
|
||||||
|
|
||||||
@@ -71,23 +71,28 @@ const BoardCard = async ({ board }: BoardCardProps) => {
|
|||||||
</Text>
|
</Text>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
{board.creator && (
|
<Group>
|
||||||
<Group gap="xs">
|
{board.isHome && (
|
||||||
<UserAvatar user={board.creator} size="sm" />
|
<Tooltip label={t("action.setHomeBoard.badge.tooltip")}>
|
||||||
<Text>{board.creator?.name}</Text>
|
<Badge tt="none" color="yellow" variant="light" leftSection={<IconHomeFilled size=".7rem" />}>
|
||||||
</Group>
|
{t("action.setHomeBoard.badge.label")}
|
||||||
)}
|
</Badge>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{board.creator && (
|
||||||
|
<Group gap="xs">
|
||||||
|
<UserAvatar user={board.creator} size="sm" />
|
||||||
|
<Text>{board.creator?.name}</Text>
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
</CardSection>
|
</CardSection>
|
||||||
|
|
||||||
<CardSection p="sm">
|
<CardSection p="sm">
|
||||||
<Group wrap="nowrap">
|
<Group wrap="nowrap">
|
||||||
<Button
|
<Button component={Link} href={`/boards/${board.name}`} variant="default" fullWidth>
|
||||||
component={Link}
|
|
||||||
href={`/boards/${board.name}`}
|
|
||||||
variant="default"
|
|
||||||
fullWidth
|
|
||||||
>
|
|
||||||
{t("action.open.label")}
|
{t("action.open.label")}
|
||||||
</Button>
|
</Button>
|
||||||
{isMenuVisible && (
|
{isMenuVisible && (
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import { IconTrash } from "@tabler/icons-react";
|
|||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useConfirmModal } from "@homarr/modals";
|
import { useConfirmModal } from "@homarr/modals";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
import { revalidatePathActionAsync } from "../../../revalidatePathAction";
|
import { revalidatePathActionAsync } from "../../../revalidatePathAction";
|
||||||
@@ -19,10 +16,7 @@ interface DeleteIntegrationActionButtonProps {
|
|||||||
integration: { id: string; name: string };
|
integration: { id: string; name: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DeleteIntegrationActionButton = ({
|
export const DeleteIntegrationActionButton = ({ count, integration }: DeleteIntegrationActionButtonProps) => {
|
||||||
count,
|
|
||||||
integration,
|
|
||||||
}: DeleteIntegrationActionButtonProps) => {
|
|
||||||
const t = useScopedI18n("integration.page.delete");
|
const t = useScopedI18n("integration.page.delete");
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { openConfirmModal } = useConfirmModal();
|
const { openConfirmModal } = useConfirmModal();
|
||||||
|
|||||||
@@ -2,17 +2,7 @@
|
|||||||
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
import {
|
import { ActionIcon, Avatar, Button, Card, Collapse, Group, Kbd, Stack, Text } from "@mantine/core";
|
||||||
ActionIcon,
|
|
||||||
Avatar,
|
|
||||||
Button,
|
|
||||||
Card,
|
|
||||||
Collapse,
|
|
||||||
Group,
|
|
||||||
Kbd,
|
|
||||||
Stack,
|
|
||||||
Text,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import { useDisclosure } from "@mantine/hooks";
|
import { useDisclosure } from "@mantine/hooks";
|
||||||
import { IconEye, IconEyeOff } from "@tabler/icons-react";
|
import { IconEye, IconEyeOff } from "@tabler/icons-react";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
@@ -36,8 +26,7 @@ export const SecretCard = ({ secret, children, onCancel }: SecretCardProps) => {
|
|||||||
const params = useParams<{ locale: string }>();
|
const params = useParams<{ locale: string }>();
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const { isPublic } = integrationSecretKindObject[secret.kind];
|
const { isPublic } = integrationSecretKindObject[secret.kind];
|
||||||
const [publicSecretDisplayOpened, { toggle: togglePublicSecretDisplay }] =
|
const [publicSecretDisplayOpened, { toggle: togglePublicSecretDisplay }] = useDisclosure(false);
|
||||||
useDisclosure(false);
|
|
||||||
const [editMode, setEditMode] = useState(false);
|
const [editMode, setEditMode] = useState(false);
|
||||||
const DisplayIcon = publicSecretDisplayOpened ? IconEye : IconEyeOff;
|
const DisplayIcon = publicSecretDisplayOpened ? IconEye : IconEyeOff;
|
||||||
const KindIcon = integrationSecretIcons[secret.kind];
|
const KindIcon = integrationSecretIcons[secret.kind];
|
||||||
@@ -50,9 +39,7 @@ export const SecretCard = ({ secret, children, onCancel }: SecretCardProps) => {
|
|||||||
<Avatar>
|
<Avatar>
|
||||||
<KindIcon size={16} />
|
<KindIcon size={16} />
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<Text fw={500}>
|
<Text fw={500}>{t(`integration.secrets.kind.${secret.kind}.label`)}</Text>
|
||||||
{t(`integration.secrets.kind.${secret.kind}.label`)}
|
|
||||||
</Text>
|
|
||||||
{publicSecretDisplayOpened ? <Kbd>{secret.value}</Kbd> : null}
|
{publicSecretDisplayOpened ? <Kbd>{secret.value}</Kbd> : null}
|
||||||
</Group>
|
</Group>
|
||||||
<Group>
|
<Group>
|
||||||
@@ -62,11 +49,7 @@ export const SecretCard = ({ secret, children, onCancel }: SecretCardProps) => {
|
|||||||
})}
|
})}
|
||||||
</Text>
|
</Text>
|
||||||
{isPublic ? (
|
{isPublic ? (
|
||||||
<ActionIcon
|
<ActionIcon color="gray" variant="subtle" onClick={togglePublicSecretDisplay}>
|
||||||
color="gray"
|
|
||||||
variant="subtle"
|
|
||||||
onClick={togglePublicSecretDisplay}
|
|
||||||
>
|
|
||||||
<DisplayIcon size={16} stroke={1.5} />
|
<DisplayIcon size={16} stroke={1.5} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { useI18n } from "@homarr/translation/client";
|
|||||||
import { integrationSecretIcons } from "./_integration-secret-icons";
|
import { integrationSecretIcons } from "./_integration-secret-icons";
|
||||||
|
|
||||||
interface IntegrationSecretInputProps {
|
interface IntegrationSecretInputProps {
|
||||||
|
withAsterisk?: boolean;
|
||||||
label?: string;
|
label?: string;
|
||||||
kind: IntegrationSecretKind;
|
kind: IntegrationSecretKind;
|
||||||
value?: string;
|
value?: string;
|
||||||
@@ -41,10 +42,7 @@ const PublicSecretInput = ({ kind, ...props }: IntegrationSecretInputProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const PrivateSecretInput = ({
|
const PrivateSecretInput = ({ kind, ...props }: IntegrationSecretInputProps) => {
|
||||||
kind,
|
|
||||||
...props
|
|
||||||
}: IntegrationSecretInputProps) => {
|
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const Icon = integrationSecretIcons[kind];
|
const Icon = integrationSecretIcons[kind];
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import { IconCheck, IconInfoCircle, IconX } from "@tabler/icons-react";
|
|||||||
|
|
||||||
import type { RouterInputs } from "@homarr/api";
|
import type { RouterInputs } from "@homarr/api";
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
interface UseTestConnectionDirtyProps {
|
interface UseTestConnectionDirtyProps {
|
||||||
@@ -20,10 +17,7 @@ interface UseTestConnectionDirtyProps {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useTestConnectionDirty = ({
|
export const useTestConnectionDirty = ({ defaultDirty, initialFormValue }: UseTestConnectionDirtyProps) => {
|
||||||
defaultDirty,
|
|
||||||
initialFormValue,
|
|
||||||
}: UseTestConnectionDirtyProps) => {
|
|
||||||
const [isDirty, setIsDirty] = useState(defaultDirty);
|
const [isDirty, setIsDirty] = useState(defaultDirty);
|
||||||
const prevFormValueRef = useRef(initialFormValue);
|
const prevFormValueRef = useRef(initialFormValue);
|
||||||
|
|
||||||
@@ -36,10 +30,7 @@ export const useTestConnectionDirty = ({
|
|||||||
prevFormValueRef.current.url !== values.url ||
|
prevFormValueRef.current.url !== values.url ||
|
||||||
!prevFormValueRef.current.secrets
|
!prevFormValueRef.current.secrets
|
||||||
.map((secret) => secret.value)
|
.map((secret) => secret.value)
|
||||||
.every(
|
.every((secretValue, index) => values.secrets[index]?.value === secretValue)
|
||||||
(secretValue, index) =>
|
|
||||||
values.secrets[index]?.value === secretValue,
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
setIsDirty(true);
|
setIsDirty(true);
|
||||||
return;
|
return;
|
||||||
@@ -62,14 +53,9 @@ interface TestConnectionProps {
|
|||||||
integration: RouterInputs["integration"]["testConnection"] & { name: string };
|
integration: RouterInputs["integration"]["testConnection"] & { name: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TestConnection = ({
|
export const TestConnection = ({ integration, removeDirty, isDirty }: TestConnectionProps) => {
|
||||||
integration,
|
|
||||||
removeDirty,
|
|
||||||
isDirty,
|
|
||||||
}: TestConnectionProps) => {
|
|
||||||
const t = useScopedI18n("integration.testConnection");
|
const t = useScopedI18n("integration.testConnection");
|
||||||
const { mutateAsync, ...mutation } =
|
const { mutateAsync, ...mutation } = clientApi.integration.testConnection.useMutation();
|
||||||
clientApi.integration.testConnection.useMutation();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Group>
|
<Group>
|
||||||
@@ -125,13 +111,7 @@ interface TestConnectionIconProps {
|
|||||||
size: number;
|
size: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TestConnectionIcon = ({
|
const TestConnectionIcon = ({ isDirty, isPending, isSuccess, isError, size }: TestConnectionIconProps) => {
|
||||||
isDirty,
|
|
||||||
isPending,
|
|
||||||
isSuccess,
|
|
||||||
isError,
|
|
||||||
size,
|
|
||||||
}: TestConnectionIconProps) => {
|
|
||||||
if (isPending) return <Loader color="blue" size={size} />;
|
if (isPending) return <Loader color="blue" size={size} />;
|
||||||
if (isDirty) return null;
|
if (isDirty) return null;
|
||||||
if (isSuccess) return <IconCheck size={size} stroke={1.5} color="green" />;
|
if (isSuccess) return <IconCheck size={size} stroke={1.5} color="green" />;
|
||||||
@@ -142,12 +122,7 @@ const TestConnectionIcon = ({
|
|||||||
export const TestConnectionNoticeAlert = () => {
|
export const TestConnectionNoticeAlert = () => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
return (
|
return (
|
||||||
<Alert
|
<Alert variant="light" color="yellow" title="Test Connection" icon={<IconInfoCircle />}>
|
||||||
variant="light"
|
|
||||||
color="yellow"
|
|
||||||
title="Test Connection"
|
|
||||||
icon={<IconInfoCircle />}
|
|
||||||
>
|
|
||||||
{t("integration.testConnection.alertNotice")}
|
{t("integration.testConnection.alertNotice")}
|
||||||
</Alert>
|
</Alert>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,16 +6,10 @@ import { Button, Fieldset, Group, Stack, TextInput } from "@mantine/core";
|
|||||||
|
|
||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import {
|
import { getAllSecretKindOptions, getDefaultSecretKinds } from "@homarr/definitions";
|
||||||
getAllSecretKindOptions,
|
import { useZodForm } from "@homarr/form";
|
||||||
getDefaultSecretKinds,
|
|
||||||
} from "@homarr/definitions";
|
|
||||||
import { useForm, zodResolver } from "@homarr/form";
|
|
||||||
import { useConfirmModal } from "@homarr/modals";
|
import { useConfirmModal } from "@homarr/modals";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useI18n } from "@homarr/translation/client";
|
import { useI18n } from "@homarr/translation/client";
|
||||||
import type { z } from "@homarr/validation";
|
import type { z } from "@homarr/validation";
|
||||||
import { validation } from "@homarr/validation";
|
import { validation } from "@homarr/validation";
|
||||||
@@ -23,11 +17,7 @@ import { validation } from "@homarr/validation";
|
|||||||
import { revalidatePathActionAsync } from "~/app/revalidatePathAction";
|
import { revalidatePathActionAsync } from "~/app/revalidatePathAction";
|
||||||
import { SecretCard } from "../../_integration-secret-card";
|
import { SecretCard } from "../../_integration-secret-card";
|
||||||
import { IntegrationSecretInput } from "../../_integration-secret-inputs";
|
import { IntegrationSecretInput } from "../../_integration-secret-inputs";
|
||||||
import {
|
import { TestConnection, TestConnectionNoticeAlert, useTestConnectionDirty } from "../../_integration-test-connection";
|
||||||
TestConnection,
|
|
||||||
TestConnectionNoticeAlert,
|
|
||||||
useTestConnectionDirty,
|
|
||||||
} from "../../_integration-test-connection";
|
|
||||||
|
|
||||||
interface EditIntegrationForm {
|
interface EditIntegrationForm {
|
||||||
integration: RouterOutputs["integration"]["byId"];
|
integration: RouterOutputs["integration"]["byId"];
|
||||||
@@ -45,8 +35,7 @@ export const EditIntegrationForm = ({ integration }: EditIntegrationForm) => {
|
|||||||
url: integration.url,
|
url: integration.url,
|
||||||
secrets: secretsKinds.map((kind) => ({
|
secrets: secretsKinds.map((kind) => ({
|
||||||
kind,
|
kind,
|
||||||
value:
|
value: integration.secrets.find((secret) => secret.kind === kind)?.value ?? "",
|
||||||
integration.secrets.find((secret) => secret.kind === kind)?.value ?? "",
|
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
const { isDirty, onValuesChange, removeDirty } = useTestConnectionDirty({
|
const { isDirty, onValuesChange, removeDirty } = useTestConnectionDirty({
|
||||||
@@ -55,16 +44,13 @@ export const EditIntegrationForm = ({ integration }: EditIntegrationForm) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const form = useForm<FormType>({
|
const form = useZodForm(validation.integration.update.omit({ id: true }), {
|
||||||
initialValues: initialFormValues,
|
initialValues: initialFormValues,
|
||||||
validate: zodResolver(validation.integration.update.omit({ id: true })),
|
|
||||||
onValuesChange,
|
onValuesChange,
|
||||||
});
|
});
|
||||||
const { mutateAsync, isPending } = clientApi.integration.update.useMutation();
|
const { mutateAsync, isPending } = clientApi.integration.update.useMutation();
|
||||||
|
|
||||||
const secretsMap = new Map(
|
const secretsMap = new Map(integration.secrets.map((secret) => [secret.kind, secret]));
|
||||||
integration.secrets.map((secret) => [secret.kind, secret]),
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleSubmitAsync = async (values: FormType) => {
|
const handleSubmitAsync = async (values: FormType) => {
|
||||||
if (isDirty) return;
|
if (isDirty) return;
|
||||||
@@ -83,9 +69,7 @@ export const EditIntegrationForm = ({ integration }: EditIntegrationForm) => {
|
|||||||
title: t("integration.page.edit.notification.success.title"),
|
title: t("integration.page.edit.notification.success.title"),
|
||||||
message: t("integration.page.edit.notification.success.message"),
|
message: t("integration.page.edit.notification.success.message"),
|
||||||
});
|
});
|
||||||
void revalidatePathActionAsync("/manage/integrations").then(() =>
|
void revalidatePathActionAsync("/manage/integrations").then(() => router.push("/manage/integrations"));
|
||||||
router.push("/manage/integrations"),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
showErrorNotification({
|
showErrorNotification({
|
||||||
@@ -102,15 +86,9 @@ export const EditIntegrationForm = ({ integration }: EditIntegrationForm) => {
|
|||||||
<Stack>
|
<Stack>
|
||||||
<TestConnectionNoticeAlert />
|
<TestConnectionNoticeAlert />
|
||||||
|
|
||||||
<TextInput
|
<TextInput withAsterisk label={t("integration.field.name.label")} {...form.getInputProps("name")} />
|
||||||
label={t("integration.field.name.label")}
|
|
||||||
{...form.getInputProps("name")}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextInput
|
<TextInput withAsterisk label={t("integration.field.url.label")} {...form.getInputProps("url")} />
|
||||||
label={t("integration.field.url.label")}
|
|
||||||
{...form.getInputProps("url")}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Fieldset legend={t("integration.secrets.title")}>
|
<Fieldset legend={t("integration.secrets.title")}>
|
||||||
<Stack gap="sm">
|
<Stack gap="sm">
|
||||||
@@ -121,10 +99,7 @@ export const EditIntegrationForm = ({ integration }: EditIntegrationForm) => {
|
|||||||
onCancel={() =>
|
onCancel={() =>
|
||||||
new Promise((res) => {
|
new Promise((res) => {
|
||||||
// When nothing changed, just close the secret card
|
// When nothing changed, just close the secret card
|
||||||
if (
|
if ((form.values.secrets[index]?.value ?? "") === (secretsMap.get(kind)?.value ?? "")) {
|
||||||
(form.values.secrets[index]?.value ?? "") ===
|
|
||||||
(secretsMap.get(kind)?.value ?? "")
|
|
||||||
) {
|
|
||||||
return res(true);
|
return res(true);
|
||||||
}
|
}
|
||||||
openConfirmModal({
|
openConfirmModal({
|
||||||
@@ -132,10 +107,7 @@ export const EditIntegrationForm = ({ integration }: EditIntegrationForm) => {
|
|||||||
children: t("integration.secrets.reset.message"),
|
children: t("integration.secrets.reset.message"),
|
||||||
onCancel: () => res(false),
|
onCancel: () => res(false),
|
||||||
onConfirm: () => {
|
onConfirm: () => {
|
||||||
form.setFieldValue(
|
form.setFieldValue(`secrets.${index}.value`, secretsMap.get(kind)!.value ?? "");
|
||||||
`secrets.${index}.value`,
|
|
||||||
secretsMap.get(kind)!.value ?? "",
|
|
||||||
);
|
|
||||||
res(true);
|
res(true);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -164,11 +136,7 @@ export const EditIntegrationForm = ({ integration }: EditIntegrationForm) => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Group>
|
<Group>
|
||||||
<Button
|
<Button variant="default" component={Link} href="/manage/integrations">
|
||||||
variant="default"
|
|
||||||
component={Link}
|
|
||||||
href="/manage/integrations"
|
|
||||||
>
|
|
||||||
{t("common.action.backToOverview")}
|
{t("common.action.backToOverview")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" loading={isPending} disabled={isDirty}>
|
<Button type="submit" loading={isPending} disabled={isDirty}>
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ interface EditIntegrationPageProps {
|
|||||||
params: { id: string };
|
params: { id: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function EditIntegrationPage({
|
export default async function EditIntegrationPage({ params }: EditIntegrationPageProps) {
|
||||||
params,
|
|
||||||
}: EditIntegrationPageProps) {
|
|
||||||
const t = await getScopedI18n("integration.page.edit");
|
const t = await getScopedI18n("integration.page.edit");
|
||||||
const integration = await api.integration.byId({ id: params.id });
|
const integration = await api.integration.byId({ id: params.id });
|
||||||
|
|
||||||
@@ -22,9 +20,7 @@ export default async function EditIntegrationPage({
|
|||||||
<Stack>
|
<Stack>
|
||||||
<Group align="center">
|
<Group align="center">
|
||||||
<IntegrationAvatar kind={integration.kind} size="md" />
|
<IntegrationAvatar kind={integration.kind} size="md" />
|
||||||
<Title>
|
<Title>{t("title", { name: getIntegrationName(integration.kind) })}</Title>
|
||||||
{t("title", { name: getIntegrationName(integration.kind) })}
|
|
||||||
</Title>
|
|
||||||
</Group>
|
</Group>
|
||||||
<EditIntegrationForm integration={integration} />
|
<EditIntegrationForm integration={integration} />
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -16,9 +16,7 @@ export const IntegrationCreateDropdownContent = () => {
|
|||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
|
|
||||||
const filteredKinds = useMemo(() => {
|
const filteredKinds = useMemo(() => {
|
||||||
return integrationKinds.filter((kind) =>
|
return integrationKinds.filter((kind) => kind.includes(search.toLowerCase()));
|
||||||
kind.includes(search.toLowerCase()),
|
|
||||||
);
|
|
||||||
}, [search]);
|
}, [search]);
|
||||||
|
|
||||||
const handleSearch = React.useCallback(
|
const handleSearch = React.useCallback(
|
||||||
@@ -38,11 +36,7 @@ export const IntegrationCreateDropdownContent = () => {
|
|||||||
{filteredKinds.length > 0 ? (
|
{filteredKinds.length > 0 ? (
|
||||||
<ScrollArea.Autosize mah={384}>
|
<ScrollArea.Autosize mah={384}>
|
||||||
{filteredKinds.map((kind) => (
|
{filteredKinds.map((kind) => (
|
||||||
<Menu.Item
|
<Menu.Item component={Link} href={`/manage/integrations/new?kind=${kind}`} key={kind}>
|
||||||
component={Link}
|
|
||||||
href={`/manage/integrations/new?kind=${kind}`}
|
|
||||||
key={kind}
|
|
||||||
>
|
|
||||||
<Group>
|
<Group>
|
||||||
<IntegrationAvatar kind={kind} size="sm" />
|
<IntegrationAvatar kind={kind} size="sm" />
|
||||||
<Text size="sm">{getIntegrationName(kind)}</Text>
|
<Text size="sm">{getIntegrationName(kind)}</Text>
|
||||||
|
|||||||
@@ -3,37 +3,20 @@
|
|||||||
import { useCallback } from "react";
|
import { useCallback } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import {
|
import { Button, Fieldset, Group, SegmentedControl, Stack, TextInput } from "@mantine/core";
|
||||||
Button,
|
|
||||||
Fieldset,
|
|
||||||
Group,
|
|
||||||
SegmentedControl,
|
|
||||||
Stack,
|
|
||||||
TextInput,
|
|
||||||
} from "@mantine/core";
|
|
||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import type {
|
import type { IntegrationKind, IntegrationSecretKind } from "@homarr/definitions";
|
||||||
IntegrationKind,
|
|
||||||
IntegrationSecretKind,
|
|
||||||
} from "@homarr/definitions";
|
|
||||||
import { getAllSecretKindOptions } from "@homarr/definitions";
|
import { getAllSecretKindOptions } from "@homarr/definitions";
|
||||||
import type { UseFormReturnType } from "@homarr/form";
|
import type { UseFormReturnType } from "@homarr/form";
|
||||||
import { useForm, zodResolver } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||||
import type { z } from "@homarr/validation";
|
import type { z } from "@homarr/validation";
|
||||||
import { validation } from "@homarr/validation";
|
import { validation } from "@homarr/validation";
|
||||||
|
|
||||||
import { IntegrationSecretInput } from "../_integration-secret-inputs";
|
import { IntegrationSecretInput } from "../_integration-secret-inputs";
|
||||||
import {
|
import { TestConnection, TestConnectionNoticeAlert, useTestConnectionDirty } from "../_integration-test-connection";
|
||||||
TestConnection,
|
|
||||||
TestConnectionNoticeAlert,
|
|
||||||
useTestConnectionDirty,
|
|
||||||
} from "../_integration-test-connection";
|
|
||||||
import { revalidatePathActionAsync } from "../../../../revalidatePathAction";
|
import { revalidatePathActionAsync } from "../../../../revalidatePathAction";
|
||||||
|
|
||||||
interface NewIntegrationFormProps {
|
interface NewIntegrationFormProps {
|
||||||
@@ -42,9 +25,7 @@ interface NewIntegrationFormProps {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const NewIntegrationForm = ({
|
export const NewIntegrationForm = ({ searchParams }: NewIntegrationFormProps) => {
|
||||||
searchParams,
|
|
||||||
}: NewIntegrationFormProps) => {
|
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const secretKinds = getAllSecretKindOptions(searchParams.kind);
|
const secretKinds = getAllSecretKindOptions(searchParams.kind);
|
||||||
const initialFormValues = {
|
const initialFormValues = {
|
||||||
@@ -60,9 +41,8 @@ export const NewIntegrationForm = ({
|
|||||||
initialFormValue: initialFormValues,
|
initialFormValue: initialFormValues,
|
||||||
});
|
});
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const form = useForm<FormType>({
|
const form = useZodForm(validation.integration.create.omit({ kind: true }), {
|
||||||
initialValues: initialFormValues,
|
initialValues: initialFormValues,
|
||||||
validate: zodResolver(validation.integration.create.omit({ kind: true })),
|
|
||||||
onValuesChange,
|
onValuesChange,
|
||||||
});
|
});
|
||||||
const { mutateAsync, isPending } = clientApi.integration.create.useMutation();
|
const { mutateAsync, isPending } = clientApi.integration.create.useMutation();
|
||||||
@@ -80,9 +60,7 @@ export const NewIntegrationForm = ({
|
|||||||
title: t("integration.page.create.notification.success.title"),
|
title: t("integration.page.create.notification.success.title"),
|
||||||
message: t("integration.page.create.notification.success.message"),
|
message: t("integration.page.create.notification.success.message"),
|
||||||
});
|
});
|
||||||
void revalidatePathActionAsync("/manage/integrations").then(() =>
|
void revalidatePathActionAsync("/manage/integrations").then(() => router.push("/manage/integrations"));
|
||||||
router.push("/manage/integrations"),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
showErrorNotification({
|
showErrorNotification({
|
||||||
@@ -99,26 +77,16 @@ export const NewIntegrationForm = ({
|
|||||||
<Stack>
|
<Stack>
|
||||||
<TestConnectionNoticeAlert />
|
<TestConnectionNoticeAlert />
|
||||||
|
|
||||||
<TextInput
|
<TextInput withAsterisk label={t("integration.field.name.label")} {...form.getInputProps("name")} />
|
||||||
label={t("integration.field.name.label")}
|
|
||||||
{...form.getInputProps("name")}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextInput
|
<TextInput withAsterisk label={t("integration.field.url.label")} {...form.getInputProps("url")} />
|
||||||
label={t("integration.field.url.label")}
|
|
||||||
{...form.getInputProps("url")}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Fieldset legend={t("integration.secrets.title")}>
|
<Fieldset legend={t("integration.secrets.title")}>
|
||||||
<Stack gap="sm">
|
<Stack gap="sm">
|
||||||
{secretKinds.length > 1 && (
|
{secretKinds.length > 1 && <SecretKindsSegmentedControl secretKinds={secretKinds} form={form} />}
|
||||||
<SecretKindsSegmentedControl
|
|
||||||
secretKinds={secretKinds}
|
|
||||||
form={form}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{form.values.secrets.map(({ kind }, index) => (
|
{form.values.secrets.map(({ kind }, index) => (
|
||||||
<IntegrationSecretInput
|
<IntegrationSecretInput
|
||||||
|
withAsterisk
|
||||||
key={kind}
|
key={kind}
|
||||||
kind={kind}
|
kind={kind}
|
||||||
{...form.getInputProps(`secrets.${index}.value`)}
|
{...form.getInputProps(`secrets.${index}.value`)}
|
||||||
@@ -139,11 +107,7 @@ export const NewIntegrationForm = ({
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<Button
|
<Button variant="default" component={Link} href="/manage/integrations">
|
||||||
variant="default"
|
|
||||||
component={Link}
|
|
||||||
href="/manage/integrations"
|
|
||||||
>
|
|
||||||
{t("common.action.backToOverview")}
|
{t("common.action.backToOverview")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" loading={isPending} disabled={isDirty}>
|
<Button type="submit" loading={isPending} disabled={isDirty}>
|
||||||
@@ -161,10 +125,7 @@ interface SecretKindsSegmentedControlProps {
|
|||||||
form: UseFormReturnType<FormType, (values: FormType) => FormType>;
|
form: UseFormReturnType<FormType, (values: FormType) => FormType>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SecretKindsSegmentedControl = ({
|
const SecretKindsSegmentedControl = ({ secretKinds, form }: SecretKindsSegmentedControlProps) => {
|
||||||
secretKinds,
|
|
||||||
form,
|
|
||||||
}: SecretKindsSegmentedControlProps) => {
|
|
||||||
const t = useScopedI18n("integration.secrets");
|
const t = useScopedI18n("integration.secrets");
|
||||||
|
|
||||||
const secretKindGroups = secretKinds.map((kinds) => ({
|
const secretKindGroups = secretKinds.map((kinds) => ({
|
||||||
@@ -184,13 +145,7 @@ const SecretKindsSegmentedControl = ({
|
|||||||
[form],
|
[form],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return <SegmentedControl fullWidth data={secretKindGroups} onChange={onChange}></SegmentedControl>;
|
||||||
<SegmentedControl
|
|
||||||
fullWidth
|
|
||||||
data={secretKindGroups}
|
|
||||||
onChange={onChange}
|
|
||||||
></SegmentedControl>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type FormType = Omit<z.infer<typeof validation.integration.create>, "kind">;
|
type FormType = Omit<z.infer<typeof validation.integration.create>, "kind">;
|
||||||
|
|||||||
@@ -16,12 +16,8 @@ interface NewIntegrationPageProps {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function IntegrationsNewPage({
|
export default async function IntegrationsNewPage({ searchParams }: NewIntegrationPageProps) {
|
||||||
searchParams,
|
const result = z.enum([integrationKinds[0]!, ...integrationKinds.slice(1)]).safeParse(searchParams.kind);
|
||||||
}: NewIntegrationPageProps) {
|
|
||||||
const result = z
|
|
||||||
.enum([integrationKinds[0]!, ...integrationKinds.slice(1)])
|
|
||||||
.safeParse(searchParams.kind);
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,9 +43,7 @@ interface IntegrationsPageProps {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function IntegrationsPage({
|
export default async function IntegrationsPage({ searchParams }: IntegrationsPageProps) {
|
||||||
searchParams,
|
|
||||||
}: IntegrationsPageProps) {
|
|
||||||
const integrations = await api.integration.all();
|
const integrations = await api.integration.all();
|
||||||
const t = await getScopedI18n("integration");
|
const t = await getScopedI18n("integration");
|
||||||
|
|
||||||
@@ -54,18 +52,9 @@ export default async function IntegrationsPage({
|
|||||||
<Stack>
|
<Stack>
|
||||||
<Group justify="space-between" align="center">
|
<Group justify="space-between" align="center">
|
||||||
<Title>{t("page.list.title")}</Title>
|
<Title>{t("page.list.title")}</Title>
|
||||||
<Menu
|
<Menu width={256} trapFocus position="bottom-start" withinPortal shadow="md" keepMounted={false}>
|
||||||
width={256}
|
|
||||||
trapFocus
|
|
||||||
position="bottom-start"
|
|
||||||
withinPortal
|
|
||||||
shadow="md"
|
|
||||||
keepMounted={false}
|
|
||||||
>
|
|
||||||
<MenuTarget>
|
<MenuTarget>
|
||||||
<Button rightSection={<IconChevronDown size={16} stroke={1.5} />}>
|
<Button rightSection={<IconChevronDown size={16} stroke={1.5} />}>{t("action.create")}</Button>
|
||||||
{t("action.create")}
|
|
||||||
</Button>
|
|
||||||
</MenuTarget>
|
</MenuTarget>
|
||||||
<MenuDropdown>
|
<MenuDropdown>
|
||||||
<IntegrationCreateDropdownContent />
|
<IntegrationCreateDropdownContent />
|
||||||
@@ -73,10 +62,7 @@ export default async function IntegrationsPage({
|
|||||||
</Menu>
|
</Menu>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
<IntegrationList
|
<IntegrationList integrations={integrations} activeTab={searchParams.tab} />
|
||||||
integrations={integrations}
|
|
||||||
activeTab={searchParams.tab}
|
|
||||||
/>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
@@ -87,10 +73,7 @@ interface IntegrationListProps {
|
|||||||
activeTab?: IntegrationKind;
|
activeTab?: IntegrationKind;
|
||||||
}
|
}
|
||||||
|
|
||||||
const IntegrationList = async ({
|
const IntegrationList = async ({ integrations, activeTab }: IntegrationListProps) => {
|
||||||
integrations,
|
|
||||||
activeTab,
|
|
||||||
}: IntegrationListProps) => {
|
|
||||||
const t = await getScopedI18n("integration");
|
const t = await getScopedI18n("integration");
|
||||||
|
|
||||||
if (integrations.length === 0) {
|
if (integrations.length === 0) {
|
||||||
@@ -134,12 +117,7 @@ const IntegrationList = async ({
|
|||||||
<TableTr key={integration.id}>
|
<TableTr key={integration.id}>
|
||||||
<TableTd>{integration.name}</TableTd>
|
<TableTd>{integration.name}</TableTd>
|
||||||
<TableTd>
|
<TableTd>
|
||||||
<Anchor
|
<Anchor href={integration.url} target="_blank" rel="noreferrer" size="sm">
|
||||||
href={integration.url}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
{integration.url}
|
{integration.url}
|
||||||
</Anchor>
|
</Anchor>
|
||||||
</TableTd>
|
</TableTd>
|
||||||
@@ -155,10 +133,7 @@ const IntegrationList = async ({
|
|||||||
>
|
>
|
||||||
<IconPencil size={16} stroke={1.5} />
|
<IconPencil size={16} stroke={1.5} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
<DeleteIntegrationActionButton
|
<DeleteIntegrationActionButton integration={integration} count={integrations.length} />
|
||||||
integration={integration}
|
|
||||||
count={integrations.length}
|
|
||||||
/>
|
|
||||||
</ActionIconGroup>
|
</ActionIconGroup>
|
||||||
</Group>
|
</Group>
|
||||||
</TableTd>
|
</TableTd>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
IconMailForward,
|
IconMailForward,
|
||||||
IconPlug,
|
IconPlug,
|
||||||
IconQuestionMark,
|
IconQuestionMark,
|
||||||
|
IconSettings,
|
||||||
IconTool,
|
IconTool,
|
||||||
IconUser,
|
IconUser,
|
||||||
IconUsers,
|
IconUsers,
|
||||||
@@ -87,6 +88,11 @@ export default async function ManageLayout({ children }: PropsWithChildren) {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: t("items.settings"),
|
||||||
|
href: "/manage/settings",
|
||||||
|
icon: IconSettings,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: t("items.help.label"),
|
label: t("items.help.label"),
|
||||||
icon: IconQuestionMark,
|
icon: IconQuestionMark,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { IconArrowRight } from "@tabler/icons-react";
|
|||||||
import { api } from "@homarr/api/server";
|
import { api } from "@homarr/api/server";
|
||||||
import { getScopedI18n } from "@homarr/translation/server";
|
import { getScopedI18n } from "@homarr/translation/server";
|
||||||
|
|
||||||
|
import { createMetaTitle } from "~/metadata";
|
||||||
import { HeroBanner } from "./_components/hero-banner";
|
import { HeroBanner } from "./_components/hero-banner";
|
||||||
|
|
||||||
interface LinkProps {
|
interface LinkProps {
|
||||||
@@ -16,10 +17,9 @@ interface LinkProps {
|
|||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const t = await getScopedI18n("management");
|
const t = await getScopedI18n("management");
|
||||||
const metaTitle = `${t("metaTitle")} • Homarr`;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: metaTitle,
|
title: createMetaTitle(t("metaTitle")),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,12 +71,7 @@ export default async function ManagementPage() {
|
|||||||
<Space h="md" />
|
<Space h="md" />
|
||||||
<SimpleGrid cols={{ xs: 1, sm: 2, md: 3 }}>
|
<SimpleGrid cols={{ xs: 1, sm: 2, md: 3 }}>
|
||||||
{links.map((link, index) => (
|
{links.map((link, index) => (
|
||||||
<Card
|
<Card component={Link} href={link.href} key={`link-${index}`} withBorder>
|
||||||
component={Link}
|
|
||||||
href={link.href}
|
|
||||||
key={`link-${index}`}
|
|
||||||
withBorder
|
|
||||||
>
|
|
||||||
<Group justify="space-between">
|
<Group justify="space-between">
|
||||||
<Group>
|
<Group>
|
||||||
<Text size="2.4rem" fw="bolder">
|
<Text size="2.4rem" fw="bolder">
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import type { ReactNode } from "react";
|
||||||
|
import React from "react";
|
||||||
|
import type { MantineSpacing } from "@mantine/core";
|
||||||
|
import { Card, Group, LoadingOverlay, Stack, Switch, Text, Title, UnstyledButton } from "@mantine/core";
|
||||||
|
|
||||||
|
import { clientApi } from "@homarr/api/client";
|
||||||
|
import type { UseFormReturnType } from "@homarr/form";
|
||||||
|
import { useForm } from "@homarr/form";
|
||||||
|
import type { defaultServerSettings } from "@homarr/server-settings";
|
||||||
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
|
import { revalidatePathActionAsync } from "~/app/revalidatePathAction";
|
||||||
|
|
||||||
|
interface AnalyticsSettingsProps {
|
||||||
|
initialData: typeof defaultServerSettings.analytics;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AnalyticsSettings = ({ initialData }: AnalyticsSettingsProps) => {
|
||||||
|
const t = useScopedI18n("management.page.settings.section.analytics");
|
||||||
|
const form = useForm({
|
||||||
|
initialValues: initialData,
|
||||||
|
onValuesChange: (updatedValues, _) => {
|
||||||
|
if (!form.isValid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!updatedValues.enableGeneral &&
|
||||||
|
(updatedValues.enableWidgetData || updatedValues.enableIntegrationData || updatedValues.enableUserData)
|
||||||
|
) {
|
||||||
|
updatedValues.enableIntegrationData = false;
|
||||||
|
updatedValues.enableUserData = false;
|
||||||
|
updatedValues.enableWidgetData = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mutateAsync({
|
||||||
|
settingsKey: "analytics",
|
||||||
|
value: updatedValues,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const { mutateAsync, isPending } = clientApi.serverSettings.saveSettings.useMutation({
|
||||||
|
onSettled: async () => {
|
||||||
|
await revalidatePathActionAsync("/manage/settings");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Title order={2}>{t("title")}</Title>
|
||||||
|
|
||||||
|
<Card pos="relative" withBorder>
|
||||||
|
<LoadingOverlay visible={isPending} zIndex={1000} overlayProps={{ radius: "sm", blur: 2 }} />
|
||||||
|
<Stack>
|
||||||
|
<SwitchSetting form={form} formKey="enableGeneral" title={t("general.title")} text={t("general.text")} />
|
||||||
|
<SwitchSetting
|
||||||
|
form={form}
|
||||||
|
formKey="enableIntegrationData"
|
||||||
|
ms="xl"
|
||||||
|
title={t("integrationData.title")}
|
||||||
|
text={t("integrationData.text")}
|
||||||
|
/>
|
||||||
|
<SwitchSetting
|
||||||
|
form={form}
|
||||||
|
formKey="enableWidgetData"
|
||||||
|
ms="xl"
|
||||||
|
title={t("widgetData.title")}
|
||||||
|
text={t("widgetData.text")}
|
||||||
|
/>
|
||||||
|
<SwitchSetting
|
||||||
|
form={form}
|
||||||
|
formKey="enableUserData"
|
||||||
|
ms="xl"
|
||||||
|
title={t("usersData.title")}
|
||||||
|
text={t("usersData.text")}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const SwitchSetting = ({
|
||||||
|
form,
|
||||||
|
ms,
|
||||||
|
title,
|
||||||
|
text,
|
||||||
|
formKey,
|
||||||
|
}: {
|
||||||
|
form: UseFormReturnType<typeof defaultServerSettings.analytics>;
|
||||||
|
formKey: keyof typeof defaultServerSettings.analytics;
|
||||||
|
ms?: MantineSpacing;
|
||||||
|
title: string;
|
||||||
|
text: ReactNode;
|
||||||
|
}) => {
|
||||||
|
const handleClick = React.useCallback(() => {
|
||||||
|
form.setFieldValue(formKey, !form.values[formKey]);
|
||||||
|
}, [form, formKey]);
|
||||||
|
return (
|
||||||
|
<UnstyledButton onClick={handleClick}>
|
||||||
|
<Group ms={ms} justify="space-between" gap="lg" align="center" wrap="nowrap">
|
||||||
|
<Stack gap={0}>
|
||||||
|
<Text fw="bold">{title}</Text>
|
||||||
|
<Text c="gray.5">{text}</Text>
|
||||||
|
</Stack>
|
||||||
|
<Switch {...form.getInputProps(formKey, { type: "checkbox" })} />
|
||||||
|
</Group>
|
||||||
|
</UnstyledButton>
|
||||||
|
);
|
||||||
|
};
|
||||||
26
apps/nextjs/src/app/[locale]/manage/settings/page.tsx
Normal file
26
apps/nextjs/src/app/[locale]/manage/settings/page.tsx
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { Stack, Title } from "@mantine/core";
|
||||||
|
|
||||||
|
import { api } from "@homarr/api/server";
|
||||||
|
import { getScopedI18n } from "@homarr/translation/server";
|
||||||
|
|
||||||
|
import { AnalyticsSettings } from "./_components/analytics.settings";
|
||||||
|
|
||||||
|
export async function generateMetadata() {
|
||||||
|
const t = await getScopedI18n("management");
|
||||||
|
const metaTitle = `${t("metaTitle")} • Homarr`;
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: metaTitle,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function SettingsPage() {
|
||||||
|
const serverSettings = await api.serverSettings.getAll();
|
||||||
|
const t = await getScopedI18n("management.page.settings");
|
||||||
|
return (
|
||||||
|
<Stack>
|
||||||
|
<Title order={1}>{t("title")}</Title>
|
||||||
|
<AnalyticsSettings initialData={serverSettings.analytics} />
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -7,13 +7,13 @@ import "@xterm/xterm/css/xterm.css";
|
|||||||
import dynamic from "next/dynamic";
|
import dynamic from "next/dynamic";
|
||||||
|
|
||||||
import { fullHeightWithoutHeaderAndFooter } from "~/constants";
|
import { fullHeightWithoutHeaderAndFooter } from "~/constants";
|
||||||
|
import { createMetaTitle } from "~/metadata";
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const t = await getScopedI18n("management");
|
const t = await getScopedI18n("management");
|
||||||
const metaTitle = `${t("metaTitle")} • Homarr`;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: metaTitle,
|
title: createMetaTitle(t("metaTitle")),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,12 +23,7 @@ const ClientSideTerminalComponent = dynamic(() => import("./terminal"), {
|
|||||||
|
|
||||||
export default function LogsManagementPage() {
|
export default function LogsManagementPage() {
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box style={{ borderRadius: 6 }} h={fullHeightWithoutHeaderAndFooter} p="md" bg="black">
|
||||||
style={{ borderRadius: 6 }}
|
|
||||||
h={fullHeightWithoutHeaderAndFooter}
|
|
||||||
p="md"
|
|
||||||
bg="black"
|
|
||||||
>
|
|
||||||
<ClientSideTerminalComponent />
|
<ClientSideTerminalComponent />
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -16,9 +16,7 @@ export default function TerminalComponent() {
|
|||||||
const terminalRef = useRef<Terminal>();
|
const terminalRef = useRef<Terminal>();
|
||||||
clientApi.log.subscribe.useSubscription(undefined, {
|
clientApi.log.subscribe.useSubscription(undefined, {
|
||||||
onData(data) {
|
onData(data) {
|
||||||
terminalRef.current?.writeln(
|
terminalRef.current?.writeln(`${data.timestamp} ${data.level} ${data.message}`);
|
||||||
`${data.timestamp} ${data.level} ${data.message}`,
|
|
||||||
);
|
|
||||||
terminalRef.current?.refresh(0, terminalRef.current.rows - 1);
|
terminalRef.current?.refresh(0, terminalRef.current.rows - 1);
|
||||||
},
|
},
|
||||||
onError(err) {
|
onError(err) {
|
||||||
@@ -55,12 +53,5 @@ export default function TerminalComponent() {
|
|||||||
canvasAddon.dispose();
|
canvasAddon.dispose();
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
return (
|
return <Box ref={ref} id="terminal" className={classes.outerTerminal} h="100%"></Box>;
|
||||||
<Box
|
|
||||||
ref={ref}
|
|
||||||
id="terminal"
|
|
||||||
className={classes.outerTerminal}
|
|
||||||
h="100%"
|
|
||||||
></Box>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import type { Session } from "@homarr/auth";
|
import type { Session } from "@homarr/auth";
|
||||||
|
|
||||||
export const canAccessUserEditPage = (
|
export const canAccessUserEditPage = (session: Session | null, userId: string) => {
|
||||||
session: Session | null,
|
|
||||||
userId: string,
|
|
||||||
) => {
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,11 @@ interface DeleteUserButtonProps {
|
|||||||
export const DeleteUserButton = ({ user }: DeleteUserButtonProps) => {
|
export const DeleteUserButton = ({ user }: DeleteUserButtonProps) => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { mutateAsync: mutateUserDeletionAsync } =
|
const { mutateAsync: mutateUserDeletionAsync } = clientApi.user.delete.useMutation({
|
||||||
clientApi.user.delete.useMutation({
|
async onSuccess() {
|
||||||
async onSuccess() {
|
await revalidatePathActionAsync("/manage/users").then(() => router.push("/manage/users"));
|
||||||
await revalidatePathActionAsync("/manage/users").then(() =>
|
},
|
||||||
router.push("/manage/users"),
|
});
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const { openConfirmModal } = useConfirmModal();
|
const { openConfirmModal } = useConfirmModal();
|
||||||
|
|
||||||
const handleDelete = useCallback(
|
const handleDelete = useCallback(
|
||||||
@@ -8,10 +8,7 @@ import { IconPencil, IconPhotoEdit, IconPhotoX } from "@tabler/icons-react";
|
|||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useConfirmModal } from "@homarr/modals";
|
import { useConfirmModal } from "@homarr/modals";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||||
import { UserAvatar } from "@homarr/ui";
|
import { UserAvatar } from "@homarr/ui";
|
||||||
|
|
||||||
@@ -46,25 +43,18 @@ export const UserProfileAvatarForm = ({ user }: UserProfileAvatarForm) => {
|
|||||||
// Revalidate all as the avatar is used in multiple places
|
// Revalidate all as the avatar is used in multiple places
|
||||||
await revalidatePathActionAsync("/");
|
await revalidatePathActionAsync("/");
|
||||||
showSuccessNotification({
|
showSuccessNotification({
|
||||||
message: tManageAvatar(
|
message: tManageAvatar("changeImage.notification.success.message"),
|
||||||
"changeImage.notification.success.message",
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onError(error) {
|
onError(error) {
|
||||||
if (error.shape?.data.code === "BAD_REQUEST") {
|
if (error.shape?.data.code === "BAD_REQUEST") {
|
||||||
showErrorNotification({
|
showErrorNotification({
|
||||||
title: tManageAvatar("changeImage.notification.toLarge.title"),
|
title: tManageAvatar("changeImage.notification.toLarge.title"),
|
||||||
message: tManageAvatar(
|
message: tManageAvatar("changeImage.notification.toLarge.message", { size: "256KB" }),
|
||||||
"changeImage.notification.toLarge.message",
|
|
||||||
{ size: "256KB" },
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
showErrorNotification({
|
showErrorNotification({
|
||||||
message: tManageAvatar(
|
message: tManageAvatar("changeImage.notification.error.message"),
|
||||||
"changeImage.notification.error.message",
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -89,16 +79,12 @@ export const UserProfileAvatarForm = ({ user }: UserProfileAvatarForm) => {
|
|||||||
// Revalidate all as the avatar is used in multiple places
|
// Revalidate all as the avatar is used in multiple places
|
||||||
await revalidatePathActionAsync("/");
|
await revalidatePathActionAsync("/");
|
||||||
showSuccessNotification({
|
showSuccessNotification({
|
||||||
message: tManageAvatar(
|
message: tManageAvatar("removeImage.notification.success.message"),
|
||||||
"removeImage.notification.success.message",
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onError() {
|
onError() {
|
||||||
showErrorNotification({
|
showErrorNotification({
|
||||||
message: tManageAvatar(
|
message: tManageAvatar("removeImage.notification.error.message"),
|
||||||
"removeImage.notification.error.message",
|
|
||||||
),
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -109,13 +95,7 @@ export const UserProfileAvatarForm = ({ user }: UserProfileAvatarForm) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Box pos="relative">
|
<Box pos="relative">
|
||||||
<Menu
|
<Menu opened={opened} keepMounted onChange={toggle} position="bottom-start" withArrow>
|
||||||
opened={opened}
|
|
||||||
keepMounted
|
|
||||||
onChange={toggle}
|
|
||||||
position="bottom-start"
|
|
||||||
withArrow
|
|
||||||
>
|
|
||||||
<Menu.Target>
|
<Menu.Target>
|
||||||
<UnstyledButton onClick={toggle}>
|
<UnstyledButton onClick={toggle}>
|
||||||
<UserAvatar user={user} size={200} />
|
<UserAvatar user={user} size={200} />
|
||||||
@@ -134,24 +114,15 @@ export const UserProfileAvatarForm = ({ user }: UserProfileAvatarForm) => {
|
|||||||
</UnstyledButton>
|
</UnstyledButton>
|
||||||
</Menu.Target>
|
</Menu.Target>
|
||||||
<Menu.Dropdown>
|
<Menu.Dropdown>
|
||||||
<FileButton
|
<FileButton onChange={handleAvatarChange} accept="image/png,image/jpeg,image/webp,image/gif">
|
||||||
onChange={handleAvatarChange}
|
|
||||||
accept="image/png,image/jpeg,image/webp,image/gif"
|
|
||||||
>
|
|
||||||
{(props) => (
|
{(props) => (
|
||||||
<Menu.Item
|
<Menu.Item {...props} leftSection={<IconPhotoEdit size={16} stroke={1.5} />}>
|
||||||
{...props}
|
|
||||||
leftSection={<IconPhotoEdit size={16} stroke={1.5} />}
|
|
||||||
>
|
|
||||||
{tManageAvatar("changeImage.label")}
|
{tManageAvatar("changeImage.label")}
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
)}
|
)}
|
||||||
</FileButton>
|
</FileButton>
|
||||||
{user.image && (
|
{user.image && (
|
||||||
<Menu.Item
|
<Menu.Item onClick={handleRemoveAvatar} leftSection={<IconPhotoX size={16} stroke={1.5} />}>
|
||||||
onClick={handleRemoveAvatar}
|
|
||||||
leftSection={<IconPhotoX size={16} stroke={1.5} />}
|
|
||||||
>
|
|
||||||
{tManageAvatar("removeImage.label")}
|
{tManageAvatar("removeImage.label")}
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
)}
|
)}
|
||||||
@@ -5,11 +5,8 @@ import { Button, Group, Stack, TextInput } from "@mantine/core";
|
|||||||
|
|
||||||
import type { RouterInputs, RouterOutputs } from "@homarr/api";
|
import type { RouterInputs, RouterOutputs } from "@homarr/api";
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useForm, zodResolver } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useI18n } from "@homarr/translation/client";
|
import { useI18n } from "@homarr/translation/client";
|
||||||
import { validation } from "@homarr/validation";
|
import { validation } from "@homarr/validation";
|
||||||
|
|
||||||
@@ -21,15 +18,6 @@ interface UserProfileFormProps {
|
|||||||
|
|
||||||
export const UserProfileForm = ({ user }: UserProfileFormProps) => {
|
export const UserProfileForm = ({ user }: UserProfileFormProps) => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const form = useForm({
|
|
||||||
initialValues: {
|
|
||||||
name: user.name ?? "",
|
|
||||||
email: user.email ?? "",
|
|
||||||
},
|
|
||||||
validate: zodResolver(validation.user.editProfile.omit({ id: true })),
|
|
||||||
validateInputOnBlur: true,
|
|
||||||
validateInputOnChange: true,
|
|
||||||
});
|
|
||||||
const { mutate, isPending } = clientApi.user.editProfile.useMutation({
|
const { mutate, isPending } = clientApi.user.editProfile.useMutation({
|
||||||
async onSettled() {
|
async onSettled() {
|
||||||
await revalidatePathActionAsync("/manage/users");
|
await revalidatePathActionAsync("/manage/users");
|
||||||
@@ -56,6 +44,12 @@ export const UserProfileForm = ({ user }: UserProfileFormProps) => {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const form = useZodForm(validation.user.editProfile.omit({ id: true }), {
|
||||||
|
initialValues: {
|
||||||
|
name: user.name ?? "",
|
||||||
|
email: user.email ?? "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const handleSubmit = useCallback(
|
const handleSubmit = useCallback(
|
||||||
(values: FormType) => {
|
(values: FormType) => {
|
||||||
@@ -70,23 +64,11 @@ export const UserProfileForm = ({ user }: UserProfileFormProps) => {
|
|||||||
return (
|
return (
|
||||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||||
<Stack>
|
<Stack>
|
||||||
<TextInput
|
<TextInput label={t("user.field.username.label")} withAsterisk {...form.getInputProps("name")} />
|
||||||
label={t("user.field.username.label")}
|
<TextInput label={t("user.field.email.label")} {...form.getInputProps("email")} />
|
||||||
withAsterisk
|
|
||||||
{...form.getInputProps("name")}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
label={t("user.field.email.label")}
|
|
||||||
{...form.getInputProps("email")}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Group justify="end">
|
<Group justify="end">
|
||||||
<Button
|
<Button type="submit" color="teal" disabled={!form.isDirty()} loading={isPending}>
|
||||||
type="submit"
|
|
||||||
color="teal"
|
|
||||||
disabled={!form.isDirty()}
|
|
||||||
loading={isPending}
|
|
||||||
>
|
|
||||||
{t("common.action.saveChanges")}
|
{t("common.action.saveChanges")}
|
||||||
</Button>
|
</Button>
|
||||||
</Group>
|
</Group>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { Stack, Title } from "@mantine/core";
|
||||||
|
|
||||||
|
import { LanguageCombobox } from "~/components/language/language-combobox";
|
||||||
|
|
||||||
|
export const ProfileLanguageChange = () => {
|
||||||
|
return (
|
||||||
|
<Stack mb="lg">
|
||||||
|
<Title order={2}>Language & Region</Title>
|
||||||
|
<LanguageCombobox />
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -5,15 +5,14 @@ import { api } from "@homarr/api/server";
|
|||||||
import { auth } from "@homarr/auth/next";
|
import { auth } from "@homarr/auth/next";
|
||||||
import { getI18n, getScopedI18n } from "@homarr/translation/server";
|
import { getI18n, getScopedI18n } from "@homarr/translation/server";
|
||||||
|
|
||||||
import {
|
import { DangerZoneItem, DangerZoneRoot } from "~/components/manage/danger-zone";
|
||||||
DangerZoneItem,
|
|
||||||
DangerZoneRoot,
|
|
||||||
} from "~/components/manage/danger-zone";
|
|
||||||
import { catchTrpcNotFound } from "~/errors/trpc-not-found";
|
import { catchTrpcNotFound } from "~/errors/trpc-not-found";
|
||||||
import { DeleteUserButton } from "./_delete-user-button";
|
import { createMetaTitle } from "~/metadata";
|
||||||
import { UserProfileAvatarForm } from "./_profile-avatar-form";
|
import { canAccessUserEditPage } from "../access";
|
||||||
import { UserProfileForm } from "./_profile-form";
|
import { DeleteUserButton } from "./_components/_delete-user-button";
|
||||||
import { canAccessUserEditPage } from "./access";
|
import { UserProfileAvatarForm } from "./_components/_profile-avatar-form";
|
||||||
|
import { UserProfileForm } from "./_components/_profile-form";
|
||||||
|
import { ProfileLanguageChange } from "./_components/_profile-language-change";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
params: {
|
params: {
|
||||||
@@ -34,10 +33,9 @@ export async function generateMetadata({ params }: Props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const t = await getScopedI18n("management.page.user.edit");
|
const t = await getScopedI18n("management.page.user.edit");
|
||||||
const metaTitle = `${t("metaTitle", { username: user?.name })} • Homarr`;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: metaTitle,
|
title: createMetaTitle(t("metaTitle", { username: user?.name })),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +65,8 @@ export default async function EditUserPage({ params }: Props) {
|
|||||||
</Box>
|
</Box>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
||||||
|
<ProfileLanguageChange />
|
||||||
|
|
||||||
<DangerZoneRoot>
|
<DangerZoneRoot>
|
||||||
<DangerZoneItem
|
<DangerZoneItem
|
||||||
label={t("user.action.delete.label")}
|
label={t("user.action.delete.label")}
|
||||||
@@ -1,16 +1,7 @@
|
|||||||
import type { PropsWithChildren } from "react";
|
import type { PropsWithChildren } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import {
|
import { Button, Container, Grid, GridCol, Group, Stack, Text, Title } from "@mantine/core";
|
||||||
Button,
|
|
||||||
Container,
|
|
||||||
Grid,
|
|
||||||
GridCol,
|
|
||||||
Group,
|
|
||||||
Stack,
|
|
||||||
Text,
|
|
||||||
Title,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import { IconSettings, IconShieldLock } from "@tabler/icons-react";
|
import { IconSettings, IconShieldLock } from "@tabler/icons-react";
|
||||||
|
|
||||||
import { api } from "@homarr/api/server";
|
import { api } from "@homarr/api/server";
|
||||||
@@ -26,16 +17,11 @@ interface LayoutProps {
|
|||||||
params: { userId: string };
|
params: { userId: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function Layout({
|
export default async function Layout({ children, params }: PropsWithChildren<LayoutProps>) {
|
||||||
children,
|
|
||||||
params,
|
|
||||||
}: PropsWithChildren<LayoutProps>) {
|
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
const t = await getI18n();
|
const t = await getI18n();
|
||||||
const tUser = await getScopedI18n("management.page.user");
|
const tUser = await getScopedI18n("management.page.user");
|
||||||
const user = await api.user
|
const user = await api.user.getById({ userId: params.userId }).catch(catchTrpcNotFound);
|
||||||
.getById({ userId: params.userId })
|
|
||||||
.catch(catchTrpcNotFound);
|
|
||||||
|
|
||||||
if (!canAccessUserEditPage(session, user.id)) {
|
if (!canAccessUserEditPage(session, user.id)) {
|
||||||
notFound();
|
notFound();
|
||||||
@@ -54,12 +40,7 @@ export default async function Layout({
|
|||||||
</Stack>
|
</Stack>
|
||||||
</Group>
|
</Group>
|
||||||
{session?.user.permissions.includes("admin") && (
|
{session?.user.permissions.includes("admin") && (
|
||||||
<Button
|
<Button component={Link} href="/manage/users" color="gray" variant="light">
|
||||||
component={Link}
|
|
||||||
href="/manage/users"
|
|
||||||
color="gray"
|
|
||||||
variant="light"
|
|
||||||
>
|
|
||||||
{tUser("back")}
|
{tUser("back")}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
@@ -69,7 +50,7 @@ export default async function Layout({
|
|||||||
<Stack>
|
<Stack>
|
||||||
<Stack gap={0}>
|
<Stack gap={0}>
|
||||||
<NavigationLink
|
<NavigationLink
|
||||||
href={`/manage/users/${params.userId}`}
|
href={`/manage/users/${params.userId}/general`}
|
||||||
label={tUser("setting.general.title")}
|
label={tUser("setting.general.title")}
|
||||||
icon={<IconSettings size="1rem" stroke={1.5} />}
|
icon={<IconSettings size="1rem" stroke={1.5} />}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -5,11 +5,8 @@ import { Button, Fieldset, Group, PasswordInput, Stack } from "@mantine/core";
|
|||||||
import type { RouterInputs, RouterOutputs } from "@homarr/api";
|
import type { RouterInputs, RouterOutputs } from "@homarr/api";
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useSession } from "@homarr/auth/client";
|
import { useSession } from "@homarr/auth/client";
|
||||||
import { useForm, zodResolver } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useI18n } from "@homarr/translation/client";
|
import { useI18n } from "@homarr/translation/client";
|
||||||
import { validation } from "@homarr/validation";
|
import { validation } from "@homarr/validation";
|
||||||
|
|
||||||
@@ -37,15 +34,13 @@ export const ChangePasswordForm = ({ user }: ChangePasswordFormProps) => {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const form = useForm<FormType>({
|
const form = useZodForm(validation.user.changePassword, {
|
||||||
initialValues: {
|
initialValues: {
|
||||||
previousPassword: "",
|
/* Require previous password if the current user want's to change his password */
|
||||||
|
previousPassword: session?.user.id === user.id ? "" : "_",
|
||||||
password: "",
|
password: "",
|
||||||
confirmPassword: "",
|
confirmPassword: "",
|
||||||
},
|
},
|
||||||
validate: zodResolver(validation.user.changePassword),
|
|
||||||
validateInputOnBlur: true,
|
|
||||||
validateInputOnChange: true,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = (values: FormType) => {
|
const handleSubmit = (values: FormType) => {
|
||||||
@@ -76,11 +71,7 @@ export const ChangePasswordForm = ({ user }: ChangePasswordFormProps) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<PasswordInput
|
<PasswordInput withAsterisk label={t("user.field.password.label")} {...form.getInputProps("password")} />
|
||||||
withAsterisk
|
|
||||||
label={t("user.field.password.label")}
|
|
||||||
{...form.getInputProps("password")}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<PasswordInput
|
<PasswordInput
|
||||||
withAsterisk
|
withAsterisk
|
||||||
@@ -7,7 +7,7 @@ import { getScopedI18n } from "@homarr/translation/server";
|
|||||||
|
|
||||||
import { catchTrpcNotFound } from "~/errors/trpc-not-found";
|
import { catchTrpcNotFound } from "~/errors/trpc-not-found";
|
||||||
import { canAccessUserEditPage } from "../access";
|
import { canAccessUserEditPage } from "../access";
|
||||||
import { ChangePasswordForm } from "./_change-password-form";
|
import { ChangePasswordForm } from "./_components/_change-password-form";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
params: {
|
params: {
|
||||||
@@ -17,9 +17,7 @@ interface Props {
|
|||||||
|
|
||||||
export default async function UserSecurityPage({ params }: Props) {
|
export default async function UserSecurityPage({ params }: Props) {
|
||||||
const session = await auth();
|
const session = await auth();
|
||||||
const tSecurity = await getScopedI18n(
|
const tSecurity = await getScopedI18n("management.page.user.setting.security");
|
||||||
"management.page.user.setting.security",
|
|
||||||
);
|
|
||||||
const user = await api.user
|
const user = await api.user
|
||||||
.getById({
|
.getById({
|
||||||
userId: params.userId,
|
userId: params.userId,
|
||||||
|
|||||||
@@ -15,25 +15,21 @@ interface UserListComponentProps {
|
|||||||
initialUserList: RouterOutputs["user"]["getAll"];
|
initialUserList: RouterOutputs["user"]["getAll"];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UserListComponent = ({
|
export const UserListComponent = ({ initialUserList }: UserListComponentProps) => {
|
||||||
initialUserList,
|
|
||||||
}: UserListComponentProps) => {
|
|
||||||
const tUserList = useScopedI18n("management.page.user.list");
|
const tUserList = useScopedI18n("management.page.user.list");
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const { data, isLoading } = clientApi.user.getAll.useQuery(undefined, {
|
const { data, isLoading } = clientApi.user.getAll.useQuery(undefined, {
|
||||||
initialData: initialUserList,
|
initialData: initialUserList,
|
||||||
});
|
});
|
||||||
|
|
||||||
const columns = useMemo<
|
const columns = useMemo<MRT_ColumnDef<RouterOutputs["user"]["getAll"][number]>[]>(
|
||||||
MRT_ColumnDef<RouterOutputs["user"]["getAll"][number]>[]
|
|
||||||
>(
|
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
accessorKey: "name",
|
accessorKey: "name",
|
||||||
header: t("user.field.username.label"),
|
header: t("user.field.username.label"),
|
||||||
grow: 100,
|
grow: 100,
|
||||||
Cell: ({ renderedCellValue, row }) => (
|
Cell: ({ renderedCellValue, row }) => (
|
||||||
<Link href={`/manage/users/${row.original.id}`}>
|
<Link href={`/manage/users/${row.original.id}/general`}>
|
||||||
<Group>
|
<Group>
|
||||||
<Avatar size="sm"></Avatar>
|
<Avatar size="sm"></Avatar>
|
||||||
{renderedCellValue}
|
{renderedCellValue}
|
||||||
|
|||||||
@@ -1,23 +1,15 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useMemo, useState } from "react";
|
import { useCallback, useMemo, useState } from "react";
|
||||||
import {
|
import { Avatar, Card, PasswordInput, Stack, Stepper, Text, TextInput, Title } from "@mantine/core";
|
||||||
Avatar,
|
|
||||||
Card,
|
|
||||||
PasswordInput,
|
|
||||||
Stack,
|
|
||||||
Stepper,
|
|
||||||
Text,
|
|
||||||
TextInput,
|
|
||||||
Title,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import { IconUserCheck } from "@tabler/icons-react";
|
import { IconUserCheck } from "@tabler/icons-react";
|
||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useForm, zodResolver } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import { showErrorNotification } from "@homarr/notifications";
|
import { showErrorNotification } from "@homarr/notifications";
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
import { validation, z } from "@homarr/validation";
|
import { validation, z } from "@homarr/validation";
|
||||||
|
import { createCustomErrorParams } from "@homarr/validation/form";
|
||||||
|
|
||||||
import { StepperNavigationComponent } from "./stepper-navigation.component";
|
import { StepperNavigationComponent } from "./stepper-navigation.component";
|
||||||
|
|
||||||
@@ -28,14 +20,10 @@ export const UserCreateStepperComponent = () => {
|
|||||||
const stepperMax = 4;
|
const stepperMax = 4;
|
||||||
const [active, setActive] = useState(0);
|
const [active, setActive] = useState(0);
|
||||||
const nextStep = useCallback(
|
const nextStep = useCallback(
|
||||||
() =>
|
() => setActive((current) => (current < stepperMax ? current + 1 : current)),
|
||||||
setActive((current) => (current < stepperMax ? current + 1 : current)),
|
|
||||||
[setActive],
|
|
||||||
);
|
|
||||||
const prevStep = useCallback(
|
|
||||||
() => setActive((current) => (current > 0 ? current - 1 : current)),
|
|
||||||
[setActive],
|
[setActive],
|
||||||
);
|
);
|
||||||
|
const prevStep = useCallback(() => setActive((current) => (current > 0 ? current - 1 : current)), [setActive]);
|
||||||
const hasNext = active < stepperMax;
|
const hasNext = active < stepperMax;
|
||||||
const hasPrevious = active > 0;
|
const hasPrevious = active > 0;
|
||||||
|
|
||||||
@@ -50,49 +38,40 @@ export const UserCreateStepperComponent = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const generalForm = useForm({
|
const generalForm = useZodForm(
|
||||||
initialValues: {
|
z.object({
|
||||||
username: "",
|
username: z.string().min(1),
|
||||||
email: undefined,
|
email: z.string().email().or(z.string().length(0).optional()),
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
initialValues: {
|
||||||
|
username: "",
|
||||||
|
email: "",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
validate: zodResolver(
|
|
||||||
z.object({
|
|
||||||
username: z.string().min(1),
|
|
||||||
email: z.string().email().or(z.string().length(0).optional()),
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
validateInputOnBlur: true,
|
|
||||||
validateInputOnChange: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const securityForm = useForm({
|
|
||||||
initialValues: {
|
|
||||||
password: "",
|
|
||||||
confirmPassword: "",
|
|
||||||
},
|
|
||||||
validate: zodResolver(
|
|
||||||
z
|
|
||||||
.object({
|
|
||||||
password: validation.user.password,
|
|
||||||
confirmPassword: z.string(),
|
|
||||||
})
|
|
||||||
.refine((data) => data.password === data.confirmPassword, {
|
|
||||||
path: ["confirmPassword"],
|
|
||||||
message: "Passwords do not match",
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
validateInputOnBlur: true,
|
|
||||||
validateInputOnChange: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const allForms = useMemo(
|
|
||||||
() => [generalForm, securityForm],
|
|
||||||
[generalForm, securityForm],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const isCurrentFormValid = allForms[active]
|
const securityForm = useZodForm(
|
||||||
? (allForms[active]!.isValid satisfies () => boolean)
|
z
|
||||||
: () => true;
|
.object({
|
||||||
|
password: validation.user.password,
|
||||||
|
confirmPassword: z.string(),
|
||||||
|
})
|
||||||
|
.refine((data) => data.password === data.confirmPassword, {
|
||||||
|
path: ["confirmPassword"],
|
||||||
|
params: createCustomErrorParams("passwordsDoNotMatch"),
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
initialValues: {
|
||||||
|
password: "",
|
||||||
|
confirmPassword: "",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const allForms = useMemo(() => [generalForm, securityForm], [generalForm, securityForm]);
|
||||||
|
|
||||||
|
const isCurrentFormValid = allForms[active] ? (allForms[active]!.isValid satisfies () => boolean) : () => true;
|
||||||
const canNavigateToNextStep = isCurrentFormValid();
|
const canNavigateToNextStep = isCurrentFormValid();
|
||||||
|
|
||||||
const controlledGoToNextStep = useCallback(async () => {
|
const controlledGoToNextStep = useCallback(async () => {
|
||||||
@@ -117,12 +96,7 @@ export const UserCreateStepperComponent = () => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Title mb="md">{t("title")}</Title>
|
<Title mb="md">{t("title")}</Title>
|
||||||
<Stepper
|
<Stepper active={active} onStepClick={setActive} allowNextStepsSelect={false} mb="md">
|
||||||
active={active}
|
|
||||||
onStepClick={setActive}
|
|
||||||
allowNextStepsSelect={false}
|
|
||||||
mb="md"
|
|
||||||
>
|
|
||||||
<Stepper.Step
|
<Stepper.Step
|
||||||
label={t("step.personalInformation.label")}
|
label={t("step.personalInformation.label")}
|
||||||
allowStepSelect={false}
|
allowStepSelect={false}
|
||||||
@@ -139,20 +113,12 @@ export const UserCreateStepperComponent = () => {
|
|||||||
{...generalForm.getInputProps("username")}
|
{...generalForm.getInputProps("username")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextInput
|
<TextInput label={tUserField("email.label")} variant="filled" {...generalForm.getInputProps("email")} />
|
||||||
label={tUserField("email.label")}
|
|
||||||
variant="filled"
|
|
||||||
{...generalForm.getInputProps("email")}
|
|
||||||
/>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</Card>
|
</Card>
|
||||||
</form>
|
</form>
|
||||||
</Stepper.Step>
|
</Stepper.Step>
|
||||||
<Stepper.Step
|
<Stepper.Step label={t("step.security.label")} allowStepSelect={false} allowStepClick={false}>
|
||||||
label={t("step.security.label")}
|
|
||||||
allowStepSelect={false}
|
|
||||||
allowStepClick={false}
|
|
||||||
>
|
|
||||||
<form>
|
<form>
|
||||||
<Card p="xl">
|
<Card p="xl">
|
||||||
<Stack gap="md">
|
<Stack gap="md">
|
||||||
@@ -180,11 +146,7 @@ export const UserCreateStepperComponent = () => {
|
|||||||
>
|
>
|
||||||
3
|
3
|
||||||
</Stepper.Step>
|
</Stepper.Step>
|
||||||
<Stepper.Step
|
<Stepper.Step label={t("step.review.label")} allowStepSelect={false} allowStepClick={false}>
|
||||||
label={t("step.review.label")}
|
|
||||||
allowStepSelect={false}
|
|
||||||
allowStepClick={false}
|
|
||||||
>
|
|
||||||
<Card p="xl">
|
<Card p="xl">
|
||||||
<Stack maw={300} align="center" mx="auto">
|
<Stack maw={300} align="center" mx="auto">
|
||||||
<Avatar size="xl">{generalForm.values.username}</Avatar>
|
<Avatar size="xl">{generalForm.values.username}</Avatar>
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Button, Card, Group } from "@mantine/core";
|
import { Button, Card, Group } from "@mantine/core";
|
||||||
import {
|
import { IconArrowBackUp, IconArrowLeft, IconArrowRight, IconRotate } from "@tabler/icons-react";
|
||||||
IconArrowBackUp,
|
|
||||||
IconArrowLeft,
|
|
||||||
IconArrowRight,
|
|
||||||
IconRotate,
|
|
||||||
} from "@tabler/icons-react";
|
|
||||||
|
|
||||||
import { useI18n } from "@homarr/translation/client";
|
import { useI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
@@ -51,18 +46,10 @@ export const StepperNavigationComponent = ({
|
|||||||
</Group>
|
</Group>
|
||||||
) : (
|
) : (
|
||||||
<Group justify="end" wrap="nowrap">
|
<Group justify="end" wrap="nowrap">
|
||||||
<Button
|
<Button variant="light" leftSection={<IconRotate size="1rem" />} onClick={reset}>
|
||||||
variant="light"
|
|
||||||
leftSection={<IconRotate size="1rem" />}
|
|
||||||
onClick={reset}
|
|
||||||
>
|
|
||||||
{t("management.page.user.create.action.createAnother")}
|
{t("management.page.user.create.action.createAnother")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button leftSection={<IconArrowBackUp size="1rem" />} component={Link} href="/manage/users">
|
||||||
leftSection={<IconArrowBackUp size="1rem" />}
|
|
||||||
component={Link}
|
|
||||||
href="/manage/users"
|
|
||||||
>
|
|
||||||
{t("management.page.user.create.action.back")}
|
{t("management.page.user.create.action.back")}
|
||||||
</Button>
|
</Button>
|
||||||
</Group>
|
</Group>
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { getScopedI18n } from "@homarr/translation/server";
|
import { getScopedI18n } from "@homarr/translation/server";
|
||||||
|
|
||||||
|
import { createMetaTitle } from "~/metadata";
|
||||||
import { UserCreateStepperComponent } from "./_components/create-user-stepper";
|
import { UserCreateStepperComponent } from "./_components/create-user-stepper";
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const t = await getScopedI18n("management.page.user.create");
|
const t = await getScopedI18n("management.page.user.create");
|
||||||
const metaTitle = `${t("metaTitle")} • Homarr`;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: metaTitle,
|
title: createMetaTitle(t("metaTitle")),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import { Button } from "@mantine/core";
|
|||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useConfirmModal } from "@homarr/modals";
|
import { useConfirmModal } from "@homarr/modals";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
import { revalidatePathActionAsync } from "~/app/revalidatePathAction";
|
import { revalidatePathActionAsync } from "~/app/revalidatePathAction";
|
||||||
@@ -63,15 +60,7 @@ export const DeleteGroup = ({ group }: DeleteGroupProps) => {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}, [
|
}, [tDelete, tRoot, openConfirmModal, group.id, group.name, mutateAsync, router]);
|
||||||
tDelete,
|
|
||||||
tRoot,
|
|
||||||
openConfirmModal,
|
|
||||||
group.id,
|
|
||||||
group.name,
|
|
||||||
mutateAsync,
|
|
||||||
router,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button variant="subtle" color="red" onClick={handleDeletion}>
|
<Button variant="subtle" color="red" onClick={handleDeletion}>
|
||||||
|
|||||||
@@ -14,13 +14,5 @@ interface NavigationLinkProps {
|
|||||||
export const NavigationLink = ({ href, icon, label }: NavigationLinkProps) => {
|
export const NavigationLink = ({ href, icon, label }: NavigationLinkProps) => {
|
||||||
const pathName = usePathname();
|
const pathName = usePathname();
|
||||||
|
|
||||||
return (
|
return <NavLink component={Link} href={href} active={pathName === href} label={label} leftSection={icon} />;
|
||||||
<NavLink
|
|
||||||
component={Link}
|
|
||||||
href={href}
|
|
||||||
active={pathName === href}
|
|
||||||
label={label}
|
|
||||||
leftSection={icon}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,12 +4,10 @@ import { useCallback } from "react";
|
|||||||
import { Button, Group, Stack, TextInput } from "@mantine/core";
|
import { Button, Group, Stack, TextInput } from "@mantine/core";
|
||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useForm } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useI18n } from "@homarr/translation/client";
|
import { useI18n } from "@homarr/translation/client";
|
||||||
|
import { validation } from "@homarr/validation";
|
||||||
|
|
||||||
import { revalidatePathActionAsync } from "~/app/revalidatePathAction";
|
import { revalidatePathActionAsync } from "~/app/revalidatePathAction";
|
||||||
|
|
||||||
@@ -23,7 +21,7 @@ interface RenameGroupFormProps {
|
|||||||
export const RenameGroupForm = ({ group }: RenameGroupFormProps) => {
|
export const RenameGroupForm = ({ group }: RenameGroupFormProps) => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const { mutate, isPending } = clientApi.group.updateGroup.useMutation();
|
const { mutate, isPending } = clientApi.group.updateGroup.useMutation();
|
||||||
const form = useForm<FormType>({
|
const form = useZodForm(validation.group.update.pick({ name: true }), {
|
||||||
initialValues: {
|
initialValues: {
|
||||||
name: group.name,
|
name: group.name,
|
||||||
},
|
},
|
||||||
@@ -63,10 +61,7 @@ export const RenameGroupForm = ({ group }: RenameGroupFormProps) => {
|
|||||||
return (
|
return (
|
||||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||||
<Stack>
|
<Stack>
|
||||||
<TextInput
|
<TextInput label={t("group.field.name")} {...form.getInputProps("name")} />
|
||||||
label={t("group.field.name")}
|
|
||||||
{...form.getInputProps("name")}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Group justify="end">
|
<Group justify="end">
|
||||||
<Button type="submit" color="teal" loading={isPending}>
|
<Button type="submit" color="teal" loading={isPending}>
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ import { Button } from "@mantine/core";
|
|||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useConfirmModal, useModalAction } from "@homarr/modals";
|
import { useConfirmModal, useModalAction } from "@homarr/modals";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
import { UserSelectModal } from "~/app/[locale]/boards/[name]/settings/_access/user-select-modal";
|
import { UserSelectModal } from "~/app/[locale]/boards/[name]/settings/_access/user-select-modal";
|
||||||
@@ -21,9 +18,7 @@ interface TransferGroupOwnershipProps {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TransferGroupOwnership = ({
|
export const TransferGroupOwnership = ({ group }: TransferGroupOwnershipProps) => {
|
||||||
group,
|
|
||||||
}: TransferGroupOwnershipProps) => {
|
|
||||||
const tTransfer = useScopedI18n("group.action.transfer");
|
const tTransfer = useScopedI18n("group.action.transfer");
|
||||||
const tRoot = useI18n();
|
const tRoot = useI18n();
|
||||||
const [innerOwnerId, setInnerOwnerId] = useState(group.ownerId);
|
const [innerOwnerId, setInnerOwnerId] = useState(group.ownerId);
|
||||||
@@ -77,16 +72,7 @@ export const TransferGroupOwnership = ({
|
|||||||
title: tTransfer("label"),
|
title: tTransfer("label"),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}, [
|
}, [group.id, group.name, innerOwnerId, mutateAsync, openConfirmModal, openModal, tRoot, tTransfer]);
|
||||||
group.id,
|
|
||||||
group.name,
|
|
||||||
innerOwnerId,
|
|
||||||
mutateAsync,
|
|
||||||
openConfirmModal,
|
|
||||||
openModal,
|
|
||||||
tRoot,
|
|
||||||
tTransfer,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button variant="subtle" color="red" onClick={handleTransfer}>
|
<Button variant="subtle" color="red" onClick={handleTransfer}>
|
||||||
|
|||||||
@@ -1,15 +1,6 @@
|
|||||||
import type { PropsWithChildren } from "react";
|
import type { PropsWithChildren } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import {
|
import { Button, Container, Grid, GridCol, Group, Stack, Text, Title } from "@mantine/core";
|
||||||
Button,
|
|
||||||
Container,
|
|
||||||
Grid,
|
|
||||||
GridCol,
|
|
||||||
Group,
|
|
||||||
Stack,
|
|
||||||
Text,
|
|
||||||
Title,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import { IconLock, IconSettings, IconUsersGroup } from "@tabler/icons-react";
|
import { IconLock, IconSettings, IconUsersGroup } from "@tabler/icons-react";
|
||||||
|
|
||||||
import { api } from "@homarr/api/server";
|
import { api } from "@homarr/api/server";
|
||||||
@@ -21,10 +12,7 @@ interface LayoutProps {
|
|||||||
params: { id: string };
|
params: { id: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function Layout({
|
export default async function Layout({ children, params }: PropsWithChildren<LayoutProps>) {
|
||||||
children,
|
|
||||||
params,
|
|
||||||
}: PropsWithChildren<LayoutProps>) {
|
|
||||||
const t = await getI18n();
|
const t = await getI18n();
|
||||||
const tGroup = await getScopedI18n("management.page.group");
|
const tGroup = await getScopedI18n("management.page.group");
|
||||||
const group = await api.group.getById({ id: params.id });
|
const group = await api.group.getById({ id: params.id });
|
||||||
@@ -38,12 +26,7 @@ export default async function Layout({
|
|||||||
<Title order={3}>{group.name}</Title>
|
<Title order={3}>{group.name}</Title>
|
||||||
<Text c="gray.5">{t("group.name")}</Text>
|
<Text c="gray.5">{t("group.name")}</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Button
|
<Button component={Link} href="/manage/users/groups" color="gray" variant="light">
|
||||||
component={Link}
|
|
||||||
href="/manage/users/groups"
|
|
||||||
color="gray"
|
|
||||||
variant="light"
|
|
||||||
>
|
|
||||||
{tGroup("back")}
|
{tGroup("back")}
|
||||||
</Button>
|
</Button>
|
||||||
</Group>
|
</Group>
|
||||||
|
|||||||
@@ -15,10 +15,7 @@ interface AddGroupMemberProps {
|
|||||||
presentUserIds: string[];
|
presentUserIds: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AddGroupMember = ({
|
export const AddGroupMember = ({ groupId, presentUserIds }: AddGroupMemberProps) => {
|
||||||
groupId,
|
|
||||||
presentUserIds,
|
|
||||||
}: AddGroupMemberProps) => {
|
|
||||||
const tMembersAdd = useScopedI18n("group.action.addMember");
|
const tMembersAdd = useScopedI18n("group.action.addMember");
|
||||||
const { mutateAsync } = clientApi.group.addMember.useMutation();
|
const { mutateAsync } = clientApi.group.addMember.useMutation();
|
||||||
const { openModal } = useModalAction(UserSelectModal);
|
const { openModal } = useModalAction(UserSelectModal);
|
||||||
@@ -32,9 +29,7 @@ export const AddGroupMember = ({
|
|||||||
userId: id,
|
userId: id,
|
||||||
groupId,
|
groupId,
|
||||||
});
|
});
|
||||||
await revalidatePathActionAsync(
|
await revalidatePathActionAsync(`/manage/users/groups/${groupId}}/members`);
|
||||||
`/manage/users/groups/${groupId}}/members`,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
presentUserIds,
|
presentUserIds,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -14,10 +14,7 @@ interface RemoveGroupMemberProps {
|
|||||||
user: { id: string; name: string | null };
|
user: { id: string; name: string | null };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const RemoveGroupMember = ({
|
export const RemoveGroupMember = ({ groupId, user }: RemoveGroupMemberProps) => {
|
||||||
groupId,
|
|
||||||
user,
|
|
||||||
}: RemoveGroupMemberProps) => {
|
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const tRemoveMember = useScopedI18n("group.action.removeMember");
|
const tRemoveMember = useScopedI18n("group.action.removeMember");
|
||||||
const { mutateAsync } = clientApi.group.removeMember.useMutation();
|
const { mutateAsync } = clientApi.group.removeMember.useMutation();
|
||||||
@@ -35,27 +32,13 @@ export const RemoveGroupMember = ({
|
|||||||
groupId,
|
groupId,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
await revalidatePathActionAsync(
|
await revalidatePathActionAsync(`/manage/users/groups/${groupId}/members`);
|
||||||
`/manage/users/groups/${groupId}/members`,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}, [
|
}, [openConfirmModal, mutateAsync, groupId, user.id, user.name, tRemoveMember]);
|
||||||
openConfirmModal,
|
|
||||||
mutateAsync,
|
|
||||||
groupId,
|
|
||||||
user.id,
|
|
||||||
user.name,
|
|
||||||
tRemoveMember,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button variant="subtle" color="red.9" size="compact-sm" onClick={handleRemove}>
|
||||||
variant="subtle"
|
|
||||||
color="red.9"
|
|
||||||
size="compact-sm"
|
|
||||||
onClick={handleRemove}
|
|
||||||
>
|
|
||||||
{t("common.action.remove")}
|
{t("common.action.remove")}
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,16 +1,5 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import {
|
import { Anchor, Center, Group, Stack, Table, TableTbody, TableTd, TableTr, Text, Title } from "@mantine/core";
|
||||||
Anchor,
|
|
||||||
Center,
|
|
||||||
Group,
|
|
||||||
Stack,
|
|
||||||
Table,
|
|
||||||
TableTbody,
|
|
||||||
TableTd,
|
|
||||||
TableTr,
|
|
||||||
Text,
|
|
||||||
Title,
|
|
||||||
} from "@mantine/core";
|
|
||||||
|
|
||||||
import type { RouterOutputs } from "@homarr/api";
|
import type { RouterOutputs } from "@homarr/api";
|
||||||
import { api } from "@homarr/api/server";
|
import { api } from "@homarr/api/server";
|
||||||
@@ -29,20 +18,13 @@ interface GroupsDetailPageProps {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function GroupsDetailPage({
|
export default async function GroupsDetailPage({ params, searchParams }: GroupsDetailPageProps) {
|
||||||
params,
|
|
||||||
searchParams,
|
|
||||||
}: GroupsDetailPageProps) {
|
|
||||||
const t = await getI18n();
|
const t = await getI18n();
|
||||||
const tMembers = await getScopedI18n("management.page.group.setting.members");
|
const tMembers = await getScopedI18n("management.page.group.setting.members");
|
||||||
const group = await api.group.getById({ id: params.id });
|
const group = await api.group.getById({ id: params.id });
|
||||||
|
|
||||||
const filteredMembers = searchParams.search
|
const filteredMembers = searchParams.search
|
||||||
? group.members.filter((member) =>
|
? group.members.filter((member) => member.name?.toLowerCase().includes(searchParams.search!.trim().toLowerCase()))
|
||||||
member.name
|
|
||||||
?.toLowerCase()
|
|
||||||
.includes(searchParams.search!.trim().toLowerCase()),
|
|
||||||
)
|
|
||||||
: group.members;
|
: group.members;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -56,10 +38,7 @@ export default async function GroupsDetailPage({
|
|||||||
})}
|
})}
|
||||||
defaultValue={searchParams.search}
|
defaultValue={searchParams.search}
|
||||||
/>
|
/>
|
||||||
<AddGroupMember
|
<AddGroupMember groupId={group.id} presentUserIds={group.members.map((member) => member.id)} />
|
||||||
groupId={group.id}
|
|
||||||
presentUserIds={group.members.map((member) => member.id)}
|
|
||||||
/>
|
|
||||||
</Group>
|
</Group>
|
||||||
{filteredMembers.length === 0 && (
|
{filteredMembers.length === 0 && (
|
||||||
<Center py="sm">
|
<Center py="sm">
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ import { Stack, Title } from "@mantine/core";
|
|||||||
import { api } from "@homarr/api/server";
|
import { api } from "@homarr/api/server";
|
||||||
import { getScopedI18n } from "@homarr/translation/server";
|
import { getScopedI18n } from "@homarr/translation/server";
|
||||||
|
|
||||||
import {
|
import { DangerZoneItem, DangerZoneRoot } from "~/components/manage/danger-zone";
|
||||||
DangerZoneItem,
|
|
||||||
DangerZoneRoot,
|
|
||||||
} from "~/components/manage/danger-zone";
|
|
||||||
import { DeleteGroup } from "./_delete-group";
|
import { DeleteGroup } from "./_delete-group";
|
||||||
import { RenameGroupForm } from "./_rename-group-form";
|
import { RenameGroupForm } from "./_rename-group-form";
|
||||||
import { TransferGroupOwnership } from "./_transfer-group-ownership";
|
import { TransferGroupOwnership } from "./_transfer-group-ownership";
|
||||||
@@ -17,9 +14,7 @@ interface GroupsDetailPageProps {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function GroupsDetailPage({
|
export default async function GroupsDetailPage({ params }: GroupsDetailPageProps) {
|
||||||
params,
|
|
||||||
}: GroupsDetailPageProps) {
|
|
||||||
const group = await api.group.getById({ id: params.id });
|
const group = await api.group.getById({ id: params.id });
|
||||||
const tGeneral = await getScopedI18n("management.page.group.setting.general");
|
const tGeneral = await getScopedI18n("management.page.group.setting.general");
|
||||||
const tGroupAction = await getScopedI18n("group.action");
|
const tGroupAction = await getScopedI18n("group.action");
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ import { objectEntries } from "@homarr/common";
|
|||||||
import type { GroupPermissionKey } from "@homarr/definitions";
|
import type { GroupPermissionKey } from "@homarr/definitions";
|
||||||
import { groupPermissionKeys } from "@homarr/definitions";
|
import { groupPermissionKeys } from "@homarr/definitions";
|
||||||
import { createFormContext } from "@homarr/form";
|
import { createFormContext } from "@homarr/form";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
const [FormProvider, useFormContext, useForm] = createFormContext<FormType>();
|
const [FormProvider, useFormContext, useForm] = createFormContext<FormType>();
|
||||||
@@ -21,10 +18,7 @@ interface PermissionFormProps {
|
|||||||
initialPermissions: GroupPermissionKey[];
|
initialPermissions: GroupPermissionKey[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PermissionForm = ({
|
export const PermissionForm = ({ children, initialPermissions }: PropsWithChildren<PermissionFormProps>) => {
|
||||||
children,
|
|
||||||
initialPermissions,
|
|
||||||
}: PropsWithChildren<PermissionFormProps>) => {
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
initialValues: groupPermissionKeys.reduce((acc, key) => {
|
initialValues: groupPermissionKeys.reduce((acc, key) => {
|
||||||
acc[key] = initialPermissions.includes(key);
|
acc[key] = initialPermissions.includes(key);
|
||||||
@@ -73,9 +67,7 @@ interface SaveAffixProps {
|
|||||||
export const SaveAffix = ({ groupId }: SaveAffixProps) => {
|
export const SaveAffix = ({ groupId }: SaveAffixProps) => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const tForm = useScopedI18n("management.page.group.setting.permissions.form");
|
const tForm = useScopedI18n("management.page.group.setting.permissions.form");
|
||||||
const tNotification = useScopedI18n(
|
const tNotification = useScopedI18n("group.action.changePermissions.notification");
|
||||||
"group.action.changePermissions.notification",
|
|
||||||
);
|
|
||||||
const form = useFormContext();
|
const form = useFormContext();
|
||||||
const { mutate, isPending } = clientApi.group.savePermissions.useMutation();
|
const { mutate, isPending } = clientApi.group.savePermissions.useMutation();
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import {
|
import { Card, CardSection, Divider, Group, Stack, Text, Title } from "@mantine/core";
|
||||||
Card,
|
|
||||||
CardSection,
|
|
||||||
Divider,
|
|
||||||
Group,
|
|
||||||
Stack,
|
|
||||||
Text,
|
|
||||||
Title,
|
|
||||||
} from "@mantine/core";
|
|
||||||
|
|
||||||
import { api } from "@homarr/api/server";
|
import { api } from "@homarr/api/server";
|
||||||
import { objectKeys } from "@homarr/common";
|
import { objectKeys } from "@homarr/common";
|
||||||
@@ -15,11 +7,7 @@ import type { GroupPermissionKey } from "@homarr/definitions";
|
|||||||
import { groupPermissions } from "@homarr/definitions";
|
import { groupPermissions } from "@homarr/definitions";
|
||||||
import { getI18n, getScopedI18n } from "@homarr/translation/server";
|
import { getI18n, getScopedI18n } from "@homarr/translation/server";
|
||||||
|
|
||||||
import {
|
import { PermissionForm, PermissionSwitch, SaveAffix } from "./_group-permission-form";
|
||||||
PermissionForm,
|
|
||||||
PermissionSwitch,
|
|
||||||
SaveAffix,
|
|
||||||
} from "./_group-permission-form";
|
|
||||||
|
|
||||||
interface GroupPermissionsPageProps {
|
interface GroupPermissionsPageProps {
|
||||||
params: {
|
params: {
|
||||||
@@ -27,9 +15,7 @@ interface GroupPermissionsPageProps {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function GroupPermissionsPage({
|
export default async function GroupPermissionsPage({ params }: GroupPermissionsPageProps) {
|
||||||
params,
|
|
||||||
}: GroupPermissionsPageProps) {
|
|
||||||
const group = await api.group.getById({ id: params.id });
|
const group = await api.group.getById({ id: params.id });
|
||||||
const tPermissions = await getScopedI18n("group.permission");
|
const tPermissions = await getScopedI18n("group.permission");
|
||||||
const t = await getI18n();
|
const t = await getI18n();
|
||||||
@@ -99,10 +85,7 @@ const PermissionCard = async ({ group, isDanger }: PermissionCardProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createGroupPermissionKey = (
|
const createGroupPermissionKey = (group: keyof typeof groupPermissions, permission: string): GroupPermissionKey => {
|
||||||
group: keyof typeof groupPermissions,
|
|
||||||
permission: string,
|
|
||||||
): GroupPermissionKey => {
|
|
||||||
if (typeof groupPermissions[group] === "boolean") {
|
if (typeof groupPermissions[group] === "boolean") {
|
||||||
return group as GroupPermissionKey;
|
return group as GroupPermissionKey;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,11 @@ import { useCallback } from "react";
|
|||||||
import { Button, Group, Stack, TextInput } from "@mantine/core";
|
import { Button, Group, Stack, TextInput } from "@mantine/core";
|
||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useForm } from "@homarr/form";
|
import { useZodForm } from "@homarr/form";
|
||||||
import { createModal, useModalAction } from "@homarr/modals";
|
import { createModal, useModalAction } from "@homarr/modals";
|
||||||
import {
|
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||||
showErrorNotification,
|
|
||||||
showSuccessNotification,
|
|
||||||
} from "@homarr/notifications";
|
|
||||||
import { useI18n } from "@homarr/translation/client";
|
import { useI18n } from "@homarr/translation/client";
|
||||||
|
import { validation } from "@homarr/validation";
|
||||||
|
|
||||||
import { revalidatePathActionAsync } from "~/app/revalidatePathAction";
|
import { revalidatePathActionAsync } from "~/app/revalidatePathAction";
|
||||||
|
|
||||||
@@ -32,7 +30,7 @@ export const AddGroup = () => {
|
|||||||
const AddGroupModal = createModal<void>(({ actions }) => {
|
const AddGroupModal = createModal<void>(({ actions }) => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const { mutate, isPending } = clientApi.group.createGroup.useMutation();
|
const { mutate, isPending } = clientApi.group.createGroup.useMutation();
|
||||||
const form = useForm({
|
const form = useZodForm(validation.group.create, {
|
||||||
initialValues: {
|
initialValues: {
|
||||||
name: "",
|
name: "",
|
||||||
},
|
},
|
||||||
@@ -60,11 +58,7 @@ const AddGroupModal = createModal<void>(({ actions }) => {
|
|||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<Stack>
|
<Stack>
|
||||||
<TextInput
|
<TextInput label={t("group.field.name")} data-autofocus {...form.getInputProps("name")} />
|
||||||
label={t("group.field.name")}
|
|
||||||
data-autofocus
|
|
||||||
{...form.getInputProps("name")}
|
|
||||||
/>
|
|
||||||
<Group justify="right">
|
<Group justify="right">
|
||||||
<Button onClick={actions.closeModal} variant="subtle" color="gray">
|
<Button onClick={actions.closeModal} variant="subtle" color="gray">
|
||||||
{t("common.action.cancel")}
|
{t("common.action.cancel")}
|
||||||
|
|||||||
@@ -27,25 +27,18 @@ const searchParamsSchema = z.object({
|
|||||||
page: z.string().regex(/\d+/).transform(Number).catch(1),
|
page: z.string().regex(/\d+/).transform(Number).catch(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
type SearchParamsSchemaInputFromSchema<
|
type SearchParamsSchemaInputFromSchema<TSchema extends Record<string, unknown>> = Partial<{
|
||||||
TSchema extends Record<string, unknown>,
|
[K in keyof TSchema]: Exclude<TSchema[K], undefined> extends unknown[] ? string[] : string;
|
||||||
> = Partial<{
|
|
||||||
[K in keyof TSchema]: Exclude<TSchema[K], undefined> extends unknown[]
|
|
||||||
? string[]
|
|
||||||
: string;
|
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
interface GroupsListPageProps {
|
interface GroupsListPageProps {
|
||||||
searchParams: SearchParamsSchemaInputFromSchema<
|
searchParams: SearchParamsSchemaInputFromSchema<z.infer<typeof searchParamsSchema>>;
|
||||||
z.infer<typeof searchParamsSchema>
|
|
||||||
>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function GroupsListPage(props: GroupsListPageProps) {
|
export default async function GroupsListPage(props: GroupsListPageProps) {
|
||||||
const t = await getI18n();
|
const t = await getI18n();
|
||||||
const searchParams = searchParamsSchema.parse(props.searchParams);
|
const searchParams = searchParamsSchema.parse(props.searchParams);
|
||||||
const { items: groups, totalCount } =
|
const { items: groups, totalCount } = await api.group.getPaginated(searchParams);
|
||||||
await api.group.getPaginated(searchParams);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container size="xl">
|
<Container size="xl">
|
||||||
@@ -76,9 +69,7 @@ export default async function GroupsListPage(props: GroupsListPageProps) {
|
|||||||
</Table>
|
</Table>
|
||||||
|
|
||||||
<Group justify="end">
|
<Group justify="end">
|
||||||
<TablePagination
|
<TablePagination total={Math.ceil(totalCount / searchParams.pageSize)} />
|
||||||
total={Math.ceil(totalCount / searchParams.pageSize)}
|
|
||||||
/>
|
|
||||||
</Group>
|
</Group>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Container>
|
</Container>
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ import type { RouterOutputs } from "@homarr/api";
|
|||||||
import { createModal } from "@homarr/modals";
|
import { createModal } from "@homarr/modals";
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
export const InviteCopyModal = createModal<
|
export const InviteCopyModal = createModal<RouterOutputs["invite"]["createInvite"]>(({ actions, innerProps }) => {
|
||||||
RouterOutputs["invite"]["createInvite"]
|
|
||||||
>(({ actions, innerProps }) => {
|
|
||||||
const t = useScopedI18n("management.page.user.invite");
|
const t = useScopedI18n("management.page.user.invite");
|
||||||
const inviteUrl = useInviteUrl(innerProps);
|
const inviteUrl = useInviteUrl(innerProps);
|
||||||
|
|
||||||
@@ -50,13 +48,9 @@ export const InviteCopyModal = createModal<
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const createPath = ({ id, token }: RouterOutputs["invite"]["createInvite"]) =>
|
const createPath = ({ id, token }: RouterOutputs["invite"]["createInvite"]) => `/auth/invite/${id}?token=${token}`;
|
||||||
`/auth/invite/${id}?token=${token}`;
|
|
||||||
|
|
||||||
const useInviteUrl = ({
|
const useInviteUrl = ({ id, token }: RouterOutputs["invite"]["createInvite"]) => {
|
||||||
id,
|
|
||||||
token,
|
|
||||||
}: RouterOutputs["invite"]["createInvite"]) => {
|
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
|
||||||
return window.location.href.replace(pathname, createPath({ id, token }));
|
return window.location.href.replace(pathname, createPath({ id, token }));
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ interface InviteListComponentProps {
|
|||||||
initialInvites: RouterOutputs["invite"]["getAll"];
|
initialInvites: RouterOutputs["invite"]["getAll"];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const InviteListComponent = ({
|
export const InviteListComponent = ({ initialInvites }: InviteListComponentProps) => {
|
||||||
initialInvites,
|
|
||||||
}: InviteListComponentProps) => {
|
|
||||||
const t = useScopedI18n("management.page.user.invite");
|
const t = useScopedI18n("management.page.user.invite");
|
||||||
const { data, isLoading } = clientApi.invite.getAll.useQuery(undefined, {
|
const { data, isLoading } = clientApi.invite.getAll.useQuery(undefined, {
|
||||||
initialData: initialInvites,
|
initialData: initialInvites,
|
||||||
@@ -32,9 +30,7 @@ export const InviteListComponent = ({
|
|||||||
refetchOnReconnect: false,
|
refetchOnReconnect: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const columns = useMemo<
|
const columns = useMemo<MRT_ColumnDef<RouterOutputs["invite"]["getAll"][number]>[]>(
|
||||||
MRT_ColumnDef<RouterOutputs["invite"]["getAll"][number]>[]
|
|
||||||
>(
|
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
accessorKey: "id",
|
accessorKey: "id",
|
||||||
@@ -100,11 +96,7 @@ const RenderTopToolbarCustomActions = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const RenderRowActions = ({
|
const RenderRowActions = ({ row }: { row: MRT_Row<RouterOutputs["invite"]["getAll"][number]> }) => {
|
||||||
row,
|
|
||||||
}: {
|
|
||||||
row: MRT_Row<RouterOutputs["invite"]["getAll"][number]>;
|
|
||||||
}) => {
|
|
||||||
const t = useScopedI18n("management.page.user.invite");
|
const t = useScopedI18n("management.page.user.invite");
|
||||||
const { mutate, isPending } = clientApi.invite.deleteInvite.useMutation();
|
const { mutate, isPending } = clientApi.invite.deleteInvite.useMutation();
|
||||||
const utils = clientApi.useUtils();
|
const utils = clientApi.useUtils();
|
||||||
@@ -121,12 +113,7 @@ const RenderRowActions = ({
|
|||||||
}, [openConfirmModal, row.original.id, mutate, utils, t]);
|
}, [openConfirmModal, row.original.id, mutate, utils, t]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ActionIcon
|
<ActionIcon variant="subtle" color="red" onClick={handleDelete} loading={isPending}>
|
||||||
variant="subtle"
|
|
||||||
color="red"
|
|
||||||
onClick={handleDelete}
|
|
||||||
loading={isPending}
|
|
||||||
>
|
|
||||||
<IconTrash color="red" size={20} stroke={1.5} />
|
<IconTrash color="red" size={20} stroke={1.5} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { api } from "@homarr/api/server";
|
import { api } from "@homarr/api/server";
|
||||||
import { getScopedI18n } from "@homarr/translation/server";
|
import { getScopedI18n } from "@homarr/translation/server";
|
||||||
|
|
||||||
|
import { createMetaTitle } from "~/metadata";
|
||||||
import { UserListComponent } from "./_components/user-list.component";
|
import { UserListComponent } from "./_components/user-list.component";
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
const t = await getScopedI18n("management.page.user.list");
|
const t = await getScopedI18n("management.page.user.list");
|
||||||
const metaTitle = `${t("metaTitle")} • Homarr`;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: metaTitle,
|
title: createMetaTitle(t("metaTitle")),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,18 +2,13 @@
|
|||||||
|
|
||||||
import { useCallback, useMemo, useState } from "react";
|
import { useCallback, useMemo, useState } from "react";
|
||||||
import { ActionIcon, Affix, Card } from "@mantine/core";
|
import { ActionIcon, Affix, Card } from "@mantine/core";
|
||||||
import {
|
import { IconDimensions, IconPencil, IconToggleLeft, IconToggleRight } from "@tabler/icons-react";
|
||||||
IconDimensions,
|
|
||||||
IconPencil,
|
|
||||||
IconToggleLeft,
|
|
||||||
IconToggleRight,
|
|
||||||
} from "@tabler/icons-react";
|
|
||||||
|
|
||||||
import type { IntegrationKind, WidgetKind } from "@homarr/definitions";
|
import type { IntegrationKind, WidgetKind } from "@homarr/definitions";
|
||||||
import { useModalAction } from "@homarr/modals";
|
import { useModalAction } from "@homarr/modals";
|
||||||
import { showSuccessNotification } from "@homarr/notifications";
|
import { showSuccessNotification } from "@homarr/notifications";
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
import type { BoardItemIntegration } from "@homarr/validation";
|
import type { BoardItemAdvancedOptions, BoardItemIntegration } from "@homarr/validation";
|
||||||
import {
|
import {
|
||||||
loadWidgetDynamic,
|
loadWidgetDynamic,
|
||||||
reduceWidgetOptionsWithDefaultValues,
|
reduceWidgetOptionsWithDefaultValues,
|
||||||
@@ -34,19 +29,11 @@ interface WidgetPreviewPageContentProps {
|
|||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WidgetPreviewPageContent = ({
|
export const WidgetPreviewPageContent = ({ kind, integrationData }: WidgetPreviewPageContentProps) => {
|
||||||
kind,
|
|
||||||
integrationData,
|
|
||||||
}: WidgetPreviewPageContentProps) => {
|
|
||||||
const t = useScopedI18n("widgetPreview");
|
const t = useScopedI18n("widgetPreview");
|
||||||
const { openModal: openWidgetEditModal } = useModalAction(WidgetEditModal);
|
const { openModal: openWidgetEditModal } = useModalAction(WidgetEditModal);
|
||||||
const { openModal: openPreviewDimensionsModal } = useModalAction(
|
const { openModal: openPreviewDimensionsModal } = useModalAction(PreviewDimensionsModal);
|
||||||
PreviewDimensionsModal,
|
const currentDefinition = useMemo(() => widgetImports[kind].definition, [kind]);
|
||||||
);
|
|
||||||
const currentDefinition = useMemo(
|
|
||||||
() => widgetImports[kind].definition,
|
|
||||||
[kind],
|
|
||||||
);
|
|
||||||
const [editMode, setEditMode] = useState(false);
|
const [editMode, setEditMode] = useState(false);
|
||||||
const [dimensions, setDimensions] = useState<Dimensions>({
|
const [dimensions, setDimensions] = useState<Dimensions>({
|
||||||
width: 128,
|
width: 128,
|
||||||
@@ -55,9 +42,13 @@ export const WidgetPreviewPageContent = ({
|
|||||||
const [state, setState] = useState<{
|
const [state, setState] = useState<{
|
||||||
options: Record<string, unknown>;
|
options: Record<string, unknown>;
|
||||||
integrations: BoardItemIntegration[];
|
integrations: BoardItemIntegration[];
|
||||||
|
advancedOptions: BoardItemAdvancedOptions;
|
||||||
}>({
|
}>({
|
||||||
options: reduceWidgetOptionsWithDefaultValues(kind, {}),
|
options: reduceWidgetOptionsWithDefaultValues(kind, {}),
|
||||||
integrations: [],
|
integrations: [],
|
||||||
|
advancedOptions: {
|
||||||
|
customCssClasses: [],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleOpenEditWidgetModal = useCallback(() => {
|
const handleOpenEditWidgetModal = useCallback(() => {
|
||||||
@@ -70,9 +61,7 @@ export const WidgetPreviewPageContent = ({
|
|||||||
integrationData: integrationData.filter(
|
integrationData: integrationData.filter(
|
||||||
(integration) =>
|
(integration) =>
|
||||||
"supportedIntegrations" in currentDefinition &&
|
"supportedIntegrations" in currentDefinition &&
|
||||||
(currentDefinition.supportedIntegrations as string[]).some(
|
(currentDefinition.supportedIntegrations as string[]).some((kind) => kind === integration.kind),
|
||||||
(kind) => kind === integration.kind,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
integrationSupport: "supportedIntegrations" in currentDefinition,
|
integrationSupport: "supportedIntegrations" in currentDefinition,
|
||||||
});
|
});
|
||||||
@@ -96,19 +85,11 @@ export const WidgetPreviewPageContent = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Card
|
<Card withBorder w={dimensions.width} h={dimensions.height} p={dimensions.height >= 96 ? undefined : 4}>
|
||||||
withBorder
|
|
||||||
w={dimensions.width}
|
|
||||||
h={dimensions.height}
|
|
||||||
p={dimensions.height >= 96 ? undefined : 4}
|
|
||||||
>
|
|
||||||
<Comp
|
<Comp
|
||||||
options={state.options as never}
|
options={state.options as never}
|
||||||
integrations={state.integrations.map(
|
integrations={state.integrations.map(
|
||||||
(stateIntegration) =>
|
(stateIntegration) => integrationData.find((integration) => integration.id === stateIntegration.id)!,
|
||||||
integrationData.find(
|
|
||||||
(integration) => integration.id === stateIntegration.id,
|
|
||||||
)!,
|
|
||||||
)}
|
)}
|
||||||
width={dimensions.width}
|
width={dimensions.width}
|
||||||
height={dimensions.height}
|
height={dimensions.height}
|
||||||
@@ -118,36 +99,17 @@ export const WidgetPreviewPageContent = ({
|
|||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
<Affix bottom={12} right={72}>
|
<Affix bottom={12} right={72}>
|
||||||
<ActionIcon
|
<ActionIcon size={48} variant="default" radius="xl" onClick={handleOpenEditWidgetModal}>
|
||||||
size={48}
|
|
||||||
variant="default"
|
|
||||||
radius="xl"
|
|
||||||
onClick={handleOpenEditWidgetModal}
|
|
||||||
>
|
|
||||||
<IconPencil size={24} />
|
<IconPencil size={24} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
</Affix>
|
</Affix>
|
||||||
<Affix bottom={12} right={72 + 60}>
|
<Affix bottom={12} right={72 + 60}>
|
||||||
<ActionIcon
|
<ActionIcon size={48} variant="default" radius="xl" onClick={toggleEditMode}>
|
||||||
size={48}
|
{editMode ? <IconToggleLeft size={24} /> : <IconToggleRight size={24} />}
|
||||||
variant="default"
|
|
||||||
radius="xl"
|
|
||||||
onClick={toggleEditMode}
|
|
||||||
>
|
|
||||||
{editMode ? (
|
|
||||||
<IconToggleLeft size={24} />
|
|
||||||
) : (
|
|
||||||
<IconToggleRight size={24} />
|
|
||||||
)}
|
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
</Affix>
|
</Affix>
|
||||||
<Affix bottom={12} right={72 + 120}>
|
<Affix bottom={12} right={72 + 120}>
|
||||||
<ActionIcon
|
<ActionIcon size={48} variant="default" radius="xl" onClick={openDimensionsModal}>
|
||||||
size={48}
|
|
||||||
variant="default"
|
|
||||||
radius="xl"
|
|
||||||
onClick={openDimensionsModal}
|
|
||||||
>
|
|
||||||
<IconDimensions size={24} />
|
<IconDimensions size={24} />
|
||||||
</ActionIcon>
|
</ActionIcon>
|
||||||
</Affix>
|
</Affix>
|
||||||
|
|||||||
@@ -11,48 +11,36 @@ interface InnerProps {
|
|||||||
setDimensions: (dimensions: Dimensions) => void;
|
setDimensions: (dimensions: Dimensions) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PreviewDimensionsModal = createModal<InnerProps>(
|
export const PreviewDimensionsModal = createModal<InnerProps>(({ actions, innerProps }) => {
|
||||||
({ actions, innerProps }) => {
|
const t = useI18n();
|
||||||
const t = useI18n();
|
const form = useForm({
|
||||||
const form = useForm({
|
initialValues: innerProps.dimensions,
|
||||||
initialValues: innerProps.dimensions,
|
});
|
||||||
});
|
|
||||||
|
|
||||||
const handleSubmit = (values: Dimensions) => {
|
const handleSubmit = (values: Dimensions) => {
|
||||||
innerProps.setDimensions(values);
|
innerProps.setDimensions(values);
|
||||||
actions.closeModal();
|
actions.closeModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||||
<Stack>
|
<Stack>
|
||||||
<InputWrapper label={t("item.move.field.width.label")}>
|
<InputWrapper label={t("item.move.field.width.label")}>
|
||||||
<Slider
|
<Slider min={64} max={1024} step={64} {...form.getInputProps("width")} />
|
||||||
min={64}
|
</InputWrapper>
|
||||||
max={1024}
|
<InputWrapper label={t("item.move.field.height.label")}>
|
||||||
step={64}
|
<Slider min={64} max={1024} step={64} {...form.getInputProps("height")} />
|
||||||
{...form.getInputProps("width")}
|
</InputWrapper>
|
||||||
/>
|
<Group justify="end">
|
||||||
</InputWrapper>
|
<Button variant="subtle" color="gray" onClick={actions.closeModal}>
|
||||||
<InputWrapper label={t("item.move.field.height.label")}>
|
{t("common.action.cancel")}
|
||||||
<Slider
|
</Button>
|
||||||
min={64}
|
<Button type="submit">{t("common.action.confirm")}</Button>
|
||||||
max={1024}
|
</Group>
|
||||||
step={64}
|
</Stack>
|
||||||
{...form.getInputProps("height")}
|
</form>
|
||||||
/>
|
);
|
||||||
</InputWrapper>
|
}).withOptions({
|
||||||
<Group justify="end">
|
|
||||||
<Button variant="subtle" color="gray" onClick={actions.closeModal}>
|
|
||||||
{t("common.action.cancel")}
|
|
||||||
</Button>
|
|
||||||
<Button type="submit">{t("common.action.confirm")}</Button>
|
|
||||||
</Group>
|
|
||||||
</Stack>
|
|
||||||
</form>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
).withOptions({
|
|
||||||
defaultTitle: (t) => t("widgetPreview.dimensions.title"),
|
defaultTitle: (t) => t("widgetPreview.dimensions.title"),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,9 @@ const handler = auth(async (req) => {
|
|||||||
endpoint: "/api/trpc",
|
endpoint: "/api/trpc",
|
||||||
router: appRouter,
|
router: appRouter,
|
||||||
req,
|
req,
|
||||||
createContext: () =>
|
createContext: () => createTRPCContext({ session: req.auth, headers: req.headers }),
|
||||||
createTRPCContext({ session: req.auth, headers: req.headers }),
|
|
||||||
onError({ error, path, type }) {
|
onError({ error, path, type }) {
|
||||||
logger.error(
|
logger.error(`tRPC Error with ${type} on '${path}': (${error.code}) - ${error.message}`);
|
||||||
`tRPC Error with ${type} on '${path}': (${error.code}) - ${error.message}`,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user