-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GEN-1613]: delete destination (#1672)
- Loading branch information
1 parent
08eacfe
commit 240730f
Showing
9 changed files
with
81 additions
and
107 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
export * from './useDestinations'; | ||
export * from './useTestConnection'; | ||
export * from './useConnectDestinationForm'; | ||
export * from './useCreateDestination'; | ||
export * from './usePotentialDestinations'; | ||
export * from './useActualDestinations'; | ||
export * from './useUpdateDestination'; | ||
export * from './useDestinationCRUD'; | ||
export * from './useDestinationFormData'; | ||
export * from './useEditDestinationFormHandlers'; | ||
export * from './useDestinationTypes'; |
21 changes: 0 additions & 21 deletions
21
frontend/webapp/hooks/destinations/useCreateDestination.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useDrawerStore } from '@/store'; | ||
import { useNotify } from '../useNotify'; | ||
import { useMutation } from '@apollo/client'; | ||
import type { DestinationInput } from '@/types'; | ||
import { useComputePlatform } from '../compute-platform'; | ||
import { CREATE_DESTINATION, DELETE_DESTINATION, UPDATE_DESTINATION } from '@/graphql/mutations'; | ||
|
||
interface Params { | ||
onSuccess?: () => void; | ||
onError?: () => void; | ||
} | ||
|
||
export const useDestinationCRUD = (params?: Params) => { | ||
const { setSelectedItem: setDrawerItem } = useDrawerStore((store) => store); | ||
const { refetch } = useComputePlatform(); | ||
const notify = useNotify(); | ||
|
||
const notifyUser = (title: string, message: string, type: 'error' | 'success') => { | ||
notify({ title, message, type, target: 'notification', crdType: 'notification' }); | ||
}; | ||
|
||
const handleError = (title: string, message: string) => { | ||
notifyUser(title, message, 'error'); | ||
params?.onError?.(); | ||
}; | ||
|
||
const handleComplete = (title: string, message: string) => { | ||
notifyUser(title, message, 'success'); | ||
setDrawerItem(null); | ||
refetch(); | ||
params?.onSuccess?.(); | ||
}; | ||
|
||
const [createDestination, cState] = useMutation<{ createNewDestination: { id: string } }>(CREATE_DESTINATION, { | ||
onError: (error) => handleError('Create Destination', error.message), | ||
onCompleted: () => handleComplete('Create Destination', 'successfully created'), | ||
}); | ||
const [updateDestination, uState] = useMutation<{ updateDestination: { id: string } }>(UPDATE_DESTINATION, { | ||
onError: (error) => handleError('Update Destination', error.message), | ||
onCompleted: () => handleComplete('Update Destination', 'successfully updated'), | ||
}); | ||
const [deleteDestination, dState] = useMutation<{ deleteDestination: boolean }>(DELETE_DESTINATION, { | ||
onError: (error) => handleError('Delete Destination', error.message), | ||
onCompleted: () => handleComplete('Delete Destination', 'successfully deleted'), | ||
}); | ||
|
||
return { | ||
loading: cState.loading || uState.loading || dState.loading, | ||
createDestination: (destination: DestinationInput) => createDestination({ variables: { destination } }), | ||
updateDestination: (id: string, destination: DestinationInput) => updateDestination({ variables: { id, destination } }), | ||
deleteDestination: (id: string) => deleteDestination({ variables: { id } }), | ||
}; | ||
}; |
32 changes: 0 additions & 32 deletions
32
frontend/webapp/hooks/destinations/useUpdateDestination.ts
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