mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Workspace roles ok.
This commit is contained in:
@@ -12,7 +12,7 @@ export default async function RoutePage(props: PageParams<{
|
|||||||
}>) {
|
}>) {
|
||||||
const {slug: organizationSlug} = await props.params
|
const {slug: organizationSlug} = await props.params
|
||||||
const currentOrganizationSlug = await getCurrentOrganizationSlug()
|
const currentOrganizationSlug = await getCurrentOrganizationSlug()
|
||||||
|
const user = await requiredCurrentUser()
|
||||||
if(currentOrganizationSlug != organizationSlug) {
|
if(currentOrganizationSlug != organizationSlug) {
|
||||||
notFound()
|
notFound()
|
||||||
}
|
}
|
||||||
@@ -24,8 +24,16 @@ export default async function RoutePage(props: PageParams<{
|
|||||||
include:{
|
include:{
|
||||||
users:{
|
users:{
|
||||||
include:{
|
include:{
|
||||||
user:{}
|
user:{
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
user: {
|
||||||
|
id: {
|
||||||
|
not: user.id, // Exclude user with id: 1
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -33,6 +41,7 @@ export default async function RoutePage(props: PageParams<{
|
|||||||
const users = await prisma.user.findMany({
|
const users = await prisma.user.findMany({
|
||||||
where: {
|
where: {
|
||||||
deleted: {not: true},
|
deleted: {not: true},
|
||||||
|
id: {not: user.id}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export const usersColumnsAdmin: ColumnDef<User>[] = [
|
|||||||
mutationFn: () => updateUserAction({id: row.original.id, data: {role: role}}),
|
mutationFn: () => updateUserAction({id: row.original.id, data: {role: role}}),
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success(`User updated successfully.`);
|
toast.success(`User updated successfully.`);
|
||||||
router.refresh()
|
// router.refresh()
|
||||||
|
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: () => {
|
||||||
|
|||||||
+16
-13
@@ -11,6 +11,9 @@ import {useState} from "react";
|
|||||||
import {Trash2} from "lucide-react";
|
import {Trash2} from "lucide-react";
|
||||||
import {deleteUserAction} from "@/components/wrappers/dashboard/profile/ButtonDeleteAccount/delete-account.action";
|
import {deleteUserAction} from "@/components/wrappers/dashboard/profile/ButtonDeleteAccount/delete-account.action";
|
||||||
import {ButtonWithLoading} from "@/components/wrappers/common/button/button-with-loading";
|
import {ButtonWithLoading} from "@/components/wrappers/common/button/button-with-loading";
|
||||||
|
import {
|
||||||
|
updateUserOrganizationAction
|
||||||
|
} from "@/components/wrappers/dashboard/settings/SettingsUsersTab/settings-user-tab.action";
|
||||||
|
|
||||||
export const usersColumns: ColumnDef<UserOrganization>[] = [
|
export const usersColumns: ColumnDef<UserOrganization>[] = [
|
||||||
{
|
{
|
||||||
@@ -20,24 +23,24 @@ export const usersColumns: ColumnDef<UserOrganization>[] = [
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [role, setRole] = useState<string>(row.getValue("role"))
|
const [role, setRole] = useState<string>(row.getValue("role"))
|
||||||
|
|
||||||
// const updateMutation = useMutation({
|
const updateMutation = useMutation({
|
||||||
// mutationFn: () => updateUserAction({id: row.original.id, data: {role: role}}),
|
mutationFn: () => updateUserOrganizationAction({id: row.original.id, role: role}),
|
||||||
// onSuccess: () => {
|
onSuccess: () => {
|
||||||
// toast.success(`User updated successfully.`);
|
toast.success(`User updated successfully.`);
|
||||||
// router.refresh()
|
// router.refresh()
|
||||||
//
|
|
||||||
// },
|
},
|
||||||
// onError: () => {
|
onError: () => {
|
||||||
// toast.error(`An error occurred while updating user information.`);
|
toast.error(`An error occurred while updating user information.`);
|
||||||
// },
|
},
|
||||||
// });
|
});
|
||||||
|
|
||||||
const handleUpdateRole = async () => {
|
const handleUpdateRole = async () => {
|
||||||
const nextRole = role === "admin" ? "member"
|
const nextRole = role === "admin" ? "member"
|
||||||
: role === "member" ? "user"
|
: role === "member" ? "admin"
|
||||||
: "admin";
|
: "admin";
|
||||||
setRole(nextRole);
|
setRole(nextRole);
|
||||||
// await updateMutation.mutateAsync()
|
await updateMutation.mutateAsync()
|
||||||
};
|
};
|
||||||
|
|
||||||
return <Badge
|
return <Badge
|
||||||
|
|||||||
+28
@@ -1,2 +1,30 @@
|
|||||||
|
"use server"
|
||||||
|
import {userAction} from "@/safe-actions";
|
||||||
|
import {z} from "zod";
|
||||||
|
import {prisma} from "@/prisma";
|
||||||
|
|
||||||
|
|
||||||
|
export const updateUserOrganizationAction = userAction
|
||||||
|
.schema(
|
||||||
|
z.object({
|
||||||
|
id: z.string(),
|
||||||
|
role: z.string(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.action(async ({parsedInput, ctx}) => {
|
||||||
|
const updatedUserOrganization = await prisma.userOrganization.update({
|
||||||
|
where: {
|
||||||
|
id: parsedInput.id,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
role: parsedInput.role,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
data: updatedUserOrganization,
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user