11'use client'
22
3- import { useAction } from 'next-safe-action/hooks '
3+ import { useMutation } from '@tanstack/react-query '
44import { useState } from 'react'
55import { toast } from 'sonner'
6- import { pauseSandboxAction } from '@/core/server/actions/sandbox-actions '
6+ import { useTRPC } from '@/trpc/client '
77import { AlertPopover } from '@/ui/alert-popover'
88import { Button } from '@/ui/primitives/button'
99import { PausedIcon } from '@/ui/primitives/icons'
@@ -18,26 +18,27 @@ export default function PauseButton({ className }: PauseButtonProps) {
1818 const [ open , setOpen ] = useState ( false )
1919 const { sandboxInfo, refetchSandboxInfo } = useSandboxContext ( )
2020 const { team } = useDashboard ( )
21+ const trpc = useTRPC ( )
2122
2223 const canPause = sandboxInfo ?. state === 'running'
2324
24- const { execute , isExecuting } = useAction ( pauseSandboxAction , {
25- onSuccess : async ( ) => {
26- toast . success ( 'Sandbox paused successfully' )
27- setOpen ( false )
28- refetchSandboxInfo ( )
29- } ,
30- onError : ( { error } ) => {
31- toast . error (
32- error . serverError || 'Failed to pause sandbox. Please try again.'
33- )
34- } ,
35- } )
25+ const { mutate : pause , isPending } = useMutation (
26+ trpc . sandbox . pause . mutationOptions ( {
27+ onSuccess : async ( ) => {
28+ toast . success ( 'Sandbox paused successfully' )
29+ setOpen ( false )
30+ refetchSandboxInfo ( )
31+ } ,
32+ onError : ( ) => {
33+ toast . error ( 'Failed to pause sandbox. Please try again.' )
34+ } ,
35+ } )
36+ )
3637
3738 const handlePause = ( ) => {
3839 if ( ! canPause || ! sandboxInfo ?. sandboxID ) return
3940
40- execute ( { teamSlug : team . slug , sandboxId : sandboxInfo . sandboxID } )
41+ pause ( { teamSlug : team . slug , sandboxId : sandboxInfo . sandboxID } )
4142 }
4243
4344 if ( ! canPause ) return null
@@ -56,8 +57,8 @@ export default function PauseButton({ className }: PauseButtonProps) {
5657 </ Button >
5758 }
5859 confirmProps = { {
59- disabled : isExecuting ,
60- loading : isExecuting ? 'Pausing...' : undefined ,
60+ disabled : isPending ,
61+ loading : isPending ? 'Pausing...' : undefined ,
6162 } }
6263 onConfirm = { handlePause }
6364 onCancel = { ( ) => setOpen ( false ) }
0 commit comments