@@ -6,7 +6,10 @@ import { useTranslations } from "next-intl";
66import { FC , useState } from "react" ;
77import toast from "react-hot-toast" ;
88
9- import { getBotTokenAction } from "@/app/(main)/accounts/settings/actions" ;
9+ import {
10+ getBotTokenAction ,
11+ impersonateBotAction ,
12+ } from "@/app/(main)/accounts/settings/actions" ;
1013import Button from "@/components/ui/button" ;
1114import { CurrentBot } from "@/types/users" ;
1215import { extractError } from "@/utils/core/errors" ;
@@ -42,6 +45,18 @@ const BotControls: FC<Props> = ({ bot }) => {
4245 }
4346 } ;
4447
48+ const [ isImpersonating , setIsImpersonating ] = useState ( false ) ;
49+
50+ const handleImpersonate = async ( ) => {
51+ setIsImpersonating ( true ) ;
52+ const response = await impersonateBotAction ( id ) ;
53+
54+ if ( response ?. errors ) {
55+ setIsImpersonating ( false ) ;
56+ toast . error ( extractError ( response . errors ) ) ;
57+ }
58+ } ;
59+
4560 return (
4661 < div className = "flex flex-col gap-2" >
4762 < div className = "flex flex-wrap gap-2" >
@@ -55,6 +70,16 @@ const BotControls: FC<Props> = ({ bot }) => {
5570 < FontAwesomeIcon icon = { faSpinner } spin className = "ml-1" />
5671 ) }
5772 </ Button >
73+ < Button
74+ size = "xs"
75+ onClick = { handleImpersonate }
76+ disabled = { isImpersonating }
77+ >
78+ { t ( "switchToBotAccount" ) }
79+ { isImpersonating && (
80+ < FontAwesomeIcon icon = { faSpinner } spin className = "ml-1" />
81+ ) }
82+ </ Button >
5883 </ div >
5984
6085 { apiToken && (
0 commit comments