synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
113 lines (112 loc) • 3.64 kB
JavaScript
import { jsxs as n, Fragment as F, jsx as e } from "react/jsx-runtime";
import r from "./CreatePackageV2.module.scss.js";
import { createPackageFromDownloadListV2 as N, getFileHandleByIdURL as D } from "../../synapse-client/SynapseClient.js";
import { useSynapseContext as L } from "../../utils/context/SynapseContext.js";
import { useQueryClient as I } from "@tanstack/react-query";
import { Card as R, Box as A, TextField as B, InputAdornment as E, Button as T } from "@mui/material";
import { useState as o } from "react";
import H from "../FullWidthAlert/FullWidthAlert.js";
const S = "Please provide a package file name and try again.", M = (y) => {
const { accessToken: c, keyFactory: k } = L(), f = I(), [d, p] = o(!1), [s, m] = o(""), [t, i] = o(), [h, g] = o(void 0), { onPackageCreation: P } = y, v = async (a) => {
if (a.preventDefault(), !s) {
i({
message: S,
variant: "danger"
});
return;
}
p(!0);
try {
const l = `${s}.zip`, u = await N(
l,
c
);
g(u);
const { resultFileHandleId: x } = u;
try {
window.location.href = await D(
x,
c
), m(""), g(void 0), f.invalidateQueries({
queryKey: k.getDownloadListBaseQueryKey()
}), P();
} catch (C) {
console.error("Err on getFileHandleByIdURL = ", C);
}
} catch (l) {
i({
message: l.reason,
variant: "danger"
});
} finally {
p(!1);
}
}, w = (a) => {
m(a.target.value);
};
return /* @__PURE__ */ n(F, { children: [
/* @__PURE__ */ e(R, { className: r.CreatePackageV2, children: /* @__PURE__ */ n("div", { className: r.createPackageStep, children: [
/* @__PURE__ */ e("span", { className: r.createPackageTitle, children: "Create your Download Package" }),
/* @__PURE__ */ e("span", { className: r.createPackageDescription, children: "Name your download package and select Download Package to get started." }),
!d && !h && /* @__PURE__ */ n(
A,
{
sx: {
display: "flex",
alignItems: "stretch"
},
children: [
/* @__PURE__ */ e(
B,
{
onChange: w,
type: "text",
placeholder: "PackageName",
sx: { width: "233px" },
slotProps: {
input: {
endAdornment: /* @__PURE__ */ e(E, { position: "end", children: ".zip" })
}
}
}
),
/* @__PURE__ */ e(
T,
{
variant: "contained",
color: "primary",
onClick: (a) => {
v(a);
},
sx: { marginLeft: "20px" },
disabled: !s,
children: "Download Package"
}
)
]
}
),
d && /* @__PURE__ */ n("div", { className: "creatingPackage", children: [
/* @__PURE__ */ e("span", { className: "spinner" }),
/* @__PURE__ */ e("span", { style: { marginLeft: 5 }, children: "Creating package..." })
] })
] }) }),
/* @__PURE__ */ e(
H,
{
show: !!t,
variant: t?.variant ? t.variant : "success",
description: t?.message,
autoCloseAfterDelayInSeconds: 10,
onClose: () => {
i(void 0);
}
}
)
] });
};
export {
M as CreatePackageV2,
S as TEMPLATE_ERROR_FILE_NAME
};
//# sourceMappingURL=CreatePackageV2.js.map