Skip to content

Commit

Permalink
feat(admin): Add edit button with form for forum
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Feb 24, 2024
1 parent 6c89a16 commit 467a829
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 20 deletions.
8 changes: 4 additions & 4 deletions frontend/admin/forum/views/forums/actions/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { Loader } from "@/components/loader";

const CreateEditFormForumAdmin = lazy(() =>
import("../create-edit-form/create-edit-form-forum-admin").then(module => ({
default: module.CreateEditFormForumAdmin
const Content = lazy(() =>
import("../create-edit/create-edit").then(module => ({
default: module.CreateEditForumAdmin
}))
);

Expand All @@ -28,7 +28,7 @@ export const ActionsForumsForumAdmin = () => {

<DialogContent className="max-w-6xl">
<Suspense fallback={<Loader />}>
<CreateEditFormForumAdmin />
<Content />
</Suspense>
</DialogContent>
</Dialog>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum TabsEnum {
PERMISSIONS = "permissions"
}

export const CreateEditFormForumAdmin = () => {
export const CreateEditForumAdmin = () => {
const t = useTranslations("admin.forum.forums");
const tCore = useTranslations("core");
const { form, onSubmit } = useCreateEditFormForumAdmin();
Expand Down
3 changes: 2 additions & 1 deletion frontend/admin/forum/views/forums/table/content-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ export const ContentTableForumsForumAdmin = () => {

if (isLoading) return <Loader />;
if (isError) return <ErrorAdminView />;
if (!data || data.length === 0)
if (!data || data.length === 0) {
return <div className="text-center">{t("no_results")}</div>;
}

return (
<DndContext
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { EditActionForumAdmin } from "./edit";

export const ActionsForumAdmin = () => {
return (
<div className="flex gap-2 flex-shrink-0">
<EditActionForumAdmin />
</div>
);
};
33 changes: 33 additions & 0 deletions frontend/admin/forum/views/forums/table/item/actions/edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Pencil } from "lucide-react";
import { useTranslations } from "next-intl";
import { Suspense, lazy } from "react";

import { Loader } from "@/components/loader";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";

const Content = lazy(() =>
import("../../../create-edit/create-edit").then(module => ({
default: module.CreateEditForumAdmin
}))
);

export const EditActionForumAdmin = () => {
const t = useTranslations("core");

return (
<Dialog>
<DialogTrigger asChild>
<Button variant="ghost" size="icon" tooltip={t("edit")}>
<Pencil />
</Button>
</DialogTrigger>

<DialogContent className="max-w-6xl">
<Suspense fallback={<Loader />}>
<Content />
</Suspense>
</DialogContent>
</Dialog>
);
};
32 changes: 18 additions & 14 deletions frontend/admin/forum/views/forums/table/item/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useTextLang } from "@/hooks/core/use-text-lang";
import { cn } from "@/functions/classnames";
import { useChildrenForumForumsAdminAPI } from "./hooks/use-children-forum-forums-admin-api";
import type { Admin__Forum_Forums__ShowFlattenedItem } from "../types";
import { ActionsForumAdmin } from "./actions/actions";

interface Props extends Admin__Forum_Forums__ShowFlattenedItem {
indentationWidth: number;
Expand Down Expand Up @@ -58,18 +59,10 @@ export const ItemTableForumsForumAdmin = ({
"--spacing": `${indentationWidth * depth}px`
} as CSSProperties
}
onClick={() => {
if (allowOpenChildren) onCollapse?.(id);
}}
role={allowOpenChildren ? "button" : undefined}
tabIndex={allowOpenChildren ? 0 : -1}
onKeyDown={e => {
if (e.key === "Enter" && allowOpenChildren) onCollapse?.(id);
}}
>
<div
className={cn(
"p-4 flex gap-4 bg-card items-center transition-[background-color,opacity] relative border",
"p-4 flex gap-2 bg-card items-center transition-[background-color,opacity] relative border",
{
"animate-pulse bg-primary/20": isDropHere,
"z-10": isDragging
Expand All @@ -93,16 +86,27 @@ export const ItemTableForumsForumAdmin = ({
</Button>

{childrenCount > 0 && (
<ChevronRight
className={cn("transition-transform text-muted-foreground", {
"rotate-90": isOpenChildren
})}
/>
<Button
onClick={() => {
if (allowOpenChildren) onCollapse?.(id);
}}
variant="ghost"
size="icon"
tooltip=""
>
<ChevronRight
className={cn("transition-transform text-muted-foreground", {
"rotate-90": isOpenChildren
})}
/>
</Button>
)}

<div className="flex-grow flex flex-col">
<span>{convertText(name)}</span>
</div>

<ActionsForumAdmin />
</div>
</div>
);
Expand Down

0 comments on commit 467a829

Please sign in to comment.