aq-fe-framework 0.1.202 → 0.1.204

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,126 @@
1
+ import {
2
+ __spreadValues
3
+ } from "./chunk-FWCSY2DS.mjs";
4
+
5
+ // src/api/baseAxios.ts
6
+ import axios from "axios";
7
+ var baseAxios = axios.create({
8
+ baseURL: process.env.NEXT_PUBLIC_API
9
+ // server
10
+ // baseURL: process.env.NEXT_PUBLIC_API_LOCAL, // local debug
11
+ });
12
+ baseAxios.interceptors.request.use(
13
+ (config) => {
14
+ var _a, _b;
15
+ const tokenData = localStorage.getItem("useS_authenticate");
16
+ const state = JSON.parse(tokenData);
17
+ const token = (_b = (_a = state == null ? void 0 : state.state) == null ? void 0 : _a.state) == null ? void 0 : _b.token;
18
+ if (token) {
19
+ config.headers.Authorization = `Bearer ${token}`;
20
+ }
21
+ return config;
22
+ },
23
+ (error) => {
24
+ return Promise.reject(error);
25
+ }
26
+ );
27
+ var baseAxios_default = baseAxios;
28
+
29
+ // src/hooks/useLoadConfig.ts
30
+ import { useEffect } from "react";
31
+ var useLoadConfig = () => {
32
+ useEffect(() => {
33
+ (async () => {
34
+ try {
35
+ const res = await fetch("/config.json");
36
+ const config = await res.json();
37
+ if (config.baseURL) {
38
+ baseAxios_default.defaults.baseURL = config.baseURL;
39
+ console.log("\u2705 baseURL set to", config.baseURL);
40
+ }
41
+ } catch (err) {
42
+ console.error("\u274C L\u1ED7i khi load config.json:", err);
43
+ }
44
+ })();
45
+ }, []);
46
+ };
47
+
48
+ // src/hooks/custom-hooks/createBaseApi.ts
49
+ function createBaseApi(baseUrl) {
50
+ return {
51
+ getAll: () => {
52
+ return baseAxios_default.get(`${baseUrl}/GetAll`);
53
+ },
54
+ getById: (id) => {
55
+ return baseAxios_default.get(`${baseUrl}/${id}`);
56
+ },
57
+ create: (data) => {
58
+ return baseAxios_default.post(`${baseUrl}/create`, data);
59
+ },
60
+ update: (data) => {
61
+ return baseAxios_default.put(`${baseUrl}/update`, data);
62
+ },
63
+ createOrUpdate: (data) => {
64
+ return baseAxios_default.put(`${baseUrl}/createOrUpdate`, data);
65
+ },
66
+ delete: (id) => {
67
+ return baseAxios_default.post(`${baseUrl}/delete`, { id });
68
+ }
69
+ };
70
+ }
71
+
72
+ // src/hooks/custom-hooks/useC_MutationAction.tsx
73
+ import { useQueryClient } from "@tanstack/react-query";
74
+
75
+ // src/hooks/custom-hooks/useMyReactMutation.ts
76
+ import { useMutation } from "@tanstack/react-query";
77
+ function useMyReactMutation({
78
+ axiosFn,
79
+ options
80
+ }) {
81
+ return useMutation(__spreadValues({
82
+ mutationFn: async (variables) => {
83
+ const res = await axiosFn(variables);
84
+ if (res.data.isSuccess == 0) throw new Error(res.data.message);
85
+ return res.data.data;
86
+ }
87
+ }, options));
88
+ }
89
+
90
+ // src/hooks/custom-hooks/useMyReactQuery.ts
91
+ import { useQuery } from "@tanstack/react-query";
92
+
93
+ // src/hooks/query/AQ/useQ_AQ_GetAQModule.ts
94
+ import { useQuery as useQuery2 } from "@tanstack/react-query";
95
+ function useQ_AQ_GetAQModule() {
96
+ const query = useQuery2({
97
+ queryKey: ["/AQ/GetAQModule"],
98
+ queryFn: async () => {
99
+ const res = await baseAxios_default.get("/AQ/GetAQModule");
100
+ return res.data.data;
101
+ }
102
+ });
103
+ return query;
104
+ }
105
+
106
+ // src/hooks/query/SkillCenter/useQ_SkillCenter_GetAll.ts
107
+ import { useQuery as useQuery3 } from "@tanstack/react-query";
108
+ function useQ_SkillCenter_GetAll() {
109
+ const query = useQuery3({
110
+ queryKey: [],
111
+ queryFn: async () => {
112
+ const res = await baseAxios_default.get("/SkillCenter/GetAll");
113
+ return res.data.data;
114
+ }
115
+ });
116
+ return query;
117
+ }
118
+
119
+ export {
120
+ baseAxios_default,
121
+ useQ_AQ_GetAQModule,
122
+ useLoadConfig,
123
+ createBaseApi,
124
+ useMyReactMutation,
125
+ useQ_SkillCenter_GetAll
126
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  baseAxios_default,
3
3
  useQ_AQ_GetAQModule
4
- } from "./chunk-QR4NSLBN.mjs";
4
+ } from "./chunk-5X2EYQ3O.mjs";
5
5
  import {
6
6
  createGenericStore
7
7
  } from "./chunk-Y3YGC5IH.mjs";
@@ -66,8 +66,8 @@ import {
66
66
  useS_BasicAppShell,
67
67
  useS_ButtonImport,
68
68
  utils_layout_getItemsWithoutLinks
69
- } from "../chunk-KTGRWET4.mjs";
70
- import "../chunk-QR4NSLBN.mjs";
69
+ } from "../chunk-KUWSCD5R.mjs";
70
+ import "../chunk-5X2EYQ3O.mjs";
71
71
  import "../chunk-Y3YGC5IH.mjs";
72
72
  import "../chunk-5U2JSHSJ.mjs";
73
73
  import "../chunk-7ZCOFATU.mjs";
@@ -1,6 +1,31 @@
1
+ import * as axios from 'axios';
2
+ import { AxiosResponse } from 'axios';
1
3
  import * as _tanstack_react_query from '@tanstack/react-query';
4
+ import { UseMutationOptions } from '@tanstack/react-query';
2
5
  import { I as IAQModule } from '../IAQModule-XZYlbivW.mjs';
3
6
 
7
+ declare const useLoadConfig: () => void;
8
+
9
+ interface MyApiResponse<IRes> {
10
+ isSuccess: 1 | 0;
11
+ message: string;
12
+ data: IRes;
13
+ }
14
+ declare function createBaseApi<T>(baseUrl: string): {
15
+ getAll: () => Promise<axios.AxiosResponse<MyApiResponse<T[]>, any>>;
16
+ getById: (id: number | string) => Promise<axios.AxiosResponse<MyApiResponse<T>, any>>;
17
+ create: (data: Partial<T>) => Promise<axios.AxiosResponse<MyApiResponse<T>, any>>;
18
+ update: (data: Partial<T>) => Promise<axios.AxiosResponse<MyApiResponse<T>, any>>;
19
+ createOrUpdate: (data: Partial<T>) => Promise<axios.AxiosResponse<MyApiResponse<T>, any>>;
20
+ delete: (id: number) => Promise<axios.AxiosResponse<any, any>>;
21
+ };
22
+
23
+ interface MyReactMutationProps<IReq, IRes> {
24
+ axiosFn: (variables: IReq) => Promise<AxiosResponse<MyApiResponse<IRes>>>;
25
+ options?: UseMutationOptions<IRes, Error, IReq>;
26
+ }
27
+ declare function useMyReactMutation<IReq, IRes>({ axiosFn, options, }: MyReactMutationProps<IReq, IRes>): _tanstack_react_query.UseMutationResult<IRes, Error, IReq, unknown>;
28
+
4
29
  declare function useQ_AQ_GetAQModule(): _tanstack_react_query.UseQueryResult<IAQModule, Error>;
5
30
 
6
- export { useQ_AQ_GetAQModule };
31
+ export { type MyApiResponse, createBaseApi, useLoadConfig, useMyReactMutation, useQ_AQ_GetAQModule };
@@ -1,8 +1,14 @@
1
1
  import {
2
+ createBaseApi,
3
+ useLoadConfig,
4
+ useMyReactMutation,
2
5
  useQ_AQ_GetAQModule
3
- } from "../chunk-QR4NSLBN.mjs";
6
+ } from "../chunk-5X2EYQ3O.mjs";
4
7
  import "../chunk-7ZCOFATU.mjs";
5
8
  import "../chunk-FWCSY2DS.mjs";
6
9
  export {
10
+ createBaseApi,
11
+ useLoadConfig,
12
+ useMyReactMutation,
7
13
  useQ_AQ_GetAQModule
8
14
  };
@@ -25,12 +25,12 @@ import {
25
25
  useS_BasicAppShell,
26
26
  useS_authenticate,
27
27
  utils_layout_getItemsWithoutLinks
28
- } from "../chunk-KTGRWET4.mjs";
28
+ } from "../chunk-KUWSCD5R.mjs";
29
29
  import {
30
30
  baseAxios_default,
31
31
  useQ_AQ_GetAQModule,
32
32
  useQ_SkillCenter_GetAll
33
- } from "../chunk-QR4NSLBN.mjs";
33
+ } from "../chunk-5X2EYQ3O.mjs";
34
34
  import {
35
35
  createGenericStore
36
36
  } from "../chunk-Y3YGC5IH.mjs";
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "types": "./dist/hooks/index.d.mts"
23
23
  }
24
24
  },
25
- "version": "0.1.202",
25
+ "version": "0.1.204",
26
26
  "private": false,
27
27
  "files": [
28
28
  "dist"
@@ -76,6 +76,7 @@
76
76
  "@tiptap/starter-kit": "^2.9.1",
77
77
  "autoprefixer": "^10.4.20",
78
78
  "axios": "^1.7.7",
79
+ "caniuse-lite": "^1.0.30001718",
79
80
  "clsx": "^2.1.1",
80
81
  "dayjs": "^1.11.13",
81
82
  "docxtemplater": "^3.54.1",
@@ -1,70 +0,0 @@
1
- // src/hooks/custom-hooks/useC_MutationAction.tsx
2
- import { useQueryClient } from "@tanstack/react-query";
3
-
4
- // src/api/baseAxios.ts
5
- import axios from "axios";
6
- var baseAxios = axios.create();
7
- (async function loadConfig() {
8
- try {
9
- const response = await fetch("/config.json");
10
- if (response.ok) {
11
- const data = await response.json();
12
- if (data.baseURL) {
13
- baseAxios.defaults.baseURL = data.baseURL;
14
- console.log("\u2705 baseURL set to:", data.baseURL);
15
- } else {
16
- console.warn("\u26A0\uFE0F baseURL kh\xF4ng c\xF3 trong config.json");
17
- }
18
- } else {
19
- console.error("\u274C Kh\xF4ng load \u0111\u01B0\u1EE3c config.json");
20
- }
21
- } catch (error) {
22
- console.error("\u274C L\u1ED7i khi t\u1EA3i config.json", error);
23
- }
24
- })();
25
- baseAxios.interceptors.request.use(
26
- (config) => {
27
- var _a, _b;
28
- const tokenData = localStorage.getItem("useS_authenticate");
29
- const state = tokenData ? JSON.parse(tokenData) : null;
30
- const token = (_b = (_a = state == null ? void 0 : state.state) == null ? void 0 : _a.state) == null ? void 0 : _b.token;
31
- if (token) {
32
- config.headers.Authorization = `Bearer ${token}`;
33
- }
34
- return config;
35
- },
36
- (error) => Promise.reject(error)
37
- );
38
- var baseAxios_default = baseAxios;
39
-
40
- // src/hooks/query/AQ/useQ_AQ_GetAQModule.ts
41
- import { useQuery } from "@tanstack/react-query";
42
- function useQ_AQ_GetAQModule() {
43
- const query = useQuery({
44
- queryKey: ["/AQ/GetAQModule"],
45
- queryFn: async () => {
46
- const res = await baseAxios_default.get("/AQ/GetAQModule");
47
- return res.data.data;
48
- }
49
- });
50
- return query;
51
- }
52
-
53
- // src/hooks/query/SkillCenter/useQ_SkillCenter_GetAll.ts
54
- import { useQuery as useQuery2 } from "@tanstack/react-query";
55
- function useQ_SkillCenter_GetAll() {
56
- const query = useQuery2({
57
- queryKey: [],
58
- queryFn: async () => {
59
- const res = await baseAxios_default.get("/SkillCenter/GetAll");
60
- return res.data.data;
61
- }
62
- });
63
- return query;
64
- }
65
-
66
- export {
67
- baseAxios_default,
68
- useQ_AQ_GetAQModule,
69
- useQ_SkillCenter_GetAll
70
- };