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 { api } from "../api";
|
||||||
import { useToast } from "../toast";
|
import { useToast } from "../toast";
|
||||||
|
import { confirmAction, promptForValue } from "../dialogs";
|
||||||
|
|
||||||
interface AttachmentItem {
|
interface AttachmentItem {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -82,7 +83,7 @@ export default function Attachments({ jobId }: { jobId: number }) {
|
|||||||
}, [preview?.url]);
|
}, [preview?.url]);
|
||||||
|
|
||||||
const rename = async (a: AttachmentItem) => {
|
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;
|
if (!next || next.trim() === a.fileName) return;
|
||||||
try {
|
try {
|
||||||
await api.patch(`/attachments/${a.id}`, { fileName: next.trim() });
|
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) => {
|
const remove = async (a: AttachmentItem) => {
|
||||||
if (!window.confirm(`Delete attachment "${a.fileName}"?`)) return;
|
if (!confirmAction(`Delete attachment "${a.fileName}"?`)) return;
|
||||||
try {
|
try {
|
||||||
await api.delete(`/attachments/${a.id}`);
|
await api.delete(`/attachments/${a.id}`);
|
||||||
toast("Deleted attachment.", "success");
|
toast("Deleted attachment.", "success");
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ export default function Correspondence({ jobId }: { jobId: number }) {
|
|||||||
|
|
||||||
|
|
||||||
const deleteMessage = async (messageId: number) => {
|
const deleteMessage = async (messageId: number) => {
|
||||||
if (!window.confirm("Remove this correspondence message?")) return;
|
if (!confirmAction("Remove this correspondence message?")) return;
|
||||||
try {
|
try {
|
||||||
await api.delete(`/correspondence/${messageId}`);
|
await api.delete(`/correspondence/${messageId}`);
|
||||||
await load();
|
await load();
|
||||||
@@ -527,3 +527,8 @@ export default function Correspondence({ jobId }: { jobId: number }) {
|
|||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
tions>
|
||||||
|
</Dialog>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Box, Button, Paper, TextField, Typography } from "@mui/material";
|
|||||||
import { api } from "../api";
|
import { api } from "../api";
|
||||||
import { getAuthToken } from "../auth";
|
import { getAuthToken } from "../auth";
|
||||||
import { useToast } from "../toast";
|
import { useToast } from "../toast";
|
||||||
|
import { confirmAction } from "../dialogs";
|
||||||
|
|
||||||
type UserDto = {
|
type UserDto = {
|
||||||
id: string;
|
id: string;
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export function confirmAction(message: string): boolean {
|
||||||
|
return window.confirm(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function promptForValue(message: string, defaultValue = ""): string | null {
|
||||||
|
return window.prompt(message, defaultValue);
|
||||||
|
}
|
||||||
@@ -98,7 +98,7 @@ export default function AdminUsersPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const remove = async (u: UserDto) => {
|
const remove = async (u: UserDto) => {
|
||||||
if (!window.confirm(`Delete user ${u.email || u.userName || u.id}?`)) return;
|
if (!confirmAction(`Delete user ${u.email || u.userName || u.id}?`)) return;
|
||||||
try {
|
try {
|
||||||
await api.delete(`/users/${u.id}`);
|
await api.delete(`/users/${u.id}`);
|
||||||
toast("User deleted.", "info");
|
toast("User deleted.", "info");
|
||||||
|
|||||||
Reference in New Issue
Block a user