@@ -11,8 +11,8 @@ import { useNavigate } from 'react-router-dom'
1111import { type Instance , instanceCan , useApiMutation } from '@oxide/api'
1212import type { MakeActions } from '@oxide/table'
1313
14- import { useToast } from 'app/hooks'
1514import { confirmDelete } from 'app/stores/confirm-delete'
15+ import { addToast } from 'app/stores/toast'
1616import { pb } from 'app/util/path-builder'
1717
1818import { fancifyStates } from './instance/tabs/common'
@@ -31,7 +31,6 @@ export const useMakeInstanceActions = (
3131 options : Options = { }
3232) : MakeActions < Instance > => {
3333 const navigate = useNavigate ( )
34- const addToast = useToast ( )
3534
3635 // if you also pass onSuccess to mutate(), this one is not overridden — this
3736 // one runs first, then the one passed to mutate()
@@ -43,15 +42,20 @@ export const useMakeInstanceActions = (
4342
4443 return useCallback (
4544 ( instance ) => {
46- const successToast = ( title : string ) => addToast ( { title } )
4745 const instanceSelector = { ...projectSelector , instance : instance . name }
4846 const instanceParams = { path : { instance : instance . name } , query : projectSelector }
4947 return [
5048 {
5149 label : 'Start' ,
5250 onActivate ( ) {
5351 startInstance . mutate ( instanceParams , {
54- onSuccess : ( ) => successToast ( `Starting instance '${ instance . name } '` ) ,
52+ onSuccess : ( ) => addToast ( { title : `Starting instance '${ instance . name } '` } ) ,
53+ onError : ( error ) =>
54+ addToast ( {
55+ variant : 'error' ,
56+ title : `Error starting instance '${ instance . name } '` ,
57+ content : error . message ,
58+ } ) ,
5559 } )
5660 } ,
5761 disabled : ! instanceCan . start ( instance ) && (
@@ -62,7 +66,13 @@ export const useMakeInstanceActions = (
6266 label : 'Stop' ,
6367 onActivate ( ) {
6468 stopInstance . mutate ( instanceParams , {
65- onSuccess : ( ) => successToast ( `Stopping instance '${ instance . name } '` ) ,
69+ onSuccess : ( ) => addToast ( { title : `Stopping instance '${ instance . name } '` } ) ,
70+ onError : ( error ) =>
71+ addToast ( {
72+ variant : 'error' ,
73+ title : `Error stopping instance '${ instance . name } '` ,
74+ content : error . message ,
75+ } ) ,
6676 } )
6777 } ,
6878 disabled : ! instanceCan . stop ( instance ) && (
@@ -73,7 +83,13 @@ export const useMakeInstanceActions = (
7383 label : 'Reboot' ,
7484 onActivate ( ) {
7585 rebootInstance . mutate ( instanceParams , {
76- onSuccess : ( ) => successToast ( `Rebooting instance '${ instance . name } '` ) ,
86+ onSuccess : ( ) => addToast ( { title : `Rebooting instance '${ instance . name } '` } ) ,
87+ onError : ( error ) =>
88+ addToast ( {
89+ variant : 'error' ,
90+ title : `Error rebooting instance '${ instance . name } '` ,
91+ content : error . message ,
92+ } ) ,
7793 } )
7894 } ,
7995 disabled : ! instanceCan . reboot ( instance ) && (
@@ -93,8 +109,14 @@ export const useMakeInstanceActions = (
93109 deleteInstance . mutateAsync ( instanceParams , {
94110 onSuccess : ( ) => {
95111 options . onDelete ?.( )
96- successToast ( `Deleting instance '${ instance . name } '` )
112+ addToast ( { title : `Deleting instance '${ instance . name } '` } )
97113 } ,
114+ onError : ( error ) =>
115+ addToast ( {
116+ variant : 'error' ,
117+ title : `Error deleting instance '${ instance . name } '` ,
118+ content : error . message ,
119+ } ) ,
98120 } ) ,
99121 label : instance . name ,
100122 } ) ,
@@ -113,7 +135,6 @@ export const useMakeInstanceActions = (
113135 rebootInstance ,
114136 startInstance ,
115137 stopInstance ,
116- addToast ,
117138 ]
118139 )
119140}
0 commit comments