link for action scripts

This commit is contained in:
shamsmosowi
2023-01-19 14:52:53 +01:00
parent d55846e117
commit 24dc2a1f6e
2 changed files with 24 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ import { get } from "lodash-es";
import { useAtom, useSetAtom } from "jotai";
import { httpsCallable } from "firebase/functions";
import { Fab, FabProps } from "@mui/material";
import { Button, Fab, FabProps, Link } from "@mui/material";
import RunIcon from "@mui/icons-material/PlayArrow";
import RedoIcon from "@mui/icons-material/Refresh";
import UndoIcon from "@mui/icons-material/Undo";
@@ -118,11 +118,32 @@ export default function ActionFab({
} else {
result = await handleCallableAction(data);
}
const { message, success } = result ?? {};
const { message, success, link } = result ?? {};
enqueueSnackbar(
typeof message === "string" ? message : JSON.stringify(message),
{
variant: success ? "success" : "error",
action: link ? (
typeof link === "string" ? (
<Button
variant="outlined"
href={link}
component={Link}
target="_blank"
>
Link
</Button>
) : (
<Button
href={link.url}
component={Link}
variant="outlined"
target="_blank"
>
{link.label}
</Button>
)
) : undefined,
}
);
} catch (e) {

View File

@@ -22,6 +22,7 @@ type ActionResult = {
success: boolean;
message?: any;
status?: string | number | null | undefined;
link?: string | { url: string; label: string };
};
type Action = (context: ActionContext) => Promise<ActionResult> | ActionResult;