chore: update prettier configuration for print width (#519)
* feat: update prettier configuration for print width * chore: apply code formatting to entire repository * fix: remove build files * fix: format issue --------- Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
This commit is contained in:
1 parent
919161798e
commit
f1b1ec59ec
234 files changed
+2444
-5375
No files matched your search
@@ -1,9 +1,6 @@
|
||||
import type { Session } from "@homarr/auth";
|
||||
|
||||
export const canAccessUserEditPage = (
|
||||
session: Session | null,
|
||||
userId: string,
|
||||
) => {
|
||||
export const canAccessUserEditPage = (session: Session | null, userId: string) => {
|
||||
if (!session) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+5
-8
@@ -18,14 +18,11 @@ interface DeleteUserButtonProps {
|
||||
export const DeleteUserButton = ({ user }: DeleteUserButtonProps) => {
|
||||
const t = useI18n();
|
||||
const router = useRouter();
|
||||
const { mutateAsync: mutateUserDeletionAsync } =
|
||||
clientApi.user.delete.useMutation({
|
||||
async onSuccess() {
|
||||
await revalidatePathActionAsync("/manage/users").then(() =>
|
||||
router.push("/manage/users"),
|
||||
);
|
||||
},
|
||||
});
|
||||
const { mutateAsync: mutateUserDeletionAsync } = clientApi.user.delete.useMutation({
|
||||
async onSuccess() {
|
||||
await revalidatePathActionAsync("/manage/users").then(() => router.push("/manage/users"));
|
||||
},
|
||||
});
|
||||
const { openConfirmModal } = useConfirmModal();
|
||||
|
||||
const handleDelete = useCallback(
|
||||
|
||||
+10
-39
@@ -8,10 +8,7 @@ import { IconPencil, IconPhotoEdit, IconPhotoX } from "@tabler/icons-react";
|
||||
import type { RouterOutputs } from "@homarr/api";
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useConfirmModal } from "@homarr/modals";
|
||||
import {
|
||||
showErrorNotification,
|
||||
showSuccessNotification,
|
||||
} from "@homarr/notifications";
|
||||
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||
import { UserAvatar } from "@homarr/ui";
|
||||
|
||||
@@ -46,25 +43,18 @@ export const UserProfileAvatarForm = ({ user }: UserProfileAvatarForm) => {
|
||||
// Revalidate all as the avatar is used in multiple places
|
||||
await revalidatePathActionAsync("/");
|
||||
showSuccessNotification({
|
||||
message: tManageAvatar(
|
||||
"changeImage.notification.success.message",
|
||||
),
|
||||
message: tManageAvatar("changeImage.notification.success.message"),
|
||||
});
|
||||
},
|
||||
onError(error) {
|
||||
if (error.shape?.data.code === "BAD_REQUEST") {
|
||||
showErrorNotification({
|
||||
title: tManageAvatar("changeImage.notification.toLarge.title"),
|
||||
message: tManageAvatar(
|
||||
"changeImage.notification.toLarge.message",
|
||||
{ size: "256KB" },
|
||||
),
|
||||
message: tManageAvatar("changeImage.notification.toLarge.message", { size: "256KB" }),
|
||||
});
|
||||
} else {
|
||||
showErrorNotification({
|
||||
message: tManageAvatar(
|
||||
"changeImage.notification.error.message",
|
||||
),
|
||||
message: tManageAvatar("changeImage.notification.error.message"),
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -89,16 +79,12 @@ export const UserProfileAvatarForm = ({ user }: UserProfileAvatarForm) => {
|
||||
// Revalidate all as the avatar is used in multiple places
|
||||
await revalidatePathActionAsync("/");
|
||||
showSuccessNotification({
|
||||
message: tManageAvatar(
|
||||
"removeImage.notification.success.message",
|
||||
),
|
||||
message: tManageAvatar("removeImage.notification.success.message"),
|
||||
});
|
||||
},
|
||||
onError() {
|
||||
showErrorNotification({
|
||||
message: tManageAvatar(
|
||||
"removeImage.notification.error.message",
|
||||
),
|
||||
message: tManageAvatar("removeImage.notification.error.message"),
|
||||
});
|
||||
},
|
||||
},
|
||||
@@ -109,13 +95,7 @@ export const UserProfileAvatarForm = ({ user }: UserProfileAvatarForm) => {
|
||||
|
||||
return (
|
||||
<Box pos="relative">
|
||||
<Menu
|
||||
opened={opened}
|
||||
keepMounted
|
||||
onChange={toggle}
|
||||
position="bottom-start"
|
||||
withArrow
|
||||
>
|
||||
<Menu opened={opened} keepMounted onChange={toggle} position="bottom-start" withArrow>
|
||||
<Menu.Target>
|
||||
<UnstyledButton onClick={toggle}>
|
||||
<UserAvatar user={user} size={200} />
|
||||
@@ -134,24 +114,15 @@ export const UserProfileAvatarForm = ({ user }: UserProfileAvatarForm) => {
|
||||
</UnstyledButton>
|
||||
</Menu.Target>
|
||||
<Menu.Dropdown>
|
||||
<FileButton
|
||||
onChange={handleAvatarChange}
|
||||
accept="image/png,image/jpeg,image/webp,image/gif"
|
||||
>
|
||||
<FileButton onChange={handleAvatarChange} accept="image/png,image/jpeg,image/webp,image/gif">
|
||||
{(props) => (
|
||||
<Menu.Item
|
||||
{...props}
|
||||
leftSection={<IconPhotoEdit size={16} stroke={1.5} />}
|
||||
>
|
||||
<Menu.Item {...props} leftSection={<IconPhotoEdit size={16} stroke={1.5} />}>
|
||||
{tManageAvatar("changeImage.label")}
|
||||
</Menu.Item>
|
||||
)}
|
||||
</FileButton>
|
||||
{user.image && (
|
||||
<Menu.Item
|
||||
onClick={handleRemoveAvatar}
|
||||
leftSection={<IconPhotoX size={16} stroke={1.5} />}
|
||||
>
|
||||
<Menu.Item onClick={handleRemoveAvatar} leftSection={<IconPhotoX size={16} stroke={1.5} />}>
|
||||
{tManageAvatar("removeImage.label")}
|
||||
</Menu.Item>
|
||||
)}
|
||||
|
||||
+3
-13
@@ -6,10 +6,7 @@ import { Button, Group, Stack, TextInput } from "@mantine/core";
|
||||
import type { RouterInputs, RouterOutputs } from "@homarr/api";
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useZodForm } from "@homarr/form";
|
||||
import {
|
||||
showErrorNotification,
|
||||
showSuccessNotification,
|
||||
} from "@homarr/notifications";
|
||||
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { validation } from "@homarr/validation";
|
||||
|
||||
@@ -58,15 +55,8 @@ export const UserProfileForm = ({ user }: UserProfileFormProps) => {
|
||||
return (
|
||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||
<Stack>
|
||||
<TextInput
|
||||
label={t("user.field.username.label")}
|
||||
withAsterisk
|
||||
{...form.getInputProps("name")}
|
||||
/>
|
||||
<TextInput
|
||||
label={t("user.field.email.label")}
|
||||
{...form.getInputProps("email")}
|
||||
/>
|
||||
<TextInput label={t("user.field.username.label")} withAsterisk {...form.getInputProps("name")} />
|
||||
<TextInput label={t("user.field.email.label")} {...form.getInputProps("email")} />
|
||||
|
||||
<Group justify="end">
|
||||
<Button type="submit" color="teal" loading={isPending}>
|
||||
|
||||
@@ -5,10 +5,7 @@ import { api } from "@homarr/api/server";
|
||||
import { auth } from "@homarr/auth/next";
|
||||
import { getI18n, getScopedI18n } from "@homarr/translation/server";
|
||||
|
||||
import {
|
||||
DangerZoneItem,
|
||||
DangerZoneRoot,
|
||||
} from "~/components/manage/danger-zone";
|
||||
import { DangerZoneItem, DangerZoneRoot } from "~/components/manage/danger-zone";
|
||||
import { catchTrpcNotFound } from "~/errors/trpc-not-found";
|
||||
import { createMetaTitle } from "~/metadata";
|
||||
import { canAccessUserEditPage } from "../access";
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
import type { PropsWithChildren } from "react";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import {
|
||||
Button,
|
||||
Container,
|
||||
Grid,
|
||||
GridCol,
|
||||
Group,
|
||||
Stack,
|
||||
Text,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { Button, Container, Grid, GridCol, Group, Stack, Text, Title } from "@mantine/core";
|
||||
import { IconSettings, IconShieldLock } from "@tabler/icons-react";
|
||||
|
||||
import { api } from "@homarr/api/server";
|
||||
@@ -26,16 +17,11 @@ interface LayoutProps {
|
||||
params: { userId: string };
|
||||
}
|
||||
|
||||
export default async function Layout({
|
||||
children,
|
||||
params,
|
||||
}: PropsWithChildren<LayoutProps>) {
|
||||
export default async function Layout({ children, params }: PropsWithChildren<LayoutProps>) {
|
||||
const session = await auth();
|
||||
const t = await getI18n();
|
||||
const tUser = await getScopedI18n("management.page.user");
|
||||
const user = await api.user
|
||||
.getById({ userId: params.userId })
|
||||
.catch(catchTrpcNotFound);
|
||||
const user = await api.user.getById({ userId: params.userId }).catch(catchTrpcNotFound);
|
||||
|
||||
if (!canAccessUserEditPage(session, user.id)) {
|
||||
notFound();
|
||||
@@ -54,12 +40,7 @@ export default async function Layout({
|
||||
</Stack>
|
||||
</Group>
|
||||
{session?.user.permissions.includes("admin") && (
|
||||
<Button
|
||||
component={Link}
|
||||
href="/manage/users"
|
||||
color="gray"
|
||||
variant="light"
|
||||
>
|
||||
<Button component={Link} href="/manage/users" color="gray" variant="light">
|
||||
{tUser("back")}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
+2
-9
@@ -6,10 +6,7 @@ import type { RouterInputs, RouterOutputs } from "@homarr/api";
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useSession } from "@homarr/auth/client";
|
||||
import { useZodForm } from "@homarr/form";
|
||||
import {
|
||||
showErrorNotification,
|
||||
showSuccessNotification,
|
||||
} from "@homarr/notifications";
|
||||
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { validation } from "@homarr/validation";
|
||||
|
||||
@@ -74,11 +71,7 @@ export const ChangePasswordForm = ({ user }: ChangePasswordFormProps) => {
|
||||
/>
|
||||
)}
|
||||
|
||||
<PasswordInput
|
||||
withAsterisk
|
||||
label={t("user.field.password.label")}
|
||||
{...form.getInputProps("password")}
|
||||
/>
|
||||
<PasswordInput withAsterisk label={t("user.field.password.label")} {...form.getInputProps("password")} />
|
||||
|
||||
<PasswordInput
|
||||
withAsterisk
|
||||
|
||||
@@ -17,9 +17,7 @@ interface Props {
|
||||
|
||||
export default async function UserSecurityPage({ params }: Props) {
|
||||
const session = await auth();
|
||||
const tSecurity = await getScopedI18n(
|
||||
"management.page.user.setting.security",
|
||||
);
|
||||
const tSecurity = await getScopedI18n("management.page.user.setting.security");
|
||||
const user = await api.user
|
||||
.getById({
|
||||
userId: params.userId,
|
||||
|
||||
@@ -15,18 +15,14 @@ interface UserListComponentProps {
|
||||
initialUserList: RouterOutputs["user"]["getAll"];
|
||||
}
|
||||
|
||||
export const UserListComponent = ({
|
||||
initialUserList,
|
||||
}: UserListComponentProps) => {
|
||||
export const UserListComponent = ({ initialUserList }: UserListComponentProps) => {
|
||||
const tUserList = useScopedI18n("management.page.user.list");
|
||||
const t = useI18n();
|
||||
const { data, isLoading } = clientApi.user.getAll.useQuery(undefined, {
|
||||
initialData: initialUserList,
|
||||
});
|
||||
|
||||
const columns = useMemo<
|
||||
MRT_ColumnDef<RouterOutputs["user"]["getAll"][number]>[]
|
||||
>(
|
||||
const columns = useMemo<MRT_ColumnDef<RouterOutputs["user"]["getAll"][number]>[]>(
|
||||
() => [
|
||||
{
|
||||
accessorKey: "name",
|
||||
|
||||
+9
-44
@@ -1,16 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import {
|
||||
Avatar,
|
||||
Card,
|
||||
PasswordInput,
|
||||
Stack,
|
||||
Stepper,
|
||||
Text,
|
||||
TextInput,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { Avatar, Card, PasswordInput, Stack, Stepper, Text, TextInput, Title } from "@mantine/core";
|
||||
import { IconUserCheck } from "@tabler/icons-react";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
@@ -28,14 +19,10 @@ export const UserCreateStepperComponent = () => {
|
||||
const stepperMax = 4;
|
||||
const [active, setActive] = useState(0);
|
||||
const nextStep = useCallback(
|
||||
() =>
|
||||
setActive((current) => (current < stepperMax ? current + 1 : current)),
|
||||
[setActive],
|
||||
);
|
||||
const prevStep = useCallback(
|
||||
() => setActive((current) => (current > 0 ? current - 1 : current)),
|
||||
() => setActive((current) => (current < stepperMax ? current + 1 : current)),
|
||||
[setActive],
|
||||
);
|
||||
const prevStep = useCallback(() => setActive((current) => (current > 0 ? current - 1 : current)), [setActive]);
|
||||
const hasNext = active < stepperMax;
|
||||
const hasPrevious = active > 0;
|
||||
|
||||
@@ -72,14 +59,9 @@ export const UserCreateStepperComponent = () => {
|
||||
},
|
||||
);
|
||||
|
||||
const allForms = useMemo(
|
||||
() => [generalForm, securityForm],
|
||||
[generalForm, securityForm],
|
||||
);
|
||||
const allForms = useMemo(() => [generalForm, securityForm], [generalForm, securityForm]);
|
||||
|
||||
const isCurrentFormValid = allForms[active]
|
||||
? (allForms[active]!.isValid satisfies () => boolean)
|
||||
: () => true;
|
||||
const isCurrentFormValid = allForms[active] ? (allForms[active]!.isValid satisfies () => boolean) : () => true;
|
||||
const canNavigateToNextStep = isCurrentFormValid();
|
||||
|
||||
const controlledGoToNextStep = useCallback(async () => {
|
||||
@@ -104,12 +86,7 @@ export const UserCreateStepperComponent = () => {
|
||||
return (
|
||||
<>
|
||||
<Title mb="md">{t("title")}</Title>
|
||||
<Stepper
|
||||
active={active}
|
||||
onStepClick={setActive}
|
||||
allowNextStepsSelect={false}
|
||||
mb="md"
|
||||
>
|
||||
<Stepper active={active} onStepClick={setActive} allowNextStepsSelect={false} mb="md">
|
||||
<Stepper.Step
|
||||
label={t("step.personalInformation.label")}
|
||||
allowStepSelect={false}
|
||||
@@ -126,20 +103,12 @@ export const UserCreateStepperComponent = () => {
|
||||
{...generalForm.getInputProps("username")}
|
||||
/>
|
||||
|
||||
<TextInput
|
||||
label={tUserField("email.label")}
|
||||
variant="filled"
|
||||
{...generalForm.getInputProps("email")}
|
||||
/>
|
||||
<TextInput label={tUserField("email.label")} variant="filled" {...generalForm.getInputProps("email")} />
|
||||
</Stack>
|
||||
</Card>
|
||||
</form>
|
||||
</Stepper.Step>
|
||||
<Stepper.Step
|
||||
label={t("step.security.label")}
|
||||
allowStepSelect={false}
|
||||
allowStepClick={false}
|
||||
>
|
||||
<Stepper.Step label={t("step.security.label")} allowStepSelect={false} allowStepClick={false}>
|
||||
<form>
|
||||
<Card p="xl">
|
||||
<Stack gap="md">
|
||||
@@ -167,11 +136,7 @@ export const UserCreateStepperComponent = () => {
|
||||
>
|
||||
3
|
||||
</Stepper.Step>
|
||||
<Stepper.Step
|
||||
label={t("step.review.label")}
|
||||
allowStepSelect={false}
|
||||
allowStepClick={false}
|
||||
>
|
||||
<Stepper.Step label={t("step.review.label")} allowStepSelect={false} allowStepClick={false}>
|
||||
<Card p="xl">
|
||||
<Stack maw={300} align="center" mx="auto">
|
||||
<Avatar size="xl">{generalForm.values.username}</Avatar>
|
||||
|
||||
+3
-16
@@ -1,11 +1,6 @@
|
||||
import Link from "next/link";
|
||||
import { Button, Card, Group } from "@mantine/core";
|
||||
import {
|
||||
IconArrowBackUp,
|
||||
IconArrowLeft,
|
||||
IconArrowRight,
|
||||
IconRotate,
|
||||
} from "@tabler/icons-react";
|
||||
import { IconArrowBackUp, IconArrowLeft, IconArrowRight, IconRotate } from "@tabler/icons-react";
|
||||
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
@@ -51,18 +46,10 @@ export const StepperNavigationComponent = ({
|
||||
</Group>
|
||||
) : (
|
||||
<Group justify="end" wrap="nowrap">
|
||||
<Button
|
||||
variant="light"
|
||||
leftSection={<IconRotate size="1rem" />}
|
||||
onClick={reset}
|
||||
>
|
||||
<Button variant="light" leftSection={<IconRotate size="1rem" />} onClick={reset}>
|
||||
{t("management.page.user.create.action.createAnother")}
|
||||
</Button>
|
||||
<Button
|
||||
leftSection={<IconArrowBackUp size="1rem" />}
|
||||
component={Link}
|
||||
href="/manage/users"
|
||||
>
|
||||
<Button leftSection={<IconArrowBackUp size="1rem" />} component={Link} href="/manage/users">
|
||||
{t("management.page.user.create.action.back")}
|
||||
</Button>
|
||||
</Group>
|
||||
|
||||
@@ -6,10 +6,7 @@ import { Button } from "@mantine/core";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useConfirmModal } from "@homarr/modals";
|
||||
import {
|
||||
showErrorNotification,
|
||||
showSuccessNotification,
|
||||
} from "@homarr/notifications";
|
||||
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
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 (
|
||||
<Button variant="subtle" color="red" onClick={handleDeletion}>
|
||||
|
||||
@@ -14,13 +14,5 @@ interface NavigationLinkProps {
|
||||
export const NavigationLink = ({ href, icon, label }: NavigationLinkProps) => {
|
||||
const pathName = usePathname();
|
||||
|
||||
return (
|
||||
<NavLink
|
||||
component={Link}
|
||||
href={href}
|
||||
active={pathName === href}
|
||||
label={label}
|
||||
leftSection={icon}
|
||||
/>
|
||||
);
|
||||
return <NavLink component={Link} href={href} active={pathName === href} label={label} leftSection={icon} />;
|
||||
};
|
||||
@@ -5,10 +5,7 @@ import { Button, Group, Stack, TextInput } from "@mantine/core";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useZodForm } from "@homarr/form";
|
||||
import {
|
||||
showErrorNotification,
|
||||
showSuccessNotification,
|
||||
} from "@homarr/notifications";
|
||||
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { validation } from "@homarr/validation";
|
||||
|
||||
@@ -64,10 +61,7 @@ export const RenameGroupForm = ({ group }: RenameGroupFormProps) => {
|
||||
return (
|
||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||
<Stack>
|
||||
<TextInput
|
||||
label={t("group.field.name")}
|
||||
{...form.getInputProps("name")}
|
||||
/>
|
||||
<TextInput label={t("group.field.name")} {...form.getInputProps("name")} />
|
||||
|
||||
<Group justify="end">
|
||||
<Button type="submit" color="teal" loading={isPending}>
|
||||
|
||||
+3
-17
@@ -5,10 +5,7 @@ import { Button } from "@mantine/core";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useConfirmModal, useModalAction } from "@homarr/modals";
|
||||
import {
|
||||
showErrorNotification,
|
||||
showSuccessNotification,
|
||||
} from "@homarr/notifications";
|
||||
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
import { UserSelectModal } from "~/app/[locale]/boards/[name]/settings/_access/user-select-modal";
|
||||
@@ -21,9 +18,7 @@ interface TransferGroupOwnershipProps {
|
||||
};
|
||||
}
|
||||
|
||||
export const TransferGroupOwnership = ({
|
||||
group,
|
||||
}: TransferGroupOwnershipProps) => {
|
||||
export const TransferGroupOwnership = ({ group }: TransferGroupOwnershipProps) => {
|
||||
const tTransfer = useScopedI18n("group.action.transfer");
|
||||
const tRoot = useI18n();
|
||||
const [innerOwnerId, setInnerOwnerId] = useState(group.ownerId);
|
||||
@@ -77,16 +72,7 @@ export const TransferGroupOwnership = ({
|
||||
title: tTransfer("label"),
|
||||
},
|
||||
);
|
||||
}, [
|
||||
group.id,
|
||||
group.name,
|
||||
innerOwnerId,
|
||||
mutateAsync,
|
||||
openConfirmModal,
|
||||
openModal,
|
||||
tRoot,
|
||||
tTransfer,
|
||||
]);
|
||||
}, [group.id, group.name, innerOwnerId, mutateAsync, openConfirmModal, openModal, tRoot, tTransfer]);
|
||||
|
||||
return (
|
||||
<Button variant="subtle" color="red" onClick={handleTransfer}>
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
import type { PropsWithChildren } from "react";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
Button,
|
||||
Container,
|
||||
Grid,
|
||||
GridCol,
|
||||
Group,
|
||||
Stack,
|
||||
Text,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { Button, Container, Grid, GridCol, Group, Stack, Text, Title } from "@mantine/core";
|
||||
import { IconLock, IconSettings, IconUsersGroup } from "@tabler/icons-react";
|
||||
|
||||
import { api } from "@homarr/api/server";
|
||||
@@ -21,10 +12,7 @@ interface LayoutProps {
|
||||
params: { id: string };
|
||||
}
|
||||
|
||||
export default async function Layout({
|
||||
children,
|
||||
params,
|
||||
}: PropsWithChildren<LayoutProps>) {
|
||||
export default async function Layout({ children, params }: PropsWithChildren<LayoutProps>) {
|
||||
const t = await getI18n();
|
||||
const tGroup = await getScopedI18n("management.page.group");
|
||||
const group = await api.group.getById({ id: params.id });
|
||||
@@ -38,12 +26,7 @@ export default async function Layout({
|
||||
<Title order={3}>{group.name}</Title>
|
||||
<Text c="gray.5">{t("group.name")}</Text>
|
||||
</Stack>
|
||||
<Button
|
||||
component={Link}
|
||||
href="/manage/users/groups"
|
||||
color="gray"
|
||||
variant="light"
|
||||
>
|
||||
<Button component={Link} href="/manage/users/groups" color="gray" variant="light">
|
||||
{tGroup("back")}
|
||||
</Button>
|
||||
</Group>
|
||||
|
||||
@@ -15,10 +15,7 @@ interface AddGroupMemberProps {
|
||||
presentUserIds: string[];
|
||||
}
|
||||
|
||||
export const AddGroupMember = ({
|
||||
groupId,
|
||||
presentUserIds,
|
||||
}: AddGroupMemberProps) => {
|
||||
export const AddGroupMember = ({ groupId, presentUserIds }: AddGroupMemberProps) => {
|
||||
const tMembersAdd = useScopedI18n("group.action.addMember");
|
||||
const { mutateAsync } = clientApi.group.addMember.useMutation();
|
||||
const { openModal } = useModalAction(UserSelectModal);
|
||||
@@ -32,9 +29,7 @@ export const AddGroupMember = ({
|
||||
userId: id,
|
||||
groupId,
|
||||
});
|
||||
await revalidatePathActionAsync(
|
||||
`/manage/users/groups/${groupId}}/members`,
|
||||
);
|
||||
await revalidatePathActionAsync(`/manage/users/groups/${groupId}}/members`);
|
||||
},
|
||||
presentUserIds,
|
||||
},
|
||||
|
||||
+4
-21
@@ -14,10 +14,7 @@ interface RemoveGroupMemberProps {
|
||||
user: { id: string; name: string | null };
|
||||
}
|
||||
|
||||
export const RemoveGroupMember = ({
|
||||
groupId,
|
||||
user,
|
||||
}: RemoveGroupMemberProps) => {
|
||||
export const RemoveGroupMember = ({ groupId, user }: RemoveGroupMemberProps) => {
|
||||
const t = useI18n();
|
||||
const tRemoveMember = useScopedI18n("group.action.removeMember");
|
||||
const { mutateAsync } = clientApi.group.removeMember.useMutation();
|
||||
@@ -35,27 +32,13 @@ export const RemoveGroupMember = ({
|
||||
groupId,
|
||||
userId: user.id,
|
||||
});
|
||||
await revalidatePathActionAsync(
|
||||
`/manage/users/groups/${groupId}/members`,
|
||||
);
|
||||
await revalidatePathActionAsync(`/manage/users/groups/${groupId}/members`);
|
||||
},
|
||||
});
|
||||
}, [
|
||||
openConfirmModal,
|
||||
mutateAsync,
|
||||
groupId,
|
||||
user.id,
|
||||
user.name,
|
||||
tRemoveMember,
|
||||
]);
|
||||
}, [openConfirmModal, mutateAsync, groupId, user.id, user.name, tRemoveMember]);
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="subtle"
|
||||
color="red.9"
|
||||
size="compact-sm"
|
||||
onClick={handleRemove}
|
||||
>
|
||||
<Button variant="subtle" color="red.9" size="compact-sm" onClick={handleRemove}>
|
||||
{t("common.action.remove")}
|
||||
</Button>
|
||||
);
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
import Link from "next/link";
|
||||
import {
|
||||
Anchor,
|
||||
Center,
|
||||
Group,
|
||||
Stack,
|
||||
Table,
|
||||
TableTbody,
|
||||
TableTd,
|
||||
TableTr,
|
||||
Text,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { Anchor, Center, Group, Stack, Table, TableTbody, TableTd, TableTr, Text, Title } from "@mantine/core";
|
||||
|
||||
import type { RouterOutputs } from "@homarr/api";
|
||||
import { api } from "@homarr/api/server";
|
||||
@@ -29,20 +18,13 @@ interface GroupsDetailPageProps {
|
||||
};
|
||||
}
|
||||
|
||||
export default async function GroupsDetailPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: GroupsDetailPageProps) {
|
||||
export default async function GroupsDetailPage({ params, searchParams }: GroupsDetailPageProps) {
|
||||
const t = await getI18n();
|
||||
const tMembers = await getScopedI18n("management.page.group.setting.members");
|
||||
const group = await api.group.getById({ id: params.id });
|
||||
|
||||
const filteredMembers = searchParams.search
|
||||
? group.members.filter((member) =>
|
||||
member.name
|
||||
?.toLowerCase()
|
||||
.includes(searchParams.search!.trim().toLowerCase()),
|
||||
)
|
||||
? group.members.filter((member) => member.name?.toLowerCase().includes(searchParams.search!.trim().toLowerCase()))
|
||||
: group.members;
|
||||
|
||||
return (
|
||||
@@ -56,10 +38,7 @@ export default async function GroupsDetailPage({
|
||||
})}
|
||||
defaultValue={searchParams.search}
|
||||
/>
|
||||
<AddGroupMember
|
||||
groupId={group.id}
|
||||
presentUserIds={group.members.map((member) => member.id)}
|
||||
/>
|
||||
<AddGroupMember groupId={group.id} presentUserIds={group.members.map((member) => member.id)} />
|
||||
</Group>
|
||||
{filteredMembers.length === 0 && (
|
||||
<Center py="sm">
|
||||
|
||||
@@ -3,10 +3,7 @@ import { Stack, Title } from "@mantine/core";
|
||||
import { api } from "@homarr/api/server";
|
||||
import { getScopedI18n } from "@homarr/translation/server";
|
||||
|
||||
import {
|
||||
DangerZoneItem,
|
||||
DangerZoneRoot,
|
||||
} from "~/components/manage/danger-zone";
|
||||
import { DangerZoneItem, DangerZoneRoot } from "~/components/manage/danger-zone";
|
||||
import { DeleteGroup } from "./_delete-group";
|
||||
import { RenameGroupForm } from "./_rename-group-form";
|
||||
import { TransferGroupOwnership } from "./_transfer-group-ownership";
|
||||
@@ -17,9 +14,7 @@ interface GroupsDetailPageProps {
|
||||
};
|
||||
}
|
||||
|
||||
export default async function GroupsDetailPage({
|
||||
params,
|
||||
}: GroupsDetailPageProps) {
|
||||
export default async function GroupsDetailPage({ params }: GroupsDetailPageProps) {
|
||||
const group = await api.group.getById({ id: params.id });
|
||||
const tGeneral = await getScopedI18n("management.page.group.setting.general");
|
||||
const tGroupAction = await getScopedI18n("group.action");
|
||||
|
||||
+3
-11
@@ -9,10 +9,7 @@ import { objectEntries } from "@homarr/common";
|
||||
import type { GroupPermissionKey } from "@homarr/definitions";
|
||||
import { groupPermissionKeys } from "@homarr/definitions";
|
||||
import { createFormContext } from "@homarr/form";
|
||||
import {
|
||||
showErrorNotification,
|
||||
showSuccessNotification,
|
||||
} from "@homarr/notifications";
|
||||
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
const [FormProvider, useFormContext, useForm] = createFormContext<FormType>();
|
||||
@@ -21,10 +18,7 @@ interface PermissionFormProps {
|
||||
initialPermissions: GroupPermissionKey[];
|
||||
}
|
||||
|
||||
export const PermissionForm = ({
|
||||
children,
|
||||
initialPermissions,
|
||||
}: PropsWithChildren<PermissionFormProps>) => {
|
||||
export const PermissionForm = ({ children, initialPermissions }: PropsWithChildren<PermissionFormProps>) => {
|
||||
const form = useForm({
|
||||
initialValues: groupPermissionKeys.reduce((acc, key) => {
|
||||
acc[key] = initialPermissions.includes(key);
|
||||
@@ -73,9 +67,7 @@ interface SaveAffixProps {
|
||||
export const SaveAffix = ({ groupId }: SaveAffixProps) => {
|
||||
const t = useI18n();
|
||||
const tForm = useScopedI18n("management.page.group.setting.permissions.form");
|
||||
const tNotification = useScopedI18n(
|
||||
"group.action.changePermissions.notification",
|
||||
);
|
||||
const tNotification = useScopedI18n("group.action.changePermissions.notification");
|
||||
const form = useFormContext();
|
||||
const { mutate, isPending } = clientApi.group.savePermissions.useMutation();
|
||||
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
import React from "react";
|
||||
import {
|
||||
Card,
|
||||
CardSection,
|
||||
Divider,
|
||||
Group,
|
||||
Stack,
|
||||
Text,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { Card, CardSection, Divider, Group, Stack, Text, Title } from "@mantine/core";
|
||||
|
||||
import { api } from "@homarr/api/server";
|
||||
import { objectKeys } from "@homarr/common";
|
||||
@@ -15,11 +7,7 @@ import type { GroupPermissionKey } from "@homarr/definitions";
|
||||
import { groupPermissions } from "@homarr/definitions";
|
||||
import { getI18n, getScopedI18n } from "@homarr/translation/server";
|
||||
|
||||
import {
|
||||
PermissionForm,
|
||||
PermissionSwitch,
|
||||
SaveAffix,
|
||||
} from "./_group-permission-form";
|
||||
import { PermissionForm, PermissionSwitch, SaveAffix } from "./_group-permission-form";
|
||||
|
||||
interface GroupPermissionsPageProps {
|
||||
params: {
|
||||
@@ -27,9 +15,7 @@ interface GroupPermissionsPageProps {
|
||||
};
|
||||
}
|
||||
|
||||
export default async function GroupPermissionsPage({
|
||||
params,
|
||||
}: GroupPermissionsPageProps) {
|
||||
export default async function GroupPermissionsPage({ params }: GroupPermissionsPageProps) {
|
||||
const group = await api.group.getById({ id: params.id });
|
||||
const tPermissions = await getScopedI18n("group.permission");
|
||||
const t = await getI18n();
|
||||
@@ -99,10 +85,7 @@ const PermissionCard = async ({ group, isDanger }: PermissionCardProps) => {
|
||||
);
|
||||
};
|
||||
|
||||
const createGroupPermissionKey = (
|
||||
group: keyof typeof groupPermissions,
|
||||
permission: string,
|
||||
): GroupPermissionKey => {
|
||||
const createGroupPermissionKey = (group: keyof typeof groupPermissions, permission: string): GroupPermissionKey => {
|
||||
if (typeof groupPermissions[group] === "boolean") {
|
||||
return group as GroupPermissionKey;
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@ import { Button, Group, Stack, TextInput } from "@mantine/core";
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useZodForm } from "@homarr/form";
|
||||
import { createModal, useModalAction } from "@homarr/modals";
|
||||
import {
|
||||
showErrorNotification,
|
||||
showSuccessNotification,
|
||||
} from "@homarr/notifications";
|
||||
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { validation } from "@homarr/validation";
|
||||
|
||||
@@ -61,11 +58,7 @@ const AddGroupModal = createModal<void>(({ actions }) => {
|
||||
})}
|
||||
>
|
||||
<Stack>
|
||||
<TextInput
|
||||
label={t("group.field.name")}
|
||||
data-autofocus
|
||||
{...form.getInputProps("name")}
|
||||
/>
|
||||
<TextInput label={t("group.field.name")} data-autofocus {...form.getInputProps("name")} />
|
||||
<Group justify="right">
|
||||
<Button onClick={actions.closeModal} variant="subtle" color="gray">
|
||||
{t("common.action.cancel")}
|
||||
|
||||
@@ -27,25 +27,18 @@ const searchParamsSchema = z.object({
|
||||
page: z.string().regex(/\d+/).transform(Number).catch(1),
|
||||
});
|
||||
|
||||
type SearchParamsSchemaInputFromSchema<
|
||||
TSchema extends Record<string, unknown>,
|
||||
> = Partial<{
|
||||
[K in keyof TSchema]: Exclude<TSchema[K], undefined> extends unknown[]
|
||||
? string[]
|
||||
: string;
|
||||
type SearchParamsSchemaInputFromSchema<TSchema extends Record<string, unknown>> = Partial<{
|
||||
[K in keyof TSchema]: Exclude<TSchema[K], undefined> extends unknown[] ? string[] : string;
|
||||
}>;
|
||||
|
||||
interface GroupsListPageProps {
|
||||
searchParams: SearchParamsSchemaInputFromSchema<
|
||||
z.infer<typeof searchParamsSchema>
|
||||
>;
|
||||
searchParams: SearchParamsSchemaInputFromSchema<z.infer<typeof searchParamsSchema>>;
|
||||
}
|
||||
|
||||
export default async function GroupsListPage(props: GroupsListPageProps) {
|
||||
const t = await getI18n();
|
||||
const searchParams = searchParamsSchema.parse(props.searchParams);
|
||||
const { items: groups, totalCount } =
|
||||
await api.group.getPaginated(searchParams);
|
||||
const { items: groups, totalCount } = await api.group.getPaginated(searchParams);
|
||||
|
||||
return (
|
||||
<Container size="xl">
|
||||
@@ -76,9 +69,7 @@ export default async function GroupsListPage(props: GroupsListPageProps) {
|
||||
</Table>
|
||||
|
||||
<Group justify="end">
|
||||
<TablePagination
|
||||
total={Math.ceil(totalCount / searchParams.pageSize)}
|
||||
/>
|
||||
<TablePagination total={Math.ceil(totalCount / searchParams.pageSize)} />
|
||||
</Group>
|
||||
</Stack>
|
||||
</Container>
|
||||
|
||||
@@ -6,9 +6,7 @@ import type { RouterOutputs } from "@homarr/api";
|
||||
import { createModal } from "@homarr/modals";
|
||||
import { useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
export const InviteCopyModal = createModal<
|
||||
RouterOutputs["invite"]["createInvite"]
|
||||
>(({ actions, innerProps }) => {
|
||||
export const InviteCopyModal = createModal<RouterOutputs["invite"]["createInvite"]>(({ actions, innerProps }) => {
|
||||
const t = useScopedI18n("management.page.user.invite");
|
||||
const inviteUrl = useInviteUrl(innerProps);
|
||||
|
||||
@@ -50,13 +48,9 @@ export const InviteCopyModal = createModal<
|
||||
},
|
||||
});
|
||||
|
||||
const createPath = ({ id, token }: RouterOutputs["invite"]["createInvite"]) =>
|
||||
`/auth/invite/${id}?token=${token}`;
|
||||
const createPath = ({ id, token }: RouterOutputs["invite"]["createInvite"]) => `/auth/invite/${id}?token=${token}`;
|
||||
|
||||
const useInviteUrl = ({
|
||||
id,
|
||||
token,
|
||||
}: RouterOutputs["invite"]["createInvite"]) => {
|
||||
const useInviteUrl = ({ id, token }: RouterOutputs["invite"]["createInvite"]) => {
|
||||
const pathname = usePathname();
|
||||
|
||||
return window.location.href.replace(pathname, createPath({ id, token }));
|
||||
|
||||
@@ -21,9 +21,7 @@ interface InviteListComponentProps {
|
||||
initialInvites: RouterOutputs["invite"]["getAll"];
|
||||
}
|
||||
|
||||
export const InviteListComponent = ({
|
||||
initialInvites,
|
||||
}: InviteListComponentProps) => {
|
||||
export const InviteListComponent = ({ initialInvites }: InviteListComponentProps) => {
|
||||
const t = useScopedI18n("management.page.user.invite");
|
||||
const { data, isLoading } = clientApi.invite.getAll.useQuery(undefined, {
|
||||
initialData: initialInvites,
|
||||
@@ -32,9 +30,7 @@ export const InviteListComponent = ({
|
||||
refetchOnReconnect: false,
|
||||
});
|
||||
|
||||
const columns = useMemo<
|
||||
MRT_ColumnDef<RouterOutputs["invite"]["getAll"][number]>[]
|
||||
>(
|
||||
const columns = useMemo<MRT_ColumnDef<RouterOutputs["invite"]["getAll"][number]>[]>(
|
||||
() => [
|
||||
{
|
||||
accessorKey: "id",
|
||||
@@ -100,11 +96,7 @@ const RenderTopToolbarCustomActions = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const RenderRowActions = ({
|
||||
row,
|
||||
}: {
|
||||
row: MRT_Row<RouterOutputs["invite"]["getAll"][number]>;
|
||||
}) => {
|
||||
const RenderRowActions = ({ row }: { row: MRT_Row<RouterOutputs["invite"]["getAll"][number]> }) => {
|
||||
const t = useScopedI18n("management.page.user.invite");
|
||||
const { mutate, isPending } = clientApi.invite.deleteInvite.useMutation();
|
||||
const utils = clientApi.useUtils();
|
||||
@@ -121,12 +113,7 @@ const RenderRowActions = ({
|
||||
}, [openConfirmModal, row.original.id, mutate, utils, t]);
|
||||
|
||||
return (
|
||||
<ActionIcon
|
||||
variant="subtle"
|
||||
color="red"
|
||||
onClick={handleDelete}
|
||||
loading={isPending}
|
||||
>
|
||||
<ActionIcon variant="subtle" color="red" onClick={handleDelete} loading={isPending}>
|
||||
<IconTrash color="red" size={20} stroke={1.5} />
|
||||
</ActionIcon>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user