mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix: server/client error on some dialogs.
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
import {PageParams} from "@/types/next";
|
import {PageParams} from "@/types/next";
|
||||||
import {Page, PageContent, PageTitle} from "@/features/layout/page";
|
import {Page, PageContent, PageTitle} from "@/features/layout/page";
|
||||||
import {buttonVariants} from "@/components/ui/button";
|
|
||||||
import {GearIcon} from "@radix-ui/react-icons";
|
|
||||||
import {
|
import {
|
||||||
ButtonDeleteProject
|
ButtonDeleteProject
|
||||||
} from "@/components/wrappers/dashboard/projects/button-delete-project/button-delete-project";
|
} from "@/components/wrappers/dashboard/projects/button-delete-project/button-delete-project";
|
||||||
@@ -17,6 +15,7 @@ import {capitalizeFirstLetter} from "@/utils/text";
|
|||||||
import {ProjectDialog} from "@/features/projects/components/project.dialog";
|
import {ProjectDialog} from "@/features/projects/components/project.dialog";
|
||||||
import {DatabaseWith} from "@/db/schema/07_database";
|
import {DatabaseWith} from "@/db/schema/07_database";
|
||||||
import {ProjectWith} from "@/db/schema/06_project";
|
import {ProjectWith} from "@/db/schema/06_project";
|
||||||
|
import {isUuidv4} from "@/utils/verify-uuid";
|
||||||
|
|
||||||
|
|
||||||
export default async function RoutePage(props: PageParams<{
|
export default async function RoutePage(props: PageParams<{
|
||||||
@@ -26,6 +25,10 @@ export default async function RoutePage(props: PageParams<{
|
|||||||
projectId
|
projectId
|
||||||
} = await props.params;
|
} = await props.params;
|
||||||
|
|
||||||
|
if (!isUuidv4(projectId)) {
|
||||||
|
notFound()
|
||||||
|
}
|
||||||
|
|
||||||
const organization = await getOrganization({});
|
const organization = await getOrganization({});
|
||||||
const activeMember = await getActiveMember()
|
const activeMember = await getActiveMember()
|
||||||
|
|
||||||
@@ -78,15 +81,12 @@ export default async function RoutePage(props: PageParams<{
|
|||||||
{!isMember && (
|
{!isMember && (
|
||||||
<div className="flex items-center gap-2 md:justify-between w-full ">
|
<div className="flex items-center gap-2 md:justify-between w-full ">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<ProjectDialog
|
<ProjectDialog
|
||||||
databases={availableDatabases}
|
databases={availableDatabases}
|
||||||
organization={org}
|
organization={org}
|
||||||
project={proj as ProjectWith}
|
project={proj as ProjectWith}
|
||||||
>
|
isEdit={true}
|
||||||
<div className={buttonVariants({variant: "outline", className: "cursor-pointer"})}>
|
/>
|
||||||
<GearIcon className="w-7 h-7"/>
|
|
||||||
</div>
|
|
||||||
</ProjectDialog>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<ButtonDeleteProject projectId={projectId} text={"Delete Project"}/>
|
<ButtonDeleteProject projectId={projectId} text={"Delete Project"}/>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {PageParams} from "@/types/next";
|
import {PageParams} from "@/types/next";
|
||||||
import {CardsWithPagination} from "@/components/wrappers/common/cards-with-pagination";
|
import {CardsWithPagination} from "@/components/wrappers/common/cards-with-pagination";
|
||||||
import {Button} from "@/components/ui/button";
|
|
||||||
import {Page, PageActions, PageContent, PageHeader, PageTitle} from "@/features/layout/page";
|
import {Page, PageActions, PageContent, PageHeader, PageTitle} from "@/features/layout/page";
|
||||||
import {ProjectCard} from "@/components/wrappers/dashboard/projects/project-card/project-card";
|
import {ProjectCard} from "@/components/wrappers/dashboard/projects/project-card/project-card";
|
||||||
import {db} from "@/db";
|
import {db} from "@/db";
|
||||||
@@ -56,9 +55,7 @@ export default async function RoutePage(props: PageParams<{}>) {
|
|||||||
<PageTitle>Projects</PageTitle>
|
<PageTitle>Projects</PageTitle>
|
||||||
{(projects.length > 0 && !isMember) && (
|
{(projects.length > 0 && !isMember) && (
|
||||||
<PageActions>
|
<PageActions>
|
||||||
<ProjectDialog databases={availableDatabases} organization={organization}>
|
<ProjectDialog databases={availableDatabases} organization={organization}/>
|
||||||
<Button>+ Create Project</Button>
|
|
||||||
</ProjectDialog>
|
|
||||||
</PageActions>
|
</PageActions>
|
||||||
)}
|
)}
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
@@ -75,9 +72,7 @@ export default async function RoutePage(props: PageParams<{}>) {
|
|||||||
) : isMember ? (
|
) : isMember ? (
|
||||||
<EmptyStatePlaceholder text="No project available"/>
|
<EmptyStatePlaceholder text="No project available"/>
|
||||||
) : (
|
) : (
|
||||||
<ProjectDialog databases={availableDatabases} organization={organization}>
|
<ProjectDialog databases={availableDatabases} organization={organization} isEmpty={true}/>
|
||||||
<EmptyStatePlaceholder text="Create new Project"/>
|
|
||||||
</ProjectDialog>
|
|
||||||
)}
|
)}
|
||||||
</PageContent>
|
</PageContent>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ export const ButtonDeleteProject = (props: ButtonDeleteProjectProps) => {
|
|||||||
onSuccess: async (result: any) => {
|
onSuccess: async (result: any) => {
|
||||||
if (result.data?.success) {
|
if (result.data?.success) {
|
||||||
toast.success(result.data.actionSuccess.message);
|
toast.success(result.data.actionSuccess.message);
|
||||||
router.push("/");
|
router.push("/dashboard/projects");
|
||||||
} else {
|
} else {
|
||||||
toast.error(result.data.actionError.message || "Unknown error occurred.");
|
toast.error(result.data.actionError.message || "Unknown error occurred.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,36 +8,61 @@ import {
|
|||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {ProjectForm} from "@/features/projects/components/project.form";
|
import {ProjectForm} from "@/features/projects/components/project.form";
|
||||||
import {useState} from "react";
|
import {ReactNode, useState} from "react";
|
||||||
import {Button} from "@/components/ui/button";
|
import {Button, buttonVariants} from "@/components/ui/button";
|
||||||
import {Plus} from "lucide-react";
|
import {Plus} from "lucide-react";
|
||||||
import {DatabaseWith} from "@/db/schema/07_database";
|
import {DatabaseWith} from "@/db/schema/07_database";
|
||||||
import {Organization} from "@/db/schema/03_organization";
|
import {Organization} from "@/db/schema/03_organization";
|
||||||
import {ProjectWith} from "@/db/schema/06_project";
|
import {ProjectWith} from "@/db/schema/06_project";
|
||||||
|
import {GearIcon} from "@radix-ui/react-icons";
|
||||||
|
import {EmptyStatePlaceholder} from "@/components/wrappers/common/empty-state-placeholder";
|
||||||
|
|
||||||
type ProjectDialogProps = {
|
type ProjectDialogProps = {
|
||||||
children?: React.ReactNode;
|
children?: ReactNode;
|
||||||
databases: DatabaseWith[];
|
databases: DatabaseWith[];
|
||||||
organization: Organization;
|
organization: Organization;
|
||||||
project?: ProjectWith;
|
project?: ProjectWith;
|
||||||
|
isEdit?: boolean;
|
||||||
|
isEmpty?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ProjectDialog = ({children, databases, organization, project}: ProjectDialogProps) => {
|
export const ProjectDialog = ({
|
||||||
|
databases,
|
||||||
|
organization,
|
||||||
|
project,
|
||||||
|
isEdit = false,
|
||||||
|
isEmpty = false
|
||||||
|
}: ProjectDialogProps) => {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const isEdit = !!project;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={setOpen}>
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
{children ? children : <Button><Plus className="mr-2 h-4 w-4"/> Create Project</Button>}
|
<div>
|
||||||
|
{isEdit ?
|
||||||
|
<div className={buttonVariants({variant: "outline", className: "cursor-pointer"})}>
|
||||||
|
<GearIcon className="w-7 h-7"/>
|
||||||
|
</div>
|
||||||
|
:
|
||||||
|
<>
|
||||||
|
{isEmpty ?
|
||||||
|
<EmptyStatePlaceholder text="Create new Project"/>
|
||||||
|
:
|
||||||
|
<Button><Plus className="mr-2 h-4 w-4"/> Create Project</Button>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent>
|
<DialogContent
|
||||||
|
onOpenAutoFocus={(e) => e.preventDefault()}
|
||||||
|
>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>{isEdit ? `Edit ${project.name}` : "Create new project"}</DialogTitle>
|
<DialogTitle>{isEdit ? `Edit ${project?.name}` : "Create new project"}</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<ProjectForm
|
<ProjectForm
|
||||||
onSuccess={() => setOpen(false)}
|
onSuccess={() => setOpen(false)}
|
||||||
databases={databases}
|
databases={databases}
|
||||||
organization={organization}
|
organization={organization}
|
||||||
defaultValues={project ? {
|
defaultValues={project ? {
|
||||||
...project,
|
...project,
|
||||||
|
|||||||
Reference in New Issue
Block a user