aq-fe-framework 0.1.954 → 0.1.955

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.
package/README.md CHANGED
@@ -1 +1 @@
1
- # aq-edu-coe
1
+ # aq-fe-framework
@@ -57,4 +57,4 @@ interface IRole extends IBaseEntity {
57
57
  aqModuleId?: number;
58
58
  }
59
59
 
60
- export type { AcademicYearUpdateDto as A, IAcademicYear as I, IEmailTemplate as a, IEmailConfig as b, IRole as c };
60
+ export type { AcademicYearUpdateDto as A, IAcademicYear as I, IEmailConfig as a, IEmailTemplate as b, IRole as c };
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ActionIconProps, ButtonProps, ModalProps, TooltipProps } from '@mantine/core';
3
3
  import { useDisclosure } from '@mantine/hooks';
4
4
  import { ReactNode } from 'react';
5
- import { t as type_action } from './types-BUAQG6lt.mjs';
5
+ import { t as type_action } from './type_action-BVoqAHLZ.mjs';
6
6
  import { MRT_RowData, MRT_TableOptions, MRT_ColumnDef } from 'mantine-react-table';
7
7
 
8
8
  interface MyActionIconProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "color" | "style">, ActionIconProps {
@@ -0,0 +1,68 @@
1
+ import * as zustand from 'zustand';
2
+ import * as axios from 'axios';
3
+
4
+ declare function createBaseUrl(baseUrl: string): {
5
+ get: string;
6
+ getAll: string;
7
+ create: string;
8
+ update: string;
9
+ updateList: string;
10
+ createOrUpdateList: string;
11
+ delete: string;
12
+ deleteList: string;
13
+ };
14
+
15
+ interface GenericStore<T> {
16
+ state: T;
17
+ setState: (newState: T) => void;
18
+ setProperty: <K extends keyof T>(key: K, value: T[K]) => void;
19
+ resetState: () => void;
20
+ }
21
+ declare function createGenericStore<T>({ initialState, storageKey }: {
22
+ initialState: T;
23
+ storageKey?: string;
24
+ }): zustand.UseBoundStore<zustand.StoreApi<GenericStore<T>>>;
25
+
26
+ interface Mapper<UI, API> {
27
+ toUi: (raw: API) => UI;
28
+ toApi: (item: Partial<UI>, currentApi?: Partial<API>) => Partial<API>;
29
+ }
30
+ type FieldMapping<UIField, API> = (keyof API & string) | {
31
+ toUi: (raw: API) => UIField;
32
+ toApi: (val: UIField, currentApi: Partial<API>) => Partial<API>;
33
+ };
34
+ declare function createMapper<UI, API>(fieldMap: {
35
+ [K in keyof UI]: FieldMapping<UI[K], API>;
36
+ }): Mapper<UI, API>;
37
+
38
+ declare const baseAxios: axios.AxiosInstance;
39
+
40
+ type CrudApi<UI, API> = {
41
+ getAll: () => Promise<UI[]>;
42
+ getById: (id: string) => Promise<UI>;
43
+ create: (item: Partial<UI>) => Promise<UI>;
44
+ update: (id: string, item: Partial<UI>) => Promise<UI>;
45
+ delete: (id: string) => Promise<void>;
46
+ };
47
+ declare function createRepository<UI, API, Extra extends Record<string, any> = {}>(baseUrl: string, mapper: Mapper<UI, API>, extra?: (axios: typeof baseAxios) => Extra): CrudApi<UI, API> & Extra;
48
+
49
+ interface ITenantSetting<TKey = string> {
50
+ settingKey?: TKey;
51
+ settingValue?: string | boolean | number;
52
+ description?: string;
53
+ }
54
+ interface IStoreState<TKey = string> {
55
+ tenantSettings?: ITenantSetting<TKey>[];
56
+ }
57
+ declare function createTenantSettingsStore<TKey>(params: {
58
+ storageKey?: string;
59
+ initialState?: Partial<IStoreState<TKey>>;
60
+ }): () => {
61
+ getSetting: (settingKey: TKey) => string | boolean | number | undefined;
62
+ state: IStoreState<TKey>;
63
+ setState: (newState: IStoreState<TKey>) => void;
64
+ setProperty: <K extends "tenantSettings">(key: K, value: IStoreState<TKey>[K]) => void;
65
+ resetState: () => void;
66
+ };
67
+
68
+ export { type IStoreState, type ITenantSetting, type Mapper, createBaseUrl, createGenericStore, createMapper, createRepository, createTenantSettingsStore };
@@ -0,0 +1,110 @@
1
+ import {
2
+ createGenericStore,
3
+ createGenericStore2
4
+ } from "../chunk-YGWSHSTG.mjs";
5
+ import {
6
+ baseAxios_default
7
+ } from "../chunk-YWANA62C.mjs";
8
+ import {
9
+ __spreadProps,
10
+ __spreadValues
11
+ } from "../chunk-JD6AELXS.mjs";
12
+
13
+ // src/build-object/createBaseUrl.ts
14
+ function createBaseUrl(baseUrl) {
15
+ return {
16
+ get: `${baseUrl}/get`,
17
+ getAll: `${baseUrl}/GetAll`,
18
+ create: `${baseUrl}/create`,
19
+ update: `${baseUrl}/update`,
20
+ updateList: `${baseUrl}/updateList`,
21
+ createOrUpdateList: `${baseUrl}/createOrUpdateList`,
22
+ delete: `${baseUrl}/delete`,
23
+ deleteList: `${baseUrl}/deleteList`
24
+ };
25
+ }
26
+
27
+ // src/build-object/createMapper.ts
28
+ function createMapper(fieldMap) {
29
+ const toUi = (raw) => {
30
+ const result = {};
31
+ Object.entries(fieldMap).forEach(
32
+ ([uiKey, mapping]) => {
33
+ if (typeof mapping === "string") {
34
+ result[uiKey] = raw[mapping];
35
+ } else {
36
+ result[uiKey] = mapping.toUi(raw);
37
+ }
38
+ }
39
+ );
40
+ return result;
41
+ };
42
+ const toApi = (ui, base = {}) => {
43
+ const result = __spreadValues({}, base);
44
+ Object.entries(fieldMap).forEach(
45
+ ([uiKey, mapping]) => {
46
+ const value = ui[uiKey];
47
+ if (value === void 0) return;
48
+ if (typeof mapping === "string") {
49
+ result[mapping] = value;
50
+ } else {
51
+ Object.assign(result, mapping.toApi(value, result));
52
+ }
53
+ }
54
+ );
55
+ return result;
56
+ };
57
+ return { toUi, toApi };
58
+ }
59
+
60
+ // src/build-object/createRepository.ts
61
+ function createRepository(baseUrl, mapper, extra) {
62
+ const base = {
63
+ async getAll() {
64
+ const { data } = await baseAxios_default.get(baseUrl);
65
+ return data.map(mapper.toUi);
66
+ },
67
+ async getById(id) {
68
+ const { data } = await baseAxios_default.get(`${baseUrl}/${id}`);
69
+ return mapper.toUi(data);
70
+ },
71
+ async create(item) {
72
+ const { data } = await baseAxios_default.post(baseUrl, mapper.toApi(item));
73
+ return mapper.toUi(data);
74
+ },
75
+ async update(id, item) {
76
+ const { data } = await baseAxios_default.put(`${baseUrl}/${id}`, mapper.toApi(item));
77
+ return mapper.toUi(data);
78
+ },
79
+ async delete(id) {
80
+ await baseAxios_default.delete(`${baseUrl}/${id}`);
81
+ }
82
+ };
83
+ const custom = extra ? extra(baseAxios_default) : {};
84
+ return __spreadValues(__spreadValues({}, base), custom);
85
+ }
86
+
87
+ // src/build-object/createTenantSettingsStore.ts
88
+ function createTenantSettingsStore(params) {
89
+ const useStore = createGenericStore2({
90
+ initialState: params.initialState || {},
91
+ storageKey: params.storageKey || "useStore_TenantSettings"
92
+ });
93
+ return function useTenantSettingsStore() {
94
+ const store = useStore();
95
+ function getSetting(settingKey) {
96
+ var _a, _b;
97
+ return (_b = (_a = store.state.tenantSettings) == null ? void 0 : _a.find((s) => s.settingKey === settingKey)) == null ? void 0 : _b.settingValue;
98
+ }
99
+ return __spreadProps(__spreadValues({}, store), {
100
+ getSetting
101
+ });
102
+ };
103
+ }
104
+ export {
105
+ createBaseUrl,
106
+ createGenericStore,
107
+ createMapper,
108
+ createRepository,
109
+ createTenantSettingsStore
110
+ };
@@ -355,6 +355,45 @@ function utils_list_sumField(list, field) {
355
355
  return list.reduce((sum, item) => sum + Number(item[field]), 0);
356
356
  }
357
357
 
358
+ // src/utils/utils_notification.ts
359
+ import { notifications } from "@mantine/notifications";
360
+ function utils_notification_show({ crudType = "create", message, color }) {
361
+ if (crudType == "create") {
362
+ notifications.show({
363
+ message: message ? message : "Th\xEAm th\xE0nh c\xF4ng!",
364
+ color: color ? color : "green"
365
+ });
366
+ return;
367
+ }
368
+ if (crudType == "update") {
369
+ notifications.show({
370
+ message: message ? message : "C\u1EADp nh\u1EADt th\xE0nh c\xF4ng!",
371
+ color: color ? color : "green"
372
+ });
373
+ return;
374
+ }
375
+ if (crudType == "delete") {
376
+ notifications.show({
377
+ message: message ? message : "X\xF3a th\xE0nh c\xF4ng!",
378
+ color: color ? color : "green"
379
+ });
380
+ return;
381
+ }
382
+ if (crudType == "error") {
383
+ notifications.show({
384
+ message: message ? message : "L\u1ED7i!",
385
+ color: color ? color : "red"
386
+ });
387
+ return;
388
+ }
389
+ if (crudType == "importSucess") {
390
+ notifications.show({
391
+ message: message ? message : "Import th\xE0nh c\xF4ng!"
392
+ });
393
+ return;
394
+ }
395
+ }
396
+
358
397
  // src/utils/utils_pdf.ts
359
398
  import axios from "axios";
360
399
  async function utils_pdf_download(url) {
@@ -440,6 +479,7 @@ var utils_validator_validateCode = (value) => {
440
479
 
441
480
  export {
442
481
  utils_pdf_download,
482
+ utils_notification_show,
443
483
  utils_excel_exportExcel,
444
484
  utils_excel_download,
445
485
  utils_excel_parseToJson,
@@ -0,0 +1,31 @@
1
+ import {
2
+ createGenericStore
3
+ } from "./chunk-YGWSHSTG.mjs";
4
+ import {
5
+ __spreadValues
6
+ } from "./chunk-JD6AELXS.mjs";
7
+
8
+ // src/stores/useStore_Permission.ts
9
+ var useStore = createGenericStore({
10
+ initialState: {},
11
+ storageKey: "useStore_Permission"
12
+ });
13
+ function useStore_Permission() {
14
+ const store = useStore();
15
+ return __spreadValues({}, store);
16
+ }
17
+
18
+ // src/stores/useStore_ProjectInfo.ts
19
+ var useStore2 = createGenericStore({
20
+ initialState: {},
21
+ storageKey: "useStore_ProjectInfo"
22
+ });
23
+ function useStore_ProjectInfo() {
24
+ const store = useStore2();
25
+ return __spreadValues({}, store);
26
+ }
27
+
28
+ export {
29
+ useStore_Permission,
30
+ useStore_ProjectInfo
31
+ };
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  typeLabel_mutation
3
3
  } from "./chunk-WZ6PXGGC.mjs";
4
+ import {
5
+ baseAxios_default
6
+ } from "./chunk-YWANA62C.mjs";
4
7
  import {
5
8
  __spreadProps,
6
9
  __spreadValues
@@ -8,7 +11,7 @@ import {
8
11
 
9
12
  // src/hooks/useEditableRows.ts
10
13
  import { useState } from "react";
11
- function useEditableRows({ initValues = [], rowKey = "id" }) {
14
+ function useEditableRows({ initValues = [], rowKey = "id" } = {}) {
12
15
  const [editedRows, setEditedRows] = useState(initValues);
13
16
  const handleFieldChange = (row, field, value) => {
14
17
  setEditedRows((prev) => {
@@ -337,30 +340,6 @@ function useCrudService(service, queryKey) {
337
340
  };
338
341
  }
339
342
 
340
- // src/api/config/baseAxios.ts
341
- import axios from "axios";
342
- var baseAxios = axios.create({
343
- baseURL: ""
344
- // server
345
- // baseURL: process.env.NEXT_PUBLIC_API_LOCAL, // local debug
346
- });
347
- baseAxios.interceptors.request.use(
348
- (config) => {
349
- var _a, _b;
350
- const tokenData = localStorage.getItem("useStore_Authenticate");
351
- const state = JSON.parse(tokenData);
352
- const token = (_b = (_a = state == null ? void 0 : state.state) == null ? void 0 : _a.state) == null ? void 0 : _b.token;
353
- if (token) {
354
- config.headers.Authorization = `Bearer ${token}`;
355
- }
356
- return config;
357
- },
358
- (error) => {
359
- return Promise.reject(error);
360
- }
361
- );
362
- var baseAxios_default = baseAxios;
363
-
364
343
  // src/hooks/custom-hooks/useLoadAxiosConfig.ts
365
344
  import { useEffect as useEffect2, useState as useState3 } from "react";
366
345
  var useLoadAxiosConfig = ({
@@ -388,9 +367,6 @@ var useLoadAxiosConfig = ({
388
367
  return { flag, setFlag };
389
368
  };
390
369
 
391
- // src/hooks/custom-hooks/useMutationAction.tsx
392
- import { useQueryClient as useQueryClient2 } from "@tanstack/react-query";
393
-
394
370
  // src/hooks/query/AQ/useQ_AQ_GetAQModule.ts
395
371
  import { useQuery as useQuery3 } from "@tanstack/react-query";
396
372
  function useQ_AQ_GetAQModule() {
@@ -422,7 +398,6 @@ export {
422
398
  useMyReactMutation,
423
399
  useMyReactQuery,
424
400
  useCrudService,
425
- baseAxios_default,
426
401
  useLoadAxiosConfig,
427
402
  useQ_AQ_GetAQModule
428
403
  };