-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Questionnaire delete confirmation (#1303)
Closes #1276 Adding an explanation of what happens if the questionnaire is deleted and forcing the user to write the questionnaire's name to deletion. Note: the input is case-sensitive to the name of the questionnaire. Before: ![delete-questionnaire-dialog-b4](https://github.com/konveyor/tackle2-ui/assets/67270715/ddc12fa3-431a-40a1-af67-61f6fbb41172) After: ![delete-questionnaire-dialog2](https://github.com/konveyor/tackle2-ui/assets/67270715/ef8de76d-ee19-456f-990b-c8a9f4f89600) ![delete-questionnaire-dialog](https://github.com/konveyor/tackle2-ui/assets/67270715/57819a1e-6924-4d1b-aab0-f945a92672c3) --------- Signed-off-by: Aviv Turgeman <aturgema@redhat.com>
- Loading branch information
Showing
4 changed files
with
123 additions
and
18 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
8 changes: 8 additions & 0 deletions
8
client/src/app/components/ConfirmDeleteCatalog/ConfirmDeleteCatalog.css
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,8 @@ | ||
.confirm-deletion { | ||
margin-top: var(--pf-v5-global--spacer--xl); | ||
} | ||
|
||
.confirm-deletion-input { | ||
margin-top: var(--pf-v5-global--spacer--sm); | ||
margin-bottom: var(--pf-v5-global--spacer--sm); | ||
} |
102 changes: 102 additions & 0 deletions
102
client/src/app/components/ConfirmDeleteCatalog/ConfirmDeleteCatalog.tsx
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,102 @@ | ||
import React, { FC, useState } from "react"; | ||
import { useTranslation, Trans } from "react-i18next"; | ||
import { | ||
ModalProps, | ||
Button, | ||
ButtonVariant, | ||
Modal, | ||
ModalVariant, | ||
Text, | ||
TextInput, | ||
} from "@patternfly/react-core"; | ||
|
||
import "./ConfirmDeleteCatalog.css"; | ||
|
||
type ConfirmDeleteDialogProps = { | ||
cancelBtnLabel?: string; | ||
deleteBtnLabel?: string; | ||
deleteObjectMessage: string; | ||
isOpen: boolean; | ||
nameToDelete?: string; | ||
onClose: () => void; | ||
onConfirmDelete: () => void; | ||
titleWhat: string; | ||
titleIconVariant?: ModalProps["titleIconVariant"]; | ||
}; | ||
|
||
const ConfirmDeleteDialog: FC<ConfirmDeleteDialogProps> = ({ | ||
cancelBtnLabel, | ||
deleteBtnLabel, | ||
deleteObjectMessage, | ||
isOpen, | ||
nameToDelete, | ||
onClose, | ||
onConfirmDelete, | ||
titleWhat, | ||
titleIconVariant = "warning", | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
const [nameToDeleteInput, setNameToDeleteInput] = useState<string>(""); | ||
|
||
const isDisabled = nameToDeleteInput !== nameToDelete; | ||
|
||
const handleClose = () => { | ||
setNameToDeleteInput(""); | ||
onClose(); | ||
}; | ||
|
||
const confirmBtn = ( | ||
<Button | ||
id="confirm-delete-dialog-button" | ||
key="confirm" | ||
aria-label="confirm" | ||
variant={ButtonVariant.danger} | ||
isDisabled={isDisabled} | ||
onClick={isDisabled ? undefined : onConfirmDelete} | ||
> | ||
{deleteBtnLabel ?? t("actions.delete")} | ||
</Button> | ||
); | ||
|
||
const cancelBtn = ( | ||
<Button | ||
key="cancel" | ||
id="cancel-delete-button" | ||
aria-label="cancel" | ||
variant={ButtonVariant.link} | ||
onClick={handleClose} | ||
> | ||
{cancelBtnLabel ?? t("actions.cancel")} | ||
</Button> | ||
); | ||
return ( | ||
<Modal | ||
id="confirm-delete-dialog" | ||
variant={ModalVariant.small} | ||
titleIconVariant={titleIconVariant} | ||
isOpen={isOpen} | ||
onClose={handleClose} | ||
aria-label="Confirm delete dialog" | ||
actions={[confirmBtn, cancelBtn]} | ||
title={t("dialog.title.delete", { | ||
what: titleWhat, | ||
})} | ||
> | ||
<Text component="p">{deleteObjectMessage}</Text> | ||
<Text component="p">{t("dialog.message.delete")}</Text> | ||
<Text component="p" className="confirm-deletion"> | ||
<Trans i18nKey="dialog.message.confirmDeletion"> | ||
Confirm deletion by typing <strong>{{ nameToDelete }}</strong> below: | ||
</Trans> | ||
</Text> | ||
<TextInput | ||
className="confirm-deletion-input" | ||
value={nameToDeleteInput} | ||
onChange={(_, value) => setNameToDeleteInput(value)} | ||
/> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default ConfirmDeleteDialog; |
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