Skip to content

fix: update ErrorDialog logic and tests #10111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: make input colors sync with confirmation text state
  • Loading branch information
Parkreiner committed Oct 6, 2023
commit 3fbc94dcb58d55ce9d5f9d1c16404e8226b12d7a
17 changes: 10 additions & 7 deletions site/src/components/Dialogs/DeleteDialog/DeleteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ export const DeleteDialog: FC<PropsWithChildren<DeleteDialogProps>> = ({
const [confirmationText, setConfirmationText] = useState("");
const [isFocused, setIsFocused] = useState(false);

const onSubmit = (e: FormEvent) => {
e.preventDefault();
const deletionConfirmed = name === confirmationText;
const onSubmit = (event: FormEvent) => {
event.preventDefault();
if (deletionConfirmed) {
onConfirm();
}
};

const confirmationId = `${hookId}-${DeleteDialog.name}-confirm`;
const deletionConfirmed = name === confirmationText;
const hasError =
!isFocused && !deletionConfirmed && confirmationText.length > 0;
const hasError = !deletionConfirmed && confirmationText.length > 0;
const displayErrorMessage = hasError && !isFocused;
const color = hasError ? "error" : "primary";

return (
<ConfirmDialog
Expand Down Expand Up @@ -85,11 +86,13 @@ export const DeleteDialog: FC<PropsWithChildren<DeleteDialogProps>> = ({
onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
label={`Name of the ${entity} to delete`}
error={hasError}
color={color}
error={displayErrorMessage}
helperText={
hasError &&
displayErrorMessage &&
`${confirmationText} does not match the name of this ${entity}`
}
InputProps={{ color }}
inputProps={{
["data-testid"]: "delete-dialog-name-confirmation",
}}
Expand Down