Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 16x 16x 16x 16x 16x 16x 16x 2x 2x 2x 1x 1x 1x 2x | /*
* Copyright 2022 Harness Inc. All rights reserved.
* Use of this source code is governed by the PolyForm Shield 1.0.0 license
* that can be found in the licenses directory at the root of this repository, also available at
* https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt.
*/
import React from 'react'
import { useHistory, useParams } from 'react-router-dom'
import { UseConfirmationDialogReturn, useToaster } from '@wings-software/uicore'
import { Intent } from '@harness/design-system'
import { Target, useDeleteTarget } from 'services/cf'
import { String, useStrings } from 'framework/strings'
import { useConfirmAction } from '@common/hooks'
import { getErrorMessage } from '@cf/utils/CFUtils'
import routes from '@common/RouteDefinitions'
import useActiveEnvironment from '@cf/hooks/useActiveEnvironment'
const useDeleteTargetDialog = (target?: Target): UseConfirmationDialogReturn['openDialog'] => {
const { accountId: accountIdentifier, orgIdentifier, projectIdentifier } = useParams<Record<string, string>>()
const { getString } = useStrings()
const { showSuccess, showError, clear } = useToaster()
const history = useHistory()
const { withActiveEnvironment } = useActiveEnvironment()
const { mutate: deleteTarget } = useDeleteTarget({
queryParams: {
projectIdentifier,
orgIdentifier,
accountIdentifier,
environmentIdentifier: target?.environment as string
}
})
return useConfirmAction({
title: getString('cf.targets.deleteTarget'),
intent: Intent.DANGER,
confirmText: getString('delete'),
message: <String stringID="cf.targets.deleteTargetMessage" vars={{ name: target?.name }} useRichText />,
action: async () => {
clear()
try {
await deleteTarget(target?.identifier as string)
showSuccess(getString('cf.messages.targetDeleted'))
history.push(
withActiveEnvironment(
routes.toCFTargets({
projectIdentifier,
orgIdentifier,
accountId: accountIdentifier
})
)
)
} catch (e) {
showError(getErrorMessage(e), 0, 'cf.delete.target.error')
}
}
})
}
export default useDeleteTargetDialog
|