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:
@@ -24,7 +24,7 @@ export const usersColumnsAdmin: ColumnDef<User>[] = [
|
||||
mutationFn: () => updateUserAction({id: row.original.id, data: {role: role}}),
|
||||
onSuccess: () => {
|
||||
toast.success(`User updated successfully.`);
|
||||
router.refresh()
|
||||
// router.refresh()
|
||||
|
||||
},
|
||||
onError: () => {
|
||||
|
||||
+16
-13
@@ -11,6 +11,9 @@ import {useState} from "react";
|
||||
import {Trash2} from "lucide-react";
|
||||
import {deleteUserAction} from "@/components/wrappers/dashboard/profile/ButtonDeleteAccount/delete-account.action";
|
||||
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>[] = [
|
||||
{
|
||||
@@ -20,24 +23,24 @@ export const usersColumns: ColumnDef<UserOrganization>[] = [
|
||||
const router = useRouter();
|
||||
const [role, setRole] = useState<string>(row.getValue("role"))
|
||||
|
||||
// const updateMutation = useMutation({
|
||||
// mutationFn: () => updateUserAction({id: row.original.id, data: {role: role}}),
|
||||
// onSuccess: () => {
|
||||
// toast.success(`User updated successfully.`);
|
||||
// router.refresh()
|
||||
//
|
||||
// },
|
||||
// onError: () => {
|
||||
// toast.error(`An error occurred while updating user information.`);
|
||||
// },
|
||||
// });
|
||||
const updateMutation = useMutation({
|
||||
mutationFn: () => updateUserOrganizationAction({id: row.original.id, role: role}),
|
||||
onSuccess: () => {
|
||||
toast.success(`User updated successfully.`);
|
||||
// router.refresh()
|
||||
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(`An error occurred while updating user information.`);
|
||||
},
|
||||
});
|
||||
|
||||
const handleUpdateRole = async () => {
|
||||
const nextRole = role === "admin" ? "member"
|
||||
: role === "member" ? "user"
|
||||
: role === "member" ? "admin"
|
||||
: "admin";
|
||||
setRole(nextRole);
|
||||
// await updateMutation.mutateAsync()
|
||||
await updateMutation.mutateAsync()
|
||||
};
|
||||
|
||||
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