Skip to content

Commit

Permalink
Add confirmation alerts to user grid
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Dec 8, 2023
1 parent 0102241 commit aa49769
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
24 changes: 13 additions & 11 deletions client/src/components/Grid/configs/adminQuotas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,19 @@ const fields: FieldArray = [
icon: faTrash,
condition: (data: QuotaEntry) => !!data.deleted,
handler: async (data: QuotaEntry) => {
try {
await purgeQuota({ id: String(data.id) });
return {
status: "success",
message: `'${data.name}' has been purged.`,
};
} catch (e) {
return {
status: "danger",
message: `Failed to purge '${data.name}': ${errorMessageAsString(e)}`,
};
if (confirm(_l("Are you sure that you want to purge this quota?"))) {
try {
await purgeQuota({ id: String(data.id) });
return {
status: "success",
message: `'${data.name}' has been purged.`,
};
} catch (e) {
return {
status: "danger",
message: `Failed to purge '${data.name}': ${errorMessageAsString(e)}`,
};
}
}
},
},
Expand Down
49 changes: 27 additions & 22 deletions client/src/components/Grid/configs/adminUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import axios from "axios";
import { createApiKey, deleteUser, recalculateDiskUsageByUserId, sendActivationEmail, undeleteUser } from "@/api/users";
import type { GalaxyConfiguration } from "@/stores/configurationStore";
import Filtering, { contains, equals, toBool, type ValidFilter } from "@/utils/filtering";
import _l from "@/utils/localization";
import { withPrefix } from "@/utils/redirect";
import { errorMessageAsString } from "@/utils/simple-error";

Expand Down Expand Up @@ -195,17 +196,19 @@ const fields: FieldArray = [
return config.value.allow_user_deletion && !data.deleted;
},
handler: async (data: UserEntry) => {
try {
await deleteUser({ user_id: String(data.id), purge: false });
return {
status: "success",
message: `'${data.username}' has been deleted.`,
};
} catch (e) {
return {
status: "danger",
message: `Failed to delete '${data.username}': ${errorMessageAsString(e)}`,
};
if (confirm(_l("Are you sure that you want to delete this user?"))) {
try {
await deleteUser({ user_id: String(data.id), purge: false });
return {
status: "success",
message: `'${data.username}' has been deleted.`,
};
} catch (e) {
return {
status: "danger",
message: `Failed to delete '${data.username}': ${errorMessageAsString(e)}`,
};
}
}
},
},
Expand All @@ -216,17 +219,19 @@ const fields: FieldArray = [
return config.value.allow_user_deletion && data.deleted && !data.purged;
},
handler: async (data: UserEntry) => {
try {
await deleteUser({ user_id: String(data.id), purge: true });
return {
status: "success",
message: `'${data.username}' has been purged.`,
};
} catch (e) {
return {
status: "danger",
message: `Failed to purge '${data.username}': ${errorMessageAsString(e)}`,
};
if (confirm(_l("Are you sure that you want to purge this user?"))) {
try {
await deleteUser({ user_id: String(data.id), purge: true });
return {
status: "success",
message: `'${data.username}' has been purged.`,
};
} catch (e) {
return {
status: "danger",
message: `Failed to purge '${data.username}': ${errorMessageAsString(e)}`,
};
}
}
},
},
Expand Down

0 comments on commit aa49769

Please sign in to comment.