mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
refactor(ui/modals): replace bootbox with react solution [EE-4541] (#8010)
This commit is contained in:
parent
392c7f74b8
commit
e66dea44e3
111 changed files with 1330 additions and 1562 deletions
80
app/react/components/modals/confirm.ts
Normal file
80
app/react/components/modals/confirm.ts
Normal file
|
@ -0,0 +1,80 @@
|
|||
import { openDialog, DialogOptions } from './Dialog';
|
||||
import { OnSubmit, ModalType } from './Modal';
|
||||
import { ButtonOptions } from './types';
|
||||
import { buildCancelButton, buildConfirmButton } from './utils';
|
||||
|
||||
export type ConfirmCallback = OnSubmit<boolean>;
|
||||
|
||||
export interface ConfirmOptions
|
||||
extends Omit<DialogOptions<boolean>, 'title' | 'buttons'> {
|
||||
title: string;
|
||||
confirmButton?: ButtonOptions<true>;
|
||||
cancelButtonLabel?: string;
|
||||
}
|
||||
|
||||
export async function openConfirm({
|
||||
confirmButton = buildConfirmButton(),
|
||||
cancelButtonLabel,
|
||||
...options
|
||||
}: ConfirmOptions) {
|
||||
const result = await openDialog({
|
||||
...options,
|
||||
buttons: [buildCancelButton(cancelButtonLabel), confirmButton],
|
||||
});
|
||||
return !!result;
|
||||
}
|
||||
|
||||
export function confirm(options: ConfirmOptions) {
|
||||
return openConfirm(options);
|
||||
}
|
||||
|
||||
export function confirmDestructive(options: Omit<ConfirmOptions, 'modalType'>) {
|
||||
return openConfirm({
|
||||
...options,
|
||||
modalType: ModalType.Destructive,
|
||||
});
|
||||
}
|
||||
|
||||
export function confirmWebEditorDiscard() {
|
||||
return openConfirm({
|
||||
modalType: ModalType.Warn,
|
||||
title: 'Are you sure?',
|
||||
message:
|
||||
'You currently have unsaved changes in the editor. Are you sure you want to leave?',
|
||||
confirmButton: buildConfirmButton('Yes', 'danger'),
|
||||
});
|
||||
}
|
||||
|
||||
export function confirmDelete(message: string) {
|
||||
return confirmDestructive({
|
||||
title: 'Are you sure?',
|
||||
message,
|
||||
confirmButton: buildConfirmButton('Remove', 'danger'),
|
||||
});
|
||||
}
|
||||
|
||||
export async function confirmUpdate(
|
||||
message: string,
|
||||
callback: ConfirmCallback
|
||||
) {
|
||||
const result = await openConfirm({
|
||||
title: 'Are you sure?',
|
||||
modalType: ModalType.Warn,
|
||||
message,
|
||||
confirmButton: buildConfirmButton('Update'),
|
||||
});
|
||||
|
||||
callback(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export function confirmChangePassword() {
|
||||
return openConfirm({
|
||||
modalType: ModalType.Warn,
|
||||
title: 'Are you sure?',
|
||||
message:
|
||||
'You will be logged out after the password change. Do you want to change your password?',
|
||||
confirmButton: buildConfirmButton('Change'),
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue