mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Working on implementation of alert policies. Some refactoring in user profile and patching a bug in status endpoint api.
This commit is contained in:
+7
-12
@@ -6,22 +6,17 @@ import {toast} from "sonner";
|
||||
import {useRouter} from "next/navigation";
|
||||
import {unlinkUserProviderAction} from "@/components/wrappers/dashboard/profile/user-form/user-form.action";
|
||||
import {providerSwitch} from "@/components/wrappers/common/provider-switch";
|
||||
import {Account} from "better-auth";
|
||||
|
||||
export const accountsColumns: ColumnDef<{
|
||||
id: string;
|
||||
provider: string;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
accountId: string;
|
||||
scopes: string[];
|
||||
}>[] = [
|
||||
|
||||
export const accountsColumns: ColumnDef<Account>[] = [
|
||||
{
|
||||
id: "provider",
|
||||
header: "Provider",
|
||||
cell: ({row}) => {
|
||||
return (
|
||||
<div>
|
||||
{providerSwitch(row.original.provider)}
|
||||
{providerSwitch(row.original.providerId)}
|
||||
</div>
|
||||
|
||||
)
|
||||
@@ -36,7 +31,7 @@ export const accountsColumns: ColumnDef<{
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
if (row.original.provider === "credential") {
|
||||
if (row.original.providerId === "credential") {
|
||||
toast.error(`This provider cannot be unlinked.`);
|
||||
router.refresh();
|
||||
return;
|
||||
@@ -49,7 +44,7 @@ export const accountsColumns: ColumnDef<{
|
||||
}
|
||||
|
||||
const status = await unlinkUserProviderAction({
|
||||
provider: row.original.provider,
|
||||
provider: row.original.providerId,
|
||||
account: row.original.accountId,
|
||||
});
|
||||
|
||||
@@ -66,7 +61,7 @@ export const accountsColumns: ColumnDef<{
|
||||
<div className="flex items-center gap-2">
|
||||
<ButtonWithLoading
|
||||
variant="outline"
|
||||
disabled={row.original.provider === "credential" || table.getRowModel().rows.length <= 1}
|
||||
disabled={row.original.providerId === "credential" || table.getRowModel().rows.length <= 1}
|
||||
icon={<Unlink color="red" size={15}/>}
|
||||
onClick={async () => {
|
||||
await mutation.mutateAsync();
|
||||
|
||||
@@ -68,13 +68,13 @@ export const usersColumnsAdmin: ColumnDef<UserWithAccounts>[] = [
|
||||
},
|
||||
{
|
||||
accessorKey: "accounts",
|
||||
header: "Provider ID",
|
||||
header: "Provider(s)",
|
||||
cell: ({row}) => {
|
||||
return (
|
||||
<div>
|
||||
<div className="flex flex-row items-center gap-x-2">
|
||||
{row.original.accounts.map((item) => (
|
||||
<div key={item.id}>
|
||||
{providerSwitch(item.providerId)}
|
||||
{providerSwitch(item.providerId, true)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -93,9 +93,11 @@ export const usersColumnsAdmin: ColumnDef<UserWithAccounts>[] = [
|
||||
id: "actions",
|
||||
cell: ({row}) => {
|
||||
const router = useRouter();
|
||||
const {data: session, isPending} = useSession();
|
||||
const {data: session, isPending, error} = useSession();
|
||||
const isSuperAdmin = session?.user.role == "superadmin";
|
||||
|
||||
if (isPending || error) return null;
|
||||
|
||||
return (
|
||||
<ButtonDeleteUser
|
||||
disabled={!isSuperAdmin || !session || session?.user.email === row.original.email}
|
||||
|
||||
+23
-16
@@ -1,33 +1,34 @@
|
||||
import { ButtonWithLoading } from "@/components/wrappers/common/button/button-with-loading";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { Session } from "better-auth";
|
||||
import { Unlink } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { useRouter } from "next/navigation";
|
||||
import {ButtonWithLoading} from "@/components/wrappers/common/button/button-with-loading";
|
||||
import {useMutation} from "@tanstack/react-query";
|
||||
import {ColumnDef} from "@tanstack/react-table";
|
||||
import {Session} from "better-auth";
|
||||
import {Unlink} from "lucide-react";
|
||||
import {toast} from "sonner";
|
||||
import {useRouter} from "next/navigation";
|
||||
import detectOSWithUA from "@/utils/os-parser";
|
||||
import { Icon } from "@iconify/react";
|
||||
import { authClient } from "@/lib/auth/auth-client";
|
||||
import { timeAgo } from "@/utils/date-formatting";
|
||||
import {Icon} from "@iconify/react";
|
||||
import {authClient} from "@/lib/auth/auth-client";
|
||||
import {timeAgo} from "@/utils/date-formatting";
|
||||
import {deleteUserSessionAction} from "@/components/wrappers/dashboard/profile/user-form/user-form.action";
|
||||
|
||||
export const sessionsColumns: ColumnDef<Session>[] = [
|
||||
{
|
||||
accessorKey: "expiresAt",
|
||||
header: "Expires At",
|
||||
cell: ({ row }) => {
|
||||
cell: ({row}) => {
|
||||
return timeAgo(row.original.expiresAt);
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "device",
|
||||
header: "Device",
|
||||
cell: ({ row }) => {
|
||||
cell: ({row}) => {
|
||||
const os = detectOSWithUA(row.original.userAgent!);
|
||||
|
||||
return (
|
||||
<div className="flex flex-row gap-x-2 items-center pt-4 pb-4">
|
||||
{os.icon && <Icon icon={`logos:${os.icon.name}`} height={os.icon.size.height} width={os.icon.size.width} />}
|
||||
{os.icon &&
|
||||
<Icon icon={`logos:${os.icon.name}`} height={os.icon.size.height} width={os.icon.size.width}/>}
|
||||
{os.showText && <span>{os.name}</span>}
|
||||
</div>
|
||||
);
|
||||
@@ -40,10 +41,11 @@ export const sessionsColumns: ColumnDef<Session>[] = [
|
||||
{
|
||||
header: "Action",
|
||||
id: "actions",
|
||||
cell: ({ row }) => {
|
||||
cell: ({row}) => {
|
||||
const router = useRouter();
|
||||
|
||||
const { data: session } = authClient.useSession();
|
||||
const {data: session, isPending, error} = authClient.useSession();
|
||||
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: async () => {
|
||||
@@ -64,12 +66,17 @@ export const sessionsColumns: ColumnDef<Session>[] = [
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
if (isPending || error) return null;
|
||||
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<ButtonWithLoading
|
||||
isPending={mutation.isPending}
|
||||
variant="outline"
|
||||
disabled={session?.session.id === row.original.id}
|
||||
icon={<Unlink color="red" size={15} />}
|
||||
icon={<Unlink color="red" size={15}/>}
|
||||
onClick={async () => {
|
||||
await mutation.mutateAsync();
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user