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

View File

@ -81,7 +81,10 @@ export function createApi({
? data ? data
: omitId(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; return response.data;
}, },