-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pci-instances): add start & stop actions
ref: TAPC-2149 TAPC-2150 Signed-off-by: Frédéric Vilcot <[email protected]>
- Loading branch information
1 parent
a63e560
commit 2590465
Showing
24 changed files
with
542 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/manager/apps/pci-instances/public/translations/actions/Messages_fr_FR.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"pci_instances_actions_delete_instance_title": "Supprimer une instance", | ||
"pci_instances_actions_delete_instance_confirmation_message": "Êtes-vous sûr de vouloir supprimer l'instance {{ name }} ?", | ||
"pci_instances_actions_delete_instance_error_message": "Une erreur est survenue lors de la suppression de l'instance {{ name }}.", | ||
"pci_instances_actions_delete_instance_success_message": "L'instance {{ name }} a bien été supprimée.", | ||
"pci_instances_actions_stop_instance_title": "Arrêt de votre instance", | ||
"pci_instances_actions_stop_instance_confirmation_message": "Vous allez arrêter votre instance {{ name }}. Les ressources dédiées à votre instance Public Cloud sont toujours réservées (adresse IP incluse). Vous pouvez redémarrer votre instance à tout moment. Dans l'intervalle, vous êtes toujours facturé au même prix pour votre instance.", | ||
"pci_instances_actions_stop_instance_error_message": "Une erreur est survenue lors de l'arrêt de l'instance {{ name }}.", | ||
"pci_instances_actions_stop_instance_success_message": "L'instance {{ name }} a été arrêtée.", | ||
"pci_instances_actions_start_instance_title": "Démarrage de votre instance", | ||
"pci_instances_actions_start_instance_confirmation_message": "Vous allez démarrer votre instance {{ name }}.", | ||
"pci_instances_actions_start_instance_error_message": "Une erreur est survenue lors du démarrage de l'instance {{ name }}.", | ||
"pci_instances_actions_start_instance_success_message": "L'instance {{ name }} a été démarrée.", | ||
"pci_instances_actions_instance_unknown_error_message": "Une erreur est survenue. Notre équipe technique est informée et travaille à résoudre le problème." | ||
} |
6 changes: 0 additions & 6 deletions
6
packages/manager/apps/pci-instances/public/translations/delete/Messages_fr_FR.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/manager/apps/pci-instances/src/data/hooks/instance/action/useInstanceAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useCallback } from 'react'; | ||
import { | ||
deleteInstance, | ||
startInstance, | ||
stopInstance, | ||
} from '@/data/api/instance'; | ||
import { DeepReadonly } from '@/types/utils.type'; | ||
import { instancesQueryKey } from '@/utils'; | ||
import { | ||
TDeleteInstanceDto, | ||
TStopInstanceDto, | ||
TStartInstanceDto, | ||
} from '@/types/instance/api.types'; | ||
|
||
export type TMutationFnType = 'delete' | 'start' | 'stop'; | ||
export type TMutationFnReturnType = | ||
| TDeleteInstanceDto | ||
| TStopInstanceDto | ||
| TStartInstanceDto; | ||
export type TMutationFnVariables = string | null; | ||
|
||
export type TUseInstanceActionCallbacks = DeepReadonly<{ | ||
onSuccess?: (data?: TMutationFnReturnType) => void; | ||
onError?: (error: unknown) => void; | ||
}>; | ||
|
||
export const useInstanceAction = ( | ||
type: TMutationFnType | null, | ||
projectId: string, | ||
{ onError, onSuccess }: TUseInstanceActionCallbacks = {}, | ||
) => { | ||
const mutationKey = instancesQueryKey(projectId, [ | ||
'instance', | ||
...(type !== null ? [type] : []), | ||
]); | ||
const mutationFn = useCallback( | ||
(instanceId: string | null) => { | ||
if (!instanceId) return Promise.reject(); | ||
switch (type) { | ||
case 'delete': | ||
return deleteInstance(projectId, instanceId); | ||
case 'start': | ||
return startInstance(projectId, instanceId); | ||
case 'stop': | ||
return stopInstance(projectId, instanceId); | ||
default: | ||
return Promise.reject(); | ||
} | ||
}, | ||
[projectId, type], | ||
); | ||
|
||
const mutation = useMutation< | ||
TMutationFnReturnType, | ||
unknown, | ||
TMutationFnVariables, | ||
unknown | ||
>({ | ||
mutationKey, | ||
mutationFn, | ||
onError, | ||
onSuccess, | ||
}); | ||
|
||
return { | ||
mutationHandler: mutation.mutate, | ||
...mutation, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.