add createApi

This commit is contained in:
Mohamadzadeh 2026-06-15 17:38:27 +03:30
parent 2f4a5f32f5
commit 45a618f315
2 changed files with 77 additions and 74 deletions

146
dist/index.js vendored
View File

@ -1,8 +1,8 @@
import { t as Z, a as T } from "./chunks/Pagination-LRiUo8_9.js";
import { t as Z, a as w } from "./chunks/Pagination-LRiUo8_9.js";
import { P as ht, b as mt } from "./chunks/Pagination-LRiUo8_9.js";
import { jsxs as D, jsx as u } from "react/jsx-runtime";
import { useState as F, useRef as q, useEffect as x, useCallback as y, createContext as G, useMemo as M, useContext as oe } from "react";
import { HStack as z, IconButton as Y, Button as V, Input as U, Text as w, extendTheme as ie, withDefaultColorScheme as re, ChakraProvider as Ae, Spinner as se, Box as de, VStack as L, Image as P } from "@chakra-ui/react";
import { HStack as z, IconButton as Y, Button as V, Input as U, Text as T, extendTheme as ie, withDefaultColorScheme as re, ChakraProvider as Ae, Spinner as se, Box as de, VStack as L, Image as P } from "@chakra-ui/react";
import { IoChevronForwardOutline as J, IoChevronBackOutline as k } from "react-icons/io5";
import le from "keycloak-js";
import { useQuery as Q, useQueryClient as ue, useMutation as ce, QueryClient as ae, QueryClientProvider as ge } from "@tanstack/react-query";
@ -14,42 +14,42 @@ const At = ({
totalCount: n,
onPageChange: r
}) => {
const [l, A] = F(Z(e)), [o, s] = F(!1), [a, d] = F(null), p = q(null), b = [.../* @__PURE__ */ new Set([1, e, t])].filter(
const [l, A] = F(Z(e)), [o, s] = F(!1), [C, d] = F(null), p = q(null), b = [.../* @__PURE__ */ new Set([1, e, t])].filter(
(i) => i >= 1 && i <= t
);
x(() => {
if (a !== null) {
e === a && (d(null), s(!1), A(Z(e)));
if (C !== null) {
e === C && (d(null), s(!1), A(Z(e)));
return;
}
o || A(Z(e));
}, [e, o, a]), x(() => {
if (!o || !l || a !== null) return;
const i = parseInt(T(l), 10);
}, [e, o, C]), x(() => {
if (!o || !l || C !== null) return;
const i = parseInt(w(l), 10);
if (isNaN(i)) return;
const I = setTimeout(() => {
var C;
const g = Math.min(Math.max(i, 1), t);
g !== e ? (d(g), A(Z(g)), r(g)) : (s(!1), A(Z(e))), (C = p.current) == null || C.blur();
var g;
const a = Math.min(Math.max(i, 1), t);
a !== e ? (d(a), A(Z(a)), r(a)) : (s(!1), A(Z(e))), (g = p.current) == null || g.blur();
}, 1e3);
return () => clearTimeout(I);
}, [
l,
o,
a,
C,
t,
e,
r
]);
const h = () => {
var g, C;
const i = parseInt(T(l), 10);
var a, g;
const i = parseInt(w(l), 10);
if (isNaN(i)) {
A(Z(e)), s(!1), d(null), (g = p.current) == null || g.blur();
A(Z(e)), s(!1), d(null), (a = p.current) == null || a.blur();
return;
}
const I = Math.min(Math.max(i, 1), t);
I !== e ? (d(I), A(Z(I)), r(I)) : (A(Z(e)), s(!1), d(null)), (C = p.current) == null || C.blur();
I !== e ? (d(I), A(Z(I)), r(I)) : (A(Z(e)), s(!1), d(null)), (g = p.current) == null || g.blur();
};
return t === 0 || !n ? null : /* @__PURE__ */ D(
z,
@ -117,8 +117,8 @@ const At = ({
s(!0), d(null), A("");
},
onChange: (i) => {
const I = i.target.value, g = T(I).replace(/\D/g, "");
A(Z(g));
const I = i.target.value, a = w(I).replace(/\D/g, "");
A(Z(a));
},
onBlur: () => {
l || (A(Z(e)), s(!1), d(null));
@ -135,8 +135,8 @@ const At = ({
)
] }),
/* @__PURE__ */ D(z, { spacing: 2, children: [
/* @__PURE__ */ u(w, { w: "auto", fontWeight: "bold", whiteSpace: "nowrap", children: "تعداد کل:" }),
/* @__PURE__ */ u(w, { children: Z(n) })
/* @__PURE__ */ u(T, { w: "auto", fontWeight: "bold", whiteSpace: "nowrap", children: "تعداد کل:" }),
/* @__PURE__ */ u(T, { children: Z(n) })
] })
]
}
@ -147,7 +147,7 @@ const At = ({
totalCount: n,
onPageChange: r
}) => {
const [l, A] = F(""), [o, s] = F(!1), [a, d] = F(null), p = q(null), b = a ?? e, h = y(
const [l, A] = F(""), [o, s] = F(!1), [C, d] = F(null), p = q(null), b = C ?? e, h = y(
(m) => {
const E = Math.min(Math.max(m, 1), t);
s(!1), A(""), d(null), E !== e && r(E);
@ -158,7 +158,7 @@ const At = ({
s(!1), A(""), d(null);
return;
}
const m = parseInt(T(l), 10);
const m = parseInt(w(l), 10);
if (isNaN(m)) {
s(!1), A(""), d(null);
return;
@ -170,8 +170,8 @@ const At = ({
var m;
o && ((m = p.current) == null || m.focus());
}, [o]), x(() => {
a !== null && e === a && d(null);
}, [e, a]), x(() => {
C !== null && e === C && d(null);
}, [e, C]), x(() => {
if (!o || !l) return;
const m = setTimeout(() => {
i();
@ -180,7 +180,7 @@ const At = ({
}, [l, o, i]);
const I = () => {
d(null), A(""), s(!0);
}, g = (m, E = !1) => /* @__PURE__ */ u(
}, a = (m, E = !1) => /* @__PURE__ */ u(
V,
{
size: "md",
@ -194,7 +194,7 @@ const At = ({
m
);
if (t === 0 || !n) return null;
const C = t > 1 && b !== 1, S = t > 1 && b !== t;
const g = t > 1 && b !== 1, S = t > 1 && b !== t;
return /* @__PURE__ */ u(
z,
{
@ -220,7 +220,7 @@ const At = ({
"aria-label": "صفحه قبلی"
}
),
C && g(1),
g && a(1),
o ? /* @__PURE__ */ u(
U,
{
@ -231,7 +231,7 @@ const At = ({
w: "48px",
value: l,
onChange: (m) => {
const E = m.target.value, ne = T(E).replace(/\D/g, "");
const E = m.target.value, ne = w(E).replace(/\D/g, "");
A(Z(ne));
},
onBlur: () => {
@ -246,8 +246,8 @@ const At = ({
minW: 0,
dir: "ltr"
}
) : g(b, !0),
S && g(t),
) : a(b, !0),
S && a(t),
/* @__PURE__ */ u(
Y,
{
@ -290,35 +290,35 @@ const pe = G(null), be = ({ url: e, realm: t, clientId: n }) => (c || (c = new l
initOptions: n,
loading: r = null
}) => {
const [l, A] = F(!1), [o, s] = F(!1), [a, d] = F(null), p = q(!1), b = y(() => {
const [l, A] = F(!1), [o, s] = F(!1), [C, d] = F(null), p = q(!1), b = y(() => {
c && (s(!!c.authenticated), d(c.token ?? null));
}, []);
x(() => (p.current = !0, _({ config: t, initOptions: n }).then((C) => {
p.current && (s(!!C), d((c == null ? void 0 : c.token) ?? null), A(!0));
x(() => (p.current = !0, _({ config: t, initOptions: n }).then((g) => {
p.current && (s(!!g), d((c == null ? void 0 : c.token) ?? null), A(!0));
}).catch(() => {
p.current && (s(!1), d(null), A(!0));
}), () => {
p.current = !1;
}), [t, n]);
const h = y(() => c == null ? void 0 : c.login(), []), i = y((C) => c == null ? void 0 : c.logout(C), []), I = y(
async (C = 30) => {
const h = y(() => c == null ? void 0 : c.login(), []), i = y((g) => c == null ? void 0 : c.logout(g), []), I = y(
async (g = 30) => {
if (!c) return !1;
const S = await c.updateToken(C);
const S = await c.updateToken(g);
return b(), S;
},
[b]
), g = M(
), a = M(
() => ({
initialized: l,
authenticated: o,
token: a,
token: C,
login: h,
logout: i,
updateToken: I
}),
[l, o, a, h, i, I]
[l, o, C, h, i, I]
);
return l ? /* @__PURE__ */ u(pe.Provider, { value: g, children: e }) : r;
return l ? /* @__PURE__ */ u(pe.Provider, { value: a, children: e }) : r;
}, $ = G(null), v = "permissions", Se = (e) => (e == null ? void 0 : e.storageKey) || v, Ee = ({
user: e = null,
children: t,
@ -328,17 +328,17 @@ const pe = G(null), be = ({ url: e, realm: t, clientId: n }) => (c || (c = new l
}) => {
const A = Se(n), [o, s] = F(
() => Fe(A)
), { data: a, isLoading: d, error: p } = Te(n), b = a ?? o;
), { data: C, isLoading: d, error: p } = we(n), b = C ?? o;
x(() => {
a && (xe(A, a), s(a));
}, [a, A]);
C && (xe(A, C), s(C));
}, [C, A]);
const h = M(
() => ye(b),
[b]
), i = y(
(C = "") => De(h, C),
(g = "") => De(h, g),
[h]
), I = y((C = "") => !i(C), [i]), g = M(
), I = y((g = "") => !i(g), [i]), a = M(
() => ({
user: e,
can: i,
@ -349,7 +349,7 @@ const pe = G(null), be = ({ url: e, realm: t, clientId: n }) => (c || (c = new l
}),
[e, i, I, b, d, p]
);
return p && !b ? l : d && !b ? r : /* @__PURE__ */ u($.Provider, { value: g, children: t });
return p && !b ? l : d && !b ? r : /* @__PURE__ */ u($.Provider, { value: a, children: t });
}, Fe = (e = v) => {
if (!(typeof window > "u"))
try {
@ -399,7 +399,7 @@ const pe = G(null), be = ({ url: e, realm: t, clientId: n }) => (c || (c = new l
if (!e)
throw new Error("usePermission must be used within PermissionProvider");
return e;
}, Te = (e) => Q({
}, we = (e) => Q({
queryKey: ee.list(e == null ? void 0 : e.clientId),
queryFn: () => ze(e),
enabled: !!(e != null && e.url) && !!(e != null && e.clientId) && H(),
@ -423,7 +423,7 @@ const pe = G(null), be = ({ url: e, realm: t, clientId: n }) => (c || (c = new l
}, [n, t]), e;
};
let B = null;
const we = (e) => {
const Te = (e) => {
const { api: t } = e, n = Ce.create({
baseURL: t.baseUrl
}), r = async () => {
@ -443,9 +443,9 @@ const we = (e) => {
}
return o;
}, A = async (o) => {
var a;
var C;
const s = o.config;
if (((a = o == null ? void 0 : o.response) == null ? void 0 : a.status) === 401 && !(s != null && s._retry)) {
if (((C = o == null ? void 0 : o.response) == null ? void 0 : C.status) === 401 && !(s != null && s._retry)) {
s._retry = !0;
try {
await O(30);
@ -466,7 +466,7 @@ const we = (e) => {
), {
api: n
};
}, fe = (e) => (B = we(e), B), Me = () => {
}, fe = (e) => (B = Te(e), B), Me = () => {
if (!B)
throw new Error("api is not configured. Call configureApi(config) first.");
return B.api;
@ -518,25 +518,25 @@ function gt({
...p
});
}
function a(d, p = {}) {
function C(d, p = {}) {
const b = ue(), h = n[d];
if (!h)
throw new Error(`Action "${d}" is not defined.`);
return ce({
mutationKey: [...A, d],
mutationFn: async (i = {}) => {
const I = h.method || "post", g = We(h.url, i), C = h.body ? h.body(i) : h.withId ? i : Xe(i);
return (await r[I](g, C)).data;
const I = h.method || "post", a = We(h.url, i), g = h.body ? h.body(i) : h.withId ? i : Xe(i);
return (I === "delete" ? await r.delete(a, { data: g }) : await r[I](a, g)).data;
},
onSuccess: (...i) => {
var S;
const [I, g] = i;
const [I, a] = i;
b.invalidateQueries({
queryKey: o
});
const C = (g == null ? void 0 : g.id) ?? (I == null ? void 0 : I.id);
C && b.invalidateQueries({
queryKey: qe(e, C)
const g = (a == null ? void 0 : a.id) ?? (I == null ? void 0 : I.id);
g && b.invalidateQueries({
queryKey: qe(e, g)
}), (S = p.onSuccess) == null || S.call(p, ...i);
},
...p
@ -546,7 +546,7 @@ function gt({
key: A,
listKey: o,
useGet: s,
useAction: a
useAction: C
};
}
function Ne() {
@ -650,22 +650,22 @@ function Ct({
updateChecker: A = !1,
updateCheckerProps: o,
keycloakUrl: s = "https://auth.ibagher.ir",
keycloakRealm: a = "bi",
keycloakRealm: C = "bi",
permissionUrl: d = "https://api.d.aiengines.ir/user_api/v1/permissions/list",
keycloakEnabled: p,
permissionEnabled: b
}) {
const [h, i] = F(!1), I = p ?? !!n, g = b ?? !!r, C = M(
const [h, i] = F(!1), I = p ?? !!n, a = b ?? !!r, g = M(
() => ({
api: {
baseUrl: t || ""
},
keycloak: I ? {
url: s,
realm: a,
realm: C,
clientId: n
} : null,
permission: g ? {
permission: a ? {
url: d,
clientId: r
} : null
@ -673,9 +673,9 @@ function Ct({
[
t,
I,
g,
s,
a,
s,
C,
n,
d,
r
@ -684,11 +684,11 @@ function Ct({
if (x(() => {
i(!0);
}, []), x(() => {
h && fe(C);
}, [h, C]), !h)
h && fe(g);
}, [h, g]), !h)
return null;
let S = e;
return g && (S = /* @__PURE__ */ u(Ee, { config: C.permission, loading: l, children: S })), I && (S = /* @__PURE__ */ u(Ze, { config: C.keycloak, loading: l, children: S })), /* @__PURE__ */ D(Ae, { theme: Oe, children: [
return a && (S = /* @__PURE__ */ u(Ee, { config: g.permission, loading: l, children: S })), I && (S = /* @__PURE__ */ u(Ze, { config: g.keycloak, loading: l, children: S })), /* @__PURE__ */ D(Ae, { theme: Oe, children: [
/* @__PURE__ */ u(Ge, {}),
/* @__PURE__ */ D(ge, { client: Re, children: [
A && /* @__PURE__ */ u(Ne, { ...o }),
@ -736,10 +736,10 @@ function Je({ children: e, ...t }) {
);
}
function ke({ children: e, ...t }) {
return /* @__PURE__ */ u(w, { fontWeight: "bold", fontSize: "20px", ...t, children: e });
return /* @__PURE__ */ u(T, { fontWeight: "bold", fontSize: "20px", ...t, children: e });
}
function Qe({ children: e, ...t }) {
return /* @__PURE__ */ u(w, { ...t, children: e });
return /* @__PURE__ */ u(T, { ...t, children: e });
}
function He({ logoSrc: e = Ve, ...t }) {
return /* @__PURE__ */ D(
@ -752,7 +752,7 @@ function He({ logoSrc: e = Ve, ...t }) {
...t,
children: [
/* @__PURE__ */ u(P, { src: e, loading: "lazy", maxW: "90px" }),
/* @__PURE__ */ u(w, { fontSize: "xs", fontWeight: "bold", textAlign: "center", children: "مؤسسه تولید سیستم‌های خبره و هوشمند اسلامی باقرالعلوم(ع)" })
/* @__PURE__ */ u(T, { fontSize: "xs", fontWeight: "bold", textAlign: "center", children: "مؤسسه تولید سیستم‌های خبره و هوشمند اسلامی باقرالعلوم(ع)" })
]
}
);
@ -794,10 +794,10 @@ export {
j as logoutKeycloak,
ee as permissionKeys,
xe as setCachedPermissions,
T as toEnDigits,
w as toEnDigits,
Z as toFaDigits,
mt as toFaNumber,
O as updateKeycloakToken,
R as usePermission,
Te as usePermissionsQuery
we as usePermissionsQuery
};

View File

@ -81,7 +81,10 @@ export function createApi({
? data
: omitId(data);
const response = await axiosInstance[method](requestUrl, payload);
const response =
method === "delete"
? await axiosInstance.delete(requestUrl, { data: payload })
: await axiosInstance[method](requestUrl, payload);
return response.data;
},