wrapping some agent components.

This commit is contained in:
killian-larcher
2024-11-11 18:50:42 +01:00
parent 49e069c849
commit 09529fb701
23 changed files with 338 additions and 156 deletions
@@ -0,0 +1,32 @@
"use client"
import {useMutation} from "@tanstack/react-query";
import {useRouter} from "next/navigation";
import {signOutAction} from "@/features/auth/auth.action";
import {ButtonWithConfirm} from "@/components/wrappers/Button/ButtonWithConfirm/ButtonWithConfirm";
import {deleteUserAction} from "@/components/wrappers/Dashboard/Profile/ButtonDeleteAccount/delete-account.action";
import {Trash2} from "lucide-react";
export type ButtonDeleteAccountProps = {}
export const ButtonDeleteAccount = (props: ButtonDeleteAccountProps) => {
const mutation = useMutation({
mutationFn: () => deleteUserAction(""),
onSuccess: async () => {
await signOutAction();
},
})
return (
<ButtonWithConfirm
text={"Delete my account"}
onClick={() => {
mutation.mutate()
}}
variant={"destructive"}
isPending={mutation.isPending}
className="gap-2"
icon={<Trash2/>}
/>
)
}
@@ -0,0 +1,42 @@
"use server"
import {userAction} from "@/safe-actions";
import {prisma} from "@/prisma";
import {z} from "zod";
import {v4 as uuidv4} from "uuid";
export const deleteUserAction = userAction
.schema(z.string())
.action(async ({parsedInput, ctx}) => {
const uuid = uuidv4()
const user = await prisma.user.update({
where: {
id: ctx.user.id,
},
data: {
email: `${uuid}@portabase.com`,
name: `${uuid}`,
}
})
const account = await prisma.account.findFirst({
where: {
userId: ctx.user.id,
}
})
if(account){
await prisma.account.delete({
where: {
id: account.id
}
})
}
return {
data: user,
}
});