@variamosple/variamos-components 0.0.24 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
interface BugFormModalProps {
|
|
3
|
+
show: boolean;
|
|
4
|
+
onHide: () => void;
|
|
5
|
+
onSubmit: (data: {
|
|
6
|
+
title: string;
|
|
7
|
+
description: string;
|
|
8
|
+
category: string;
|
|
9
|
+
}, file?: File) => void;
|
|
10
|
+
categories: string[];
|
|
11
|
+
isSubmitting: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const BugFormModal: FC<BugFormModalProps>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { jsxs as l, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { useState as a, useEffect as B } from "react";
|
|
3
|
+
import { Modal as o, Form as t, Button as y } from "react-bootstrap";
|
|
4
|
+
const q = ({
|
|
5
|
+
show: i,
|
|
6
|
+
onHide: d,
|
|
7
|
+
onSubmit: C,
|
|
8
|
+
categories: n,
|
|
9
|
+
isSubmitting: c
|
|
10
|
+
}) => {
|
|
11
|
+
const [s, u] = a(""), [h, p] = a(""), [m, g] = a(""), [v, b] = a(null), [F, f] = a(!1);
|
|
12
|
+
B(() => {
|
|
13
|
+
i && (u(""), p(""), g(n[0] || "Other"), b(null), f(!1));
|
|
14
|
+
}, [i, n]);
|
|
15
|
+
const x = (e) => {
|
|
16
|
+
if (e.preventDefault(), e.currentTarget.checkValidity() === !1) {
|
|
17
|
+
e.stopPropagation(), f(!0);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
C({ title: s, description: h, category: m }, v || void 0);
|
|
21
|
+
};
|
|
22
|
+
return /* @__PURE__ */ l(
|
|
23
|
+
o,
|
|
24
|
+
{
|
|
25
|
+
show: i,
|
|
26
|
+
onHide: d,
|
|
27
|
+
backdrop: "static",
|
|
28
|
+
keyboard: !1,
|
|
29
|
+
centered: !0,
|
|
30
|
+
children: [
|
|
31
|
+
/* @__PURE__ */ r(o.Header, { closeButton: !0, children: /* @__PURE__ */ r(o.Title, { children: "Report a New Bug" }) }),
|
|
32
|
+
/* @__PURE__ */ l(t, { noValidate: !0, validated: F, onSubmit: x, children: [
|
|
33
|
+
/* @__PURE__ */ l(o.Body, { children: [
|
|
34
|
+
/* @__PURE__ */ l(t.Group, { className: "mb-3", controlId: "bugTitle", children: [
|
|
35
|
+
/* @__PURE__ */ r(t.Label, { children: "Title *" }),
|
|
36
|
+
/* @__PURE__ */ r(
|
|
37
|
+
t.Control,
|
|
38
|
+
{
|
|
39
|
+
required: !0,
|
|
40
|
+
type: "text",
|
|
41
|
+
placeholder: "e.g. Build error on auth routes",
|
|
42
|
+
value: s,
|
|
43
|
+
onChange: (e) => u(e.target.value),
|
|
44
|
+
maxLength: 100
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
/* @__PURE__ */ r(t.Control.Feedback, { type: "invalid", children: "Title is required (max 100 characters)" })
|
|
48
|
+
] }),
|
|
49
|
+
/* @__PURE__ */ l(t.Group, { className: "mb-3", controlId: "bugDescription", children: [
|
|
50
|
+
/* @__PURE__ */ r(t.Label, { children: "Description *" }),
|
|
51
|
+
/* @__PURE__ */ r(
|
|
52
|
+
t.Control,
|
|
53
|
+
{
|
|
54
|
+
required: !0,
|
|
55
|
+
as: "textarea",
|
|
56
|
+
rows: 4,
|
|
57
|
+
placeholder: "Describe step-by-step how to reproduce the bug...",
|
|
58
|
+
value: h,
|
|
59
|
+
onChange: (e) => p(e.target.value)
|
|
60
|
+
}
|
|
61
|
+
),
|
|
62
|
+
/* @__PURE__ */ r(t.Control.Feedback, { type: "invalid", children: "Description is required" })
|
|
63
|
+
] }),
|
|
64
|
+
/* @__PURE__ */ r("div", { className: "row", children: /* @__PURE__ */ r("div", { className: "col-md-12", children: /* @__PURE__ */ l(t.Group, { className: "mb-3", controlId: "bugCategory", children: [
|
|
65
|
+
/* @__PURE__ */ r(t.Label, { children: "Category *" }),
|
|
66
|
+
/* @__PURE__ */ r(
|
|
67
|
+
t.Select,
|
|
68
|
+
{
|
|
69
|
+
required: !0,
|
|
70
|
+
value: m,
|
|
71
|
+
onChange: (e) => g(e.target.value),
|
|
72
|
+
children: n.map((e) => /* @__PURE__ */ r("option", { value: e, children: e }, e))
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
] }) }) }),
|
|
76
|
+
/* @__PURE__ */ l(t.Group, { className: "mb-3", controlId: "bugFile", children: [
|
|
77
|
+
/* @__PURE__ */ r(t.Label, { children: "Attachment (Optional)" }),
|
|
78
|
+
/* @__PURE__ */ r(
|
|
79
|
+
t.Control,
|
|
80
|
+
{
|
|
81
|
+
type: "file",
|
|
82
|
+
onChange: (e) => {
|
|
83
|
+
e.target.files && e.target.files.length > 0 && b(e.target.files[0]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
] })
|
|
88
|
+
] }),
|
|
89
|
+
/* @__PURE__ */ l(o.Footer, { children: [
|
|
90
|
+
/* @__PURE__ */ r(y, { variant: "secondary", onClick: d, disabled: c, children: "Cancel" }),
|
|
91
|
+
/* @__PURE__ */ r(y, { variant: "primary", type: "submit", disabled: c, children: c ? "Creating..." : "Report Bug" })
|
|
92
|
+
] })
|
|
93
|
+
] })
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
export {
|
|
99
|
+
q as BugFormModal
|
|
100
|
+
};
|
|
@@ -1,39 +1,93 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useMemo as
|
|
3
|
-
import { NavDropdown as
|
|
1
|
+
import { jsxs as S, Fragment as E, jsx as p } from "react/jsx-runtime";
|
|
2
|
+
import { useState as h, useEffect as F, useMemo as T } from "react";
|
|
3
|
+
import { NavDropdown as g } from "react-bootstrap";
|
|
4
4
|
import "../../Context/AnalyticsContext.js";
|
|
5
|
-
import { useMenu as
|
|
6
|
-
import { useRouter as
|
|
7
|
-
import { useSession as
|
|
8
|
-
import { mapToWebTarget as
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
import { useMenu as j } from "../../Context/MenuContext.js";
|
|
6
|
+
import { useRouter as C } from "../../Context/RouterContext.js";
|
|
7
|
+
import { useSession as b } from "../../Context/SessionContext.js";
|
|
8
|
+
import { mapToWebTarget as x } from "../../Model/Router.js";
|
|
9
|
+
import { Events as y } from "../../Common/Events.js";
|
|
10
|
+
import { BugFormModal as L } from "./BugFormModal.js";
|
|
11
|
+
const u = {}, K = () => {
|
|
12
|
+
const { user: o, isAuthenticated: m, logout: B } = b(), { options: l } = j(), { navigate: P } = C(), [R, c] = h(!1), [A] = h([
|
|
13
|
+
"Editor",
|
|
14
|
+
"Model",
|
|
15
|
+
"Language",
|
|
16
|
+
"Project",
|
|
17
|
+
"Simulation",
|
|
18
|
+
"Account/Security",
|
|
19
|
+
"Other"
|
|
20
|
+
]), [k, f] = h(!1), v = (u == null ? void 0 : u.VITE_ADMIN_API_URL) || "http://localhost:4000/v1";
|
|
21
|
+
F(() => {
|
|
22
|
+
const t = () => {
|
|
23
|
+
c(!0);
|
|
24
|
+
};
|
|
25
|
+
return y.subscribe("openReportBugModal", t), () => {
|
|
26
|
+
y.unsubscribe("openReportBugModal", t);
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
const D = async (t, d) => {
|
|
30
|
+
f(!0);
|
|
31
|
+
try {
|
|
32
|
+
const e = new FormData();
|
|
33
|
+
e.append("title", t.title), e.append("description", t.description), e.append("priority", "medium"), e.append("category", t.category), o != null && o.email && e.append("reporterEmail", o.email), d && e.append("file", d);
|
|
34
|
+
const i = v.replace(/\/v1$/, ""), s = {}, n = localStorage.getItem("authToken");
|
|
35
|
+
n && (s.Authorization = `Bearer ${n}`);
|
|
36
|
+
const a = await fetch(`${i}/bugs`, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: s,
|
|
39
|
+
body: e,
|
|
40
|
+
credentials: "include"
|
|
41
|
+
}), w = await a.json();
|
|
42
|
+
f(!1), a.ok && !w.errorCode ? c(!1) : alert(w.message || "Failed to submit bug. Please try again.");
|
|
43
|
+
} catch (e) {
|
|
44
|
+
f(!1), alert("Failed to submit bug. Please try again."), console.error(e);
|
|
45
|
+
}
|
|
46
|
+
}, r = T(() => {
|
|
47
|
+
const t = (o == null ? void 0 : o.permissions) || [], d = (o == null ? void 0 : o.roles) || [];
|
|
48
|
+
return l != null && l.length ? l.filter((e) => {
|
|
49
|
+
var s, n;
|
|
50
|
+
if (!((s = e == null ? void 0 : e.allowedPermissions) != null && s.length) && !((n = e == null ? void 0 : e.allowedRoles) != null && n.length))
|
|
15
51
|
return !0;
|
|
16
|
-
let
|
|
17
|
-
return
|
|
18
|
-
(
|
|
19
|
-
)),
|
|
52
|
+
let i = !0;
|
|
53
|
+
return e.allowedRoles && (i = i && e.allowedRoles.some((a) => d.includes(a))), e.allowedPermissions && (i = i && e.allowedPermissions.some(
|
|
54
|
+
(a) => t.includes(a)
|
|
55
|
+
)), i;
|
|
20
56
|
}) : [];
|
|
21
|
-
}, [
|
|
22
|
-
return !(
|
|
23
|
-
|
|
24
|
-
|
|
57
|
+
}, [l, o]);
|
|
58
|
+
return !(r != null && r.length) && !m ? null : /* @__PURE__ */ S(E, { children: [
|
|
59
|
+
/* @__PURE__ */ S(g, { title: (o == null ? void 0 : o.name) || "Options", id: "nav-dropdown", children: [
|
|
60
|
+
r == null ? void 0 : r.map((t) => /* @__PURE__ */ p(
|
|
61
|
+
g.Item,
|
|
62
|
+
{
|
|
63
|
+
onClick: () => {
|
|
64
|
+
if (t.location.endsWith("#report-bug")) {
|
|
65
|
+
c(!0);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
P(t.location, {
|
|
69
|
+
target: x(t.target)
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
children: t.title
|
|
73
|
+
},
|
|
74
|
+
t.title
|
|
75
|
+
)),
|
|
76
|
+
m && !!(r != null && r.length) && /* @__PURE__ */ p(g.Divider, {}),
|
|
77
|
+
m && /* @__PURE__ */ p(g.Item, { onClick: B, children: "Logout" })
|
|
78
|
+
] }),
|
|
79
|
+
/* @__PURE__ */ p(
|
|
80
|
+
L,
|
|
25
81
|
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
33
|
-
d && !!(l != null && l.length) && /* @__PURE__ */ c(a.Divider, {}),
|
|
34
|
-
d && /* @__PURE__ */ c(a.Item, { onClick: g, children: "Logout" })
|
|
82
|
+
show: R,
|
|
83
|
+
onHide: () => c(!1),
|
|
84
|
+
onSubmit: D,
|
|
85
|
+
categories: A,
|
|
86
|
+
isSubmitting: k
|
|
87
|
+
}
|
|
88
|
+
)
|
|
35
89
|
] });
|
|
36
90
|
};
|
|
37
91
|
export {
|
|
38
|
-
|
|
92
|
+
K as HeaderOptions
|
|
39
93
|
};
|