mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Working on the Portabase debug.
This commit is contained in:
+21
-21
@@ -7,36 +7,36 @@ import { Form } from "@/components/ui/form";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Organization, User } from "@prisma/client";
|
||||
import { MultiSelect } from "@/components/wrappers/common/multiselect/multi-select";
|
||||
import { OrganizationFormSchema, OrganizationFormType } from "@/components/wrappers/dashboard/organization/OrganizationForm/organization-form.schema";
|
||||
import { createOrganizationAction, updateOrganizationAction } from "@/components/wrappers/dashboard/organization/organization.action";
|
||||
import { updateOrganizationAction } from "@/components/wrappers/dashboard/organization/organization.action";
|
||||
import { toast } from "sonner";
|
||||
import {Member, Organization} from "better-auth/plugins";
|
||||
|
||||
export type organizationFormProps = {
|
||||
defaultValues?: Organization;
|
||||
users: User[];
|
||||
members: Member[];
|
||||
};
|
||||
|
||||
export const OrganizationForm = (props: organizationFormProps) => {
|
||||
const router = useRouter();
|
||||
const isCreate = !Boolean(props.defaultValues);
|
||||
|
||||
const formatUsersList = (users: User[]) => {
|
||||
return users.map((user) => ({
|
||||
value: user.id,
|
||||
label: `${user.name} | ${user.email}`,
|
||||
const formatUsersList = (members: Member[]) => {
|
||||
return members.map((member) => ({
|
||||
value: member.id,
|
||||
label: `${member.user.name} | ${member.user.email}`,
|
||||
}));
|
||||
};
|
||||
|
||||
const formatDefaultUsers = (users: OrganizationFormType["users"]): string[] => {
|
||||
console.log(users);
|
||||
return users.map((user) => user.userId);
|
||||
const formatDefaultUsers = (members: OrganizationFormType["members"]): string[] => {
|
||||
console.log(members);
|
||||
return members.map((member) => member.userId);
|
||||
};
|
||||
|
||||
const formattedDefaultValues = {
|
||||
...props.defaultValues,
|
||||
users: !isCreate ? formatDefaultUsers(props.defaultValues?.users) : [],
|
||||
users: !isCreate ? formatDefaultUsers(props.defaultValues?.members) : [],
|
||||
};
|
||||
|
||||
const form = useZodForm({
|
||||
@@ -47,15 +47,15 @@ export const OrganizationForm = (props: organizationFormProps) => {
|
||||
const mutation = useMutation({
|
||||
mutationFn: async (values: OrganizationFormType) => {
|
||||
console.log(values);
|
||||
const organization = await updateOrganizationAction({ data: values, organizationId: props.defaultValues.id });
|
||||
console.log(organization);
|
||||
if (organization.data.success) {
|
||||
toast.success(organization.data.actionSuccess.message);
|
||||
router.push(`/dashboard/${organization.data.value.slug}/settings`);
|
||||
router.refresh();
|
||||
} else {
|
||||
toast.success(organization.data.actionError.message);
|
||||
}
|
||||
// const organization = await updateOrganizationAction({ data: values, organizationId: props.defaultValues.id });
|
||||
// console.log(organization);
|
||||
// if (organization.data.success) {
|
||||
// // toast.success(organization.data.actionSuccess.message);
|
||||
// // router.push(`/dashboard/${organization.data.value.slug}/settings`);
|
||||
// // router.refresh();
|
||||
// } else {
|
||||
// // toast.success(organization.data.actionError.message);
|
||||
// }
|
||||
},
|
||||
});
|
||||
|
||||
@@ -113,7 +113,7 @@ export const OrganizationForm = (props: organizationFormProps) => {
|
||||
<FormLabel>Databases</FormLabel>
|
||||
<FormControl>
|
||||
<MultiSelect
|
||||
options={formatUsersList(props.users)}
|
||||
options={formatUsersList(props.members)}
|
||||
onValueChange={field.onChange}
|
||||
defaultValue={field.value ?? []}
|
||||
placeholder="Select databases"
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ export const OrganizationFormSchema = z.object({
|
||||
.regex(/^[a-zA-Z0-9_-]*$/, 'Slug can only contain letters, numbers, underscores, and hyphens')
|
||||
.min(5, 'Slug must be at least 5 characters long')
|
||||
.max(20, 'Slug must be at most 20 characters long'),
|
||||
users: z.array(z.string()),
|
||||
members: z.array(z.string()),
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import {User, UserOrganization} from "@prisma/client";
|
||||
import {DataTableWithPagination} from "@/components/wrappers/common/table/data-table-with-pagination";
|
||||
import {usersColumns} from "@/components/wrappers/dashboard/settings/SettingsUsersTab/columns-users-settings";
|
||||
import {Table, TableBody, TableCell, TableHead, TableHeader, TableRow} from "@/components/ui/table";
|
||||
import {flexRender, Row} from "@tanstack/react-table";
|
||||
@@ -7,13 +5,13 @@ import {cn} from "@/lib/utils";
|
||||
|
||||
|
||||
export type SettingsUsersTabProps = {
|
||||
currentUser: User;
|
||||
users: UserOrganization[]
|
||||
// currentUser: User;
|
||||
// users: UserOrganization[]
|
||||
}
|
||||
|
||||
export const SettingsUsersTab = (props: SettingsUsersTabProps) => {
|
||||
|
||||
const {currentUser, users} = props;
|
||||
// const {currentUser, users} = props;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full py-4">
|
||||
@@ -21,12 +19,12 @@ export const SettingsUsersTab = (props: SettingsUsersTabProps) => {
|
||||
<h1>List of organization's users</h1>
|
||||
</div>
|
||||
<div className="mt-5">
|
||||
<DataTableWithPagination
|
||||
columns={usersColumns}
|
||||
data={users}
|
||||
DataTable={UsersDataTable}
|
||||
dataTableProps={{currentUser}}
|
||||
/>
|
||||
{/*<DataTableWithPagination*/}
|
||||
{/* columns={usersColumns}*/}
|
||||
{/* data={users}*/}
|
||||
{/* DataTable={UsersDataTable}*/}
|
||||
{/* dataTableProps={{currentUser}}*/}
|
||||
{/*/>*/}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
@@ -35,63 +33,65 @@ export const SettingsUsersTab = (props: SettingsUsersTabProps) => {
|
||||
|
||||
|
||||
export type usersDataTableProps = {
|
||||
currentUser: User;
|
||||
table: any,
|
||||
// currentUser: User;
|
||||
// table: any,
|
||||
}
|
||||
|
||||
export const UsersDataTable = ({currentUser, table}: usersDataTableProps) => {
|
||||
export const UsersDataTable = (
|
||||
// {currentUser, table}: usersDataTableProps
|
||||
) => {
|
||||
|
||||
return (
|
||||
<div className="rounded-md border w-full ">
|
||||
<Table className="w-full">
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRow key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => {
|
||||
return (
|
||||
<TableHead key={header.id}>
|
||||
{header.isPlaceholder
|
||||
? null
|
||||
: flexRender(
|
||||
header.column.columnDef.header,
|
||||
header.getContext()
|
||||
)}
|
||||
</TableHead>
|
||||
)
|
||||
})}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{table.getRowModel().rows?.length ? (
|
||||
table.getRowModel().rows.map((row: Row<UserOrganization>) => {
|
||||
return(
|
||||
<TableRow
|
||||
className={cn((row.original.userId) === currentUser.id ? "opacity-40 pointer-events-none" : "")}
|
||||
key={row.id}
|
||||
data-state={row.getIsSelected() && "selected"}
|
||||
>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<TableCell key={cell.id}>
|
||||
{flexRender(
|
||||
cell.column.columnDef.cell,
|
||||
cell.getContext(),
|
||||
)}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
)
|
||||
}
|
||||
{/*<Table className="w-full">*/}
|
||||
{/* <TableHeader>*/}
|
||||
{/* {table.getHeaderGroups().map((headerGroup) => (*/}
|
||||
{/* <TableRow key={headerGroup.id}>*/}
|
||||
{/* {headerGroup.headers.map((header) => {*/}
|
||||
{/* return (*/}
|
||||
{/* <TableHead key={header.id}>*/}
|
||||
{/* {header.isPlaceholder*/}
|
||||
{/* ? null*/}
|
||||
{/* : flexRender(*/}
|
||||
{/* header.column.columnDef.header,*/}
|
||||
{/* header.getContext()*/}
|
||||
{/* )}*/}
|
||||
{/* </TableHead>*/}
|
||||
{/* )*/}
|
||||
{/* })}*/}
|
||||
{/* </TableRow>*/}
|
||||
{/* ))}*/}
|
||||
{/* </TableHeader>*/}
|
||||
{/* <TableBody>*/}
|
||||
{/* {table.getRowModel().rows?.length ? (*/}
|
||||
{/* table.getRowModel().rows.map((row: Row<UserOrganization>) => {*/}
|
||||
{/* return(*/}
|
||||
{/* <TableRow*/}
|
||||
{/* className={cn((row.original.userId) === currentUser.id ? "opacity-40 pointer-events-none" : "")}*/}
|
||||
{/* key={row.id}*/}
|
||||
{/* data-state={row.getIsSelected() && "selected"}*/}
|
||||
{/* >*/}
|
||||
{/* {row.getVisibleCells().map((cell) => (*/}
|
||||
{/* <TableCell key={cell.id}>*/}
|
||||
{/* {flexRender(*/}
|
||||
{/* cell.column.columnDef.cell,*/}
|
||||
{/* cell.getContext(),*/}
|
||||
{/* )}*/}
|
||||
{/* </TableCell>*/}
|
||||
{/* ))}*/}
|
||||
{/* </TableRow>*/}
|
||||
{/* )*/}
|
||||
{/* }*/}
|
||||
|
||||
)) : (
|
||||
<TableRow>
|
||||
<TableCell colSpan={table.getAllColumns().length} className="h-24 text-center">
|
||||
No results.
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
{/* )) : (*/}
|
||||
{/* <TableRow>*/}
|
||||
{/* <TableCell colSpan={table.getAllColumns().length} className="h-24 text-center">*/}
|
||||
{/* No results.*/}
|
||||
{/* </TableCell>*/}
|
||||
{/* </TableRow>*/}
|
||||
{/* )}*/}
|
||||
{/* </TableBody>*/}
|
||||
{/*</Table>*/}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,17 +9,19 @@ import {
|
||||
SidebarMenu as SM,
|
||||
SidebarMenuItem,
|
||||
} from "@/components/ui/sidebar";
|
||||
import { SidebarItem, SidebarMenu } from "@/components/wrappers/dashboard/sideBar/SideBarMenu/SideBarMenu";
|
||||
import { OrganizationCombobox } from "@/components/wrappers/dashboard/organization/organization-combobox";
|
||||
import { SideBarLogo } from "@/components/wrappers/dashboard/sideBar/SideBarLogo/SideBarLogo";
|
||||
import { SideBarFooterCredit } from "@/components/wrappers/dashboard/sideBar/SideBarFooterCredit/SideBarFooterCredit";
|
||||
import { LoggedInButton } from "@/components/wrappers/dashboard/loggedInButton/LoggedInButton";
|
||||
import { Layers, ChartArea, Settings, ShieldHalf } from "lucide-react";
|
||||
import { authClient } from "@/lib/auth/auth-client";
|
||||
import { SidebarContentA } from "./sidebar-content";
|
||||
import {SidebarItem, SidebarMenu} from "@/components/wrappers/dashboard/sideBar/SideBarMenu/SideBarMenu";
|
||||
import {OrganizationCombobox} from "@/components/wrappers/dashboard/organization/organization-combobox";
|
||||
import {SideBarLogo} from "@/components/wrappers/dashboard/sideBar/SideBarLogo/SideBarLogo";
|
||||
import {SideBarFooterCredit} from "@/components/wrappers/dashboard/sideBar/SideBarFooterCredit/SideBarFooterCredit";
|
||||
import {LoggedInButton} from "@/components/wrappers/dashboard/loggedInButton/LoggedInButton";
|
||||
import {Layers, ChartArea, Settings, ShieldHalf} from "lucide-react";
|
||||
import {authClient} from "@/lib/auth/auth-client";
|
||||
import {SidebarContentA} from "./sidebar-content";
|
||||
import {getActiveMember, getOrganization} from "@/lib/auth/auth";
|
||||
import {notFound} from "next/navigation";
|
||||
|
||||
export async function AppSidebar() {
|
||||
/*const member = await getActiveMember();
|
||||
const member = await getActiveMember();
|
||||
|
||||
console.log("member", member);
|
||||
|
||||
@@ -27,31 +29,33 @@ export async function AppSidebar() {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
const organization = await getOrganization(member.organizationId);
|
||||
const organization = await getOrganization({organizationId: member.organizationId});
|
||||
|
||||
//todo: à revoir
|
||||
|
||||
console.log("memebrer", member);
|
||||
console.log("aoaoaoaoaoa", organization);*/
|
||||
console.log("membrer", member);
|
||||
console.log("aoaoaoaoaoa", organization);
|
||||
|
||||
return (
|
||||
<Sidebar collapsible="icon">
|
||||
<SidebarHeader>
|
||||
<SideBarLogo />
|
||||
<SideBarLogo/>
|
||||
<SM>
|
||||
<SidebarMenuItem>
|
||||
<OrganizationCombobox />
|
||||
<OrganizationCombobox/>
|
||||
</SidebarMenuItem>
|
||||
</SM>
|
||||
</SidebarHeader>
|
||||
<SidebarContentA />
|
||||
<SidebarContent>
|
||||
<SidebarContentA/>
|
||||
</SidebarContent>
|
||||
<SidebarFooter>
|
||||
<SM>
|
||||
<SidebarMenuItem>
|
||||
<LoggedInButton />
|
||||
<LoggedInButton/>
|
||||
</SidebarMenuItem>
|
||||
</SM>
|
||||
<SideBarFooterCredit />
|
||||
<SideBarFooterCredit/>
|
||||
</SidebarFooter>
|
||||
</Sidebar>
|
||||
);
|
||||
|
||||
@@ -7,10 +7,9 @@ import { SidebarItem, SidebarMenu } from "./SideBarMenu/SideBarMenu";
|
||||
export const SidebarContentA = () => {
|
||||
const { data: activeOrganization } = authClient.useActiveOrganization();
|
||||
const { data: organizations } = authClient.useListOrganizations();
|
||||
|
||||
const { data: session } = useSession();
|
||||
const member = authClient.useActiveMember(); // Moved here — always called
|
||||
|
||||
console.log("sesssssion", session);
|
||||
|
||||
const appItems: SidebarItem[] = [
|
||||
{
|
||||
@@ -31,19 +30,15 @@ export const SidebarContentA = () => {
|
||||
},
|
||||
];
|
||||
|
||||
if (activeOrganization) {
|
||||
const member = authClient.useActiveMember();
|
||||
|
||||
if (member && member.data && (member.data.role === "admin" || member.data.role === "owner")) {
|
||||
appItems.push({
|
||||
type: "list",
|
||||
content: {
|
||||
title: "Settings",
|
||||
url: "settings",
|
||||
icon: <Settings />,
|
||||
},
|
||||
});
|
||||
}
|
||||
if (activeOrganization && member?.data?.role === "admin" || member?.data?.role === "owner") {
|
||||
appItems.push({
|
||||
type: "list",
|
||||
content: {
|
||||
title: "Settings",
|
||||
url: "settings",
|
||||
icon: <Settings />,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const adminItems: SidebarItem[] = [
|
||||
@@ -67,22 +62,13 @@ export const SidebarContentA = () => {
|
||||
|
||||
return (
|
||||
activeOrganization && (
|
||||
<SidebarContent>
|
||||
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>Application</SidebarGroupLabel>
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu items={appItems} baseUrl={`/dashboard/${activeOrganization.slug}`} />
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
{/*(user.role === "superadmin" || user.role === "admin") && (
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>Administration</SidebarGroupLabel>
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu items={adminItems} baseUrl={`/dashboard/${organization.slug}`} />
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
)*/}
|
||||
</SidebarContent>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
-15
@@ -5,10 +5,6 @@ import packageJson from "../package.json" with { type: "json" };
|
||||
const { version } = packageJson;
|
||||
|
||||
export const env = createEnv({
|
||||
/*
|
||||
* Serverside Environment variables, not available on the client.
|
||||
* Will throw if you access these variables on the client.
|
||||
*/
|
||||
server: {
|
||||
NODE_ENV: z.enum(["development", "production"]).optional(),
|
||||
DATABASE_URL: z.string().url().optional(),
|
||||
@@ -36,23 +32,12 @@ export const env = createEnv({
|
||||
|
||||
STORAGE_TYPE: z.string().optional(),
|
||||
},
|
||||
/*
|
||||
* Environment variables available on the client (and server).
|
||||
*
|
||||
* 💡 You'll get type errors if these are not prefixed with NEXT_PUBLIC_.
|
||||
*/
|
||||
client: {
|
||||
NEXT_PUBLIC_PROJECT_NAME: z.string().optional(),
|
||||
NEXT_PUBLIC_PROJECT_DESCRIPTION: z.string().optional(),
|
||||
NEXT_PUBLIC_PROJECT_URL: z.string(),
|
||||
NEXT_PUBLIC_PROJECT_VERSION: z.string(),
|
||||
},
|
||||
/*
|
||||
* Due to how Next.js bundles environment variables on Edge and Client,
|
||||
* we need to manually destructure them to make sure all are included in bundle.
|
||||
*
|
||||
* 💡 You'll get type errors if not all variables from `server` & `client` are included here.
|
||||
*/
|
||||
runtimeEnv: {
|
||||
NEXT_PUBLIC_PROJECT_NAME: process.env.NEXT_PUBLIC_PROJECT_NAME,
|
||||
NEXT_PUBLIC_PROJECT_DESCRIPTION: process.env.NEXT_PUBLIC_PROJECT_DESCRIPTION,
|
||||
|
||||
+35
-34
@@ -1,13 +1,13 @@
|
||||
import { betterAuth } from "better-auth";
|
||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||
import { db } from "@/db";
|
||||
import { env } from "@/env.mjs";
|
||||
import { nextCookies } from "better-auth/next-js";
|
||||
import { admin as adminPlugin, openAPI, organization } from "better-auth/plugins";
|
||||
import { ac, admin, user, pending, superadmin, orgOwner, orgAdmin, orgMember } from "@/lib/auth/permissions";
|
||||
import {betterAuth} from "better-auth";
|
||||
import {drizzleAdapter} from "better-auth/adapters/drizzle";
|
||||
import {db} from "@/db";
|
||||
import {env} from "@/env.mjs";
|
||||
import {nextCookies} from "better-auth/next-js";
|
||||
import {admin as adminPlugin, openAPI, organization} from "better-auth/plugins";
|
||||
import {ac, admin, orgAdmin, orgMember, orgOwner, pending, superadmin, user} from "@/lib/auth/permissions";
|
||||
|
||||
import { headers } from "next/headers";
|
||||
import { count, eq } from "drizzle-orm";
|
||||
import {headers} from "next/headers";
|
||||
import {count, eq} from "drizzle-orm";
|
||||
import * as drizzleUser from "@/db/schema/01_user";
|
||||
import * as drizzleOrganization from "@/db/schema/02_organization";
|
||||
|
||||
@@ -140,7 +140,7 @@ export const signInUser = async (email: string, password: string) => {
|
||||
};*/
|
||||
|
||||
export const createUser = async (name: string, email: string, password: string, role: "user" | "pending" | "admin" | "superadmin" = "pending") => {
|
||||
const user = await auth.api.createUser({
|
||||
return await auth.api.createUser({
|
||||
headers: await headers(),
|
||||
body: {
|
||||
name,
|
||||
@@ -149,24 +149,18 @@ export const createUser = async (name: string, email: string, password: string,
|
||||
role,
|
||||
},
|
||||
});
|
||||
|
||||
return user;
|
||||
};
|
||||
|
||||
export const getSessions = async () => {
|
||||
const sessions = await auth.api.listSessions({
|
||||
return await auth.api.listSessions({
|
||||
headers: await headers(),
|
||||
});
|
||||
|
||||
return sessions;
|
||||
};
|
||||
|
||||
export const getSession = async () => {
|
||||
const session = await auth.api.getSession({
|
||||
return await auth.api.getSession({
|
||||
headers: await headers(),
|
||||
});
|
||||
|
||||
return session;
|
||||
};
|
||||
|
||||
export const revokeSession = async (e: string) => {
|
||||
@@ -182,11 +176,9 @@ export const revokeSession = async (e: string) => {
|
||||
};
|
||||
|
||||
export const getAccounts = async () => {
|
||||
const sessions = await auth.api.listUserAccounts({
|
||||
return await auth.api.listUserAccounts({
|
||||
headers: await headers(),
|
||||
});
|
||||
|
||||
return sessions;
|
||||
};
|
||||
|
||||
export const unlinkAccount = async (provider: string, account: string) => {
|
||||
@@ -203,26 +195,35 @@ export const unlinkAccount = async (provider: string, account: string) => {
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
export const getOrganization = async (organizationSlug?: string) => {
|
||||
try {
|
||||
const organization = await auth.api.getFullOrganization({
|
||||
headers: await headers(),
|
||||
query: {
|
||||
organizationSlug,
|
||||
},
|
||||
});
|
||||
export const getOrganization = async ({
|
||||
organizationId,
|
||||
organizationSlug,
|
||||
}: {
|
||||
organizationId?: string;
|
||||
organizationSlug?: string;
|
||||
}) => {
|
||||
const query = organizationId
|
||||
? { organizationId }
|
||||
: { organizationSlug };
|
||||
|
||||
return organization;
|
||||
} catch (e) {}
|
||||
console.log(query);
|
||||
|
||||
try {
|
||||
return await auth.api.getFullOrganization({
|
||||
headers: await headers(),
|
||||
query,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const listOrganizations = async () => {
|
||||
try {
|
||||
const organizations = await auth.api.listOrganizations({
|
||||
return await auth.api.listOrganizations({
|
||||
headers: await headers(),
|
||||
});
|
||||
|
||||
return organizations;
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user