Skip to content

Commit

Permalink
refactor: extract alert method to a standalone function
Browse files Browse the repository at this point in the history
  • Loading branch information
arielsvg committed Jul 20, 2020
1 parent c6a25d6 commit 966783c
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions app/assets/javascripts/services/alertService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export function confirmDialog({
title,
confirmButtonText = 'Confirm',
cancelButtonText = 'Cancel',
confirmButtonStyle = 'info'
confirmButtonStyle = 'info',
}: {
text: string,
title?: string,
confirmButtonText?: string,
cancelButtonText?: string,
confirmButtonStyle?: 'danger' | 'info'
text: string;
title?: string;
confirmButtonText?: string;
cancelButtonText?: string;
confirmButtonStyle?: 'danger' | 'info';
}) {
return new Promise<boolean>((resolve) => {
const alert = new SKAlert({
Expand All @@ -41,24 +41,37 @@ export function confirmDialog({
});
}

export class AlertService implements SNAlertService {
alert(
text: string,
title: string,
closeButtonText = 'OK',
) {
return new Promise<void>((resolve) => {
const alert = new SKAlert({
title,
text,
buttons: [{
export function alertDialog({
title,
text,
closeButtonText = 'OK',
}: {
title?: string;
text: string;
closeButtonText?: string;
}) {
return new Promise<void>((resolve) => {
const alert = new SKAlert({
title,
text,
buttons: [
{
text: closeButtonText,
style: 'neutral',
action: resolve,
}],
});
alert.present();
},
],
});
alert.present();
});
}

export class AlertService implements SNAlertService {
/**
* @deprecated use the standalone `alertDialog` function instead
*/
alert(text: string, title?: string, closeButtonText?: string) {
return alertDialog({ text, title, closeButtonText });
}

confirm(
Expand All @@ -73,7 +86,8 @@ export class AlertService implements SNAlertService {
title,
confirmButtonText,
cancelButtonText,
confirmButtonStyle: confirmButtonType === ButtonType.Danger ? 'danger' : 'info'
confirmButtonStyle:
confirmButtonType === ButtonType.Danger ? 'danger' : 'info',
});
}

Expand Down

0 comments on commit 966783c

Please sign in to comment.