Skip to content

Commit

Permalink
Add confirmation action method (#6)
Browse files Browse the repository at this point in the history
- Add `ConfirmAction` method that uses the `runtime.MessageDialog` component for confirming an action
- Use `ConfirmAction` before deleting an organization as this is a destructive action, and should be sure the user meant to do so
  • Loading branch information
theBGuy authored Feb 20, 2024
1 parent 5653235 commit 5a5ef11
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
15 changes: 15 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ func (a *App) ShowWindow() {
runtime.WindowShow(a.ctx)
}

// Display a confirmation dialog
func (a *App) ConfirmAction(title string, message string) bool {
selection, err := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
Type: runtime.QuestionDialog,
Title: title,
Message: message,
DefaultButton: "No",
})
if err != nil {
fmt.Println(err)
return false
}
return selection == "Yes"
}

// GetWorkTime returns the total seconds worked
func (a *App) GetWorkTime(date string, organization string) (seconds int, err error) {
if date == "" || organization == "" {
Expand Down
30 changes: 19 additions & 11 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ import {
GetMonthlyWorkTime,
GetVersion,
UpdateAvailable,
ShowWindow
ShowWindow,
ConfirmAction
} from "../wailsjs/go/main/App";

function App() {
Expand Down Expand Up @@ -215,17 +216,24 @@ function App() {
};

const handleDeleteOrganization = () => {
// TODO: Are you sure you want to delete this organization? This is a destructive action we should double check with the user
handleMenuClose();
if (organizations.length === 1) {
toast.error("You cannot delete the last organization");
return;
}
DeleteOrganization(selectedOrganization).then(() => {
setOrganizations(orgs => orgs.filter(org => org !== selectedOrganization));
setSelectedOrganization(organizations[0]);
// if (window.confirm("Are you sure you want to delete this organization?") === false) {
// return;
// }
ConfirmAction(`Delete ${selectedOrganization}`, "Are you sure you want to delete this organization?").then((confirmed) => {
if (confirmed === false) {
return;
}
handleMenuClose();
if (organizations.length === 1) {
toast.error("You cannot delete the last organization");
return;
}
DeleteOrganization(selectedOrganization).then(() => {
setOrganizations(orgs => orgs.filter(org => org !== selectedOrganization));
setSelectedOrganization(organizations[0]);
});
SetOrganization(selectedOrganization);
});
SetOrganization(selectedOrganization);
};

const handleUpdateSettings = () => {
Expand Down
2 changes: 2 additions & 0 deletions frontend/wailsjs/go/main/App.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// This file is automatically generated. DO NOT EDIT
import {time} from '../models';

export function ConfirmAction(arg1:string,arg2:string):Promise<boolean>;

export function DeleteOrganization(arg1:string):Promise<void>;

export function ExportCSVByMonth(arg1:string,arg2:number,arg3:time.Month):Promise<string>;
Expand Down
4 changes: 4 additions & 0 deletions frontend/wailsjs/go/main/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT

export function ConfirmAction(arg1, arg2) {
return window['go']['main']['App']['ConfirmAction'](arg1, arg2);
}

export function DeleteOrganization(arg1) {
return window['go']['main']['App']['DeleteOrganization'](arg1);
}
Expand Down

0 comments on commit 5a5ef11

Please sign in to comment.