refactor: centralize confirm and prompt dialog calls in frontend
This commit is contained in:
@@ -24,6 +24,7 @@ import VisibilityOutlinedIcon from "@mui/icons-material/VisibilityOutlined";
|
||||
|
||||
import { api } from "../api";
|
||||
import { useToast } from "../toast";
|
||||
import { confirmAction, promptForValue } from "../dialogs";
|
||||
|
||||
interface AttachmentItem {
|
||||
id: number;
|
||||
@@ -82,7 +83,7 @@ export default function Attachments({ jobId }: { jobId: number }) {
|
||||
}, [preview?.url]);
|
||||
|
||||
const rename = async (a: AttachmentItem) => {
|
||||
const next = window.prompt("Rename attachment to:", a.fileName);
|
||||
const next = promptForValue("Rename attachment to:", a.fileName);
|
||||
if (!next || next.trim() === a.fileName) return;
|
||||
try {
|
||||
await api.patch(`/attachments/${a.id}`, { fileName: next.trim() });
|
||||
@@ -94,7 +95,7 @@ export default function Attachments({ jobId }: { jobId: number }) {
|
||||
};
|
||||
|
||||
const remove = async (a: AttachmentItem) => {
|
||||
if (!window.confirm(`Delete attachment "${a.fileName}"?`)) return;
|
||||
if (!confirmAction(`Delete attachment "${a.fileName}"?`)) return;
|
||||
try {
|
||||
await api.delete(`/attachments/${a.id}`);
|
||||
toast("Deleted attachment.", "success");
|
||||
|
||||
Reference in New Issue
Block a user