@nomos-ui/uanela-redux-next 0.0.2

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.
Files changed (90) hide show
  1. package/README.md +1 -0
  2. package/dist/apis/auth.api.d.ts +2 -0
  3. package/dist/apis/auth.api.d.ts.map +1 -0
  4. package/dist/apis/auth.api.js +108 -0
  5. package/dist/apis/auth.api.js.map +1 -0
  6. package/dist/components/api-provider.d.ts +51 -0
  7. package/dist/components/api-provider.d.ts.map +1 -0
  8. package/dist/components/api-provider.js +60 -0
  9. package/dist/components/api-provider.js.map +1 -0
  10. package/dist/components/data-manipulation/create-data-wrapper.d.ts +69 -0
  11. package/dist/components/data-manipulation/create-data-wrapper.d.ts.map +1 -0
  12. package/dist/components/data-manipulation/create-data-wrapper.js +65 -0
  13. package/dist/components/data-manipulation/create-data-wrapper.js.map +1 -0
  14. package/dist/components/data-manipulation/update-data-wrapper.d.ts +91 -0
  15. package/dist/components/data-manipulation/update-data-wrapper.d.ts.map +1 -0
  16. package/dist/components/data-manipulation/update-data-wrapper.js +85 -0
  17. package/dist/components/data-manipulation/update-data-wrapper.js.map +1 -0
  18. package/dist/components/modals/create.modal.d.ts +71 -0
  19. package/dist/components/modals/create.modal.d.ts.map +1 -0
  20. package/dist/components/modals/create.modal.js +51 -0
  21. package/dist/components/modals/create.modal.js.map +1 -0
  22. package/dist/components/modals/update.modal.d.ts +71 -0
  23. package/dist/components/modals/update.modal.d.ts.map +1 -0
  24. package/dist/components/modals/update.modal.js +51 -0
  25. package/dist/components/modals/update.modal.js.map +1 -0
  26. package/dist/components/pages/components/page-title-and-description.d.ts +6 -0
  27. package/dist/components/pages/components/page-title-and-description.d.ts.map +1 -0
  28. package/dist/components/pages/components/page-title-and-description.js +8 -0
  29. package/dist/components/pages/components/page-title-and-description.js.map +1 -0
  30. package/dist/components/pages/create-data-page/index.d.ts +25 -0
  31. package/dist/components/pages/create-data-page/index.d.ts.map +1 -0
  32. package/dist/components/pages/create-data-page/index.js +22 -0
  33. package/dist/components/pages/create-data-page/index.js.map +1 -0
  34. package/dist/components/pages/list-page/header-action-buttons.d.ts +7 -0
  35. package/dist/components/pages/list-page/header-action-buttons.d.ts.map +1 -0
  36. package/dist/components/pages/list-page/header-action-buttons.js +20 -0
  37. package/dist/components/pages/list-page/header-action-buttons.js.map +1 -0
  38. package/dist/components/pages/list-page/list-page.d.ts +19 -0
  39. package/dist/components/pages/list-page/list-page.d.ts.map +1 -0
  40. package/dist/components/pages/list-page/list-page.js +17 -0
  41. package/dist/components/pages/list-page/list-page.js.map +1 -0
  42. package/dist/components/pages/list-page/table/action-button.d.ts +12 -0
  43. package/dist/components/pages/list-page/table/action-button.d.ts.map +1 -0
  44. package/dist/components/pages/list-page/table/action-button.js +15 -0
  45. package/dist/components/pages/list-page/table/action-button.js.map +1 -0
  46. package/dist/components/pages/list-page/table/confirm-delete.modal.d.ts +6 -0
  47. package/dist/components/pages/list-page/table/confirm-delete.modal.d.ts.map +1 -0
  48. package/dist/components/pages/list-page/table/confirm-delete.modal.js +16 -0
  49. package/dist/components/pages/list-page/table/confirm-delete.modal.js.map +1 -0
  50. package/dist/components/pages/list-page/table/table-data.d.ts +27 -0
  51. package/dist/components/pages/list-page/table/table-data.d.ts.map +1 -0
  52. package/dist/components/pages/list-page/table/table-data.js +57 -0
  53. package/dist/components/pages/list-page/table/table-data.js.map +1 -0
  54. package/dist/components/pages/list-page/table/table.d.ts +43 -0
  55. package/dist/components/pages/list-page/table/table.d.ts.map +1 -0
  56. package/dist/components/pages/list-page/table/table.js +99 -0
  57. package/dist/components/pages/list-page/table/table.js.map +1 -0
  58. package/dist/components/pages/list-page/table/types/index.d.ts +54 -0
  59. package/dist/components/pages/list-page/table/types/index.d.ts.map +1 -0
  60. package/dist/components/pages/list-page/table/types/index.js +3 -0
  61. package/dist/components/pages/list-page/table/types/index.js.map +1 -0
  62. package/dist/components/pages/list-page/template.d.ts +31 -0
  63. package/dist/components/pages/list-page/template.d.ts.map +1 -0
  64. package/dist/components/pages/list-page/template.js +174 -0
  65. package/dist/components/pages/list-page/template.js.map +1 -0
  66. package/dist/components/pages/update-data-page/index.d.ts +25 -0
  67. package/dist/components/pages/update-data-page/index.d.ts.map +1 -0
  68. package/dist/components/pages/update-data-page/index.js +24 -0
  69. package/dist/components/pages/update-data-page/index.js.map +1 -0
  70. package/dist/components/query-boundary.d.ts +81 -0
  71. package/dist/components/query-boundary.d.ts.map +1 -0
  72. package/dist/components/query-boundary.js +121 -0
  73. package/dist/components/query-boundary.js.map +1 -0
  74. package/dist/components/server/server-query-boundary.d.ts +23 -0
  75. package/dist/components/server/server-query-boundary.d.ts.map +1 -0
  76. package/dist/components/server/server-query-boundary.js +36 -0
  77. package/dist/components/server/server-query-boundary.js.map +1 -0
  78. package/dist/exports/index.d.ts +11 -0
  79. package/dist/exports/index.d.ts.map +1 -0
  80. package/dist/exports/index.js +55 -0
  81. package/dist/exports/index.js.map +1 -0
  82. package/dist/hooks/use-update-search-params.d.ts +5 -0
  83. package/dist/hooks/use-update-search-params.d.ts.map +1 -0
  84. package/dist/hooks/use-update-search-params.js +13 -0
  85. package/dist/hooks/use-update-search-params.js.map +1 -0
  86. package/dist/types/index.d.ts +26 -0
  87. package/dist/types/index.d.ts.map +1 -0
  88. package/dist/types/index.js +3 -0
  89. package/dist/types/index.js.map +1 -0
  90. package/package.json +76 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ This package is made by Uanela for Uanela ;)
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=auth.api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.api.d.ts","sourceRoot":"","sources":["../../src/apis/auth.api.ts"],"names":[],"mappings":""}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ // import { createApi } from "@reduxjs/toolkit/query/react";
3
+ // // import { toastError } from "../helpers/toast.helpers";
4
+ // import baseQuery from "../utils/base-query";
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ // // Create a separate API instance for auth
7
+ // export const authApi = createApi({
8
+ // reducerPath: "authApi",
9
+ // baseQuery,
10
+ // tagTypes: ["user"],
11
+ // endpoints: (builder) => ({
12
+ // getMe: builder.query({
13
+ // query: () => "/users/me",
14
+ // transformErrorResponse: (res) => {
15
+ // return res;
16
+ // },
17
+ // providesTags: (result, err, arg) => {
18
+ // return err ? [] : [{ type: "user", id: "me" }];
19
+ // },
20
+ // }),
21
+ // updateMe: builder.mutation({
22
+ // query: (body) => ({
23
+ // url: `/users/me`,
24
+ // method: "PATCH",
25
+ // body: body,
26
+ // }),
27
+ // invalidatesTags: (result, err, arg) =>
28
+ // err ? [] : [{ type: "user", id: "me" }],
29
+ // }),
30
+ // login: builder.mutation({
31
+ // query: (credentials) => ({
32
+ // url: "/auth/login",
33
+ // method: "POST",
34
+ // body: credentials,
35
+ // }),
36
+ // transformResponse: async (res, meta, arg) => {
37
+ // // if (res?.accessToken)
38
+ // // await secureStore.setItemAsync("accessToken", res.accessToken);
39
+ // // else throw new Error("Nenhum token de acesso retornado!");
40
+ // return res;
41
+ // },
42
+ // transformErrorResponse: (res, meta, args) => {
43
+ // if (res.status === 401) {
44
+ // // toastError(
45
+ // // "Email ou palavra-passe errada, por favor digite dados corretos!"
46
+ // // );
47
+ // } else {
48
+ // // toastError(
49
+ // // "Ocorreu um erro fazendo o login, por favor tente novamente!"
50
+ // // );
51
+ // }
52
+ // return res;
53
+ // },
54
+ // invalidatesTags: (result, err, args) => {
55
+ // return err ? [] : [{ type: "user", id: "me" }];
56
+ // },
57
+ // }),
58
+ // logout: builder.mutation({
59
+ // query: () => ({
60
+ // url: "/auth/logout",
61
+ // method: "DELETE",
62
+ // }),
63
+ // invalidatesTags: (result, err, args) => {
64
+ // if (err) return [];
65
+ // return [{ type: "user", id: "me" }];
66
+ // },
67
+ // }),
68
+ // signup: builder.mutation({
69
+ // query: (data) => ({
70
+ // url: "/auth/signup",
71
+ // method: "POST",
72
+ // body: data,
73
+ // }),
74
+ // invalidatesTags: (result, err, args) => {
75
+ // return err ? [] : [{ type: "user", id: "me" }];
76
+ // },
77
+ // }),
78
+ // verifyEmail: builder.mutation({
79
+ // query: (data) => ({
80
+ // url: "/auth/signup",
81
+ // method: "PATCH",
82
+ // body: data,
83
+ // }),
84
+ // invalidatesTags: (result, err, args) => {
85
+ // return err ? [] : [{ type: "user", id: "me" }];
86
+ // },
87
+ // }),
88
+ // forgotPassword: builder.mutation({
89
+ // query: (data) => ({
90
+ // url: "/auth/forgot-password",
91
+ // method: "POST",
92
+ // body: data,
93
+ // }),
94
+ // }),
95
+ // resetPassword: builder.mutation({
96
+ // query: (data) => ({
97
+ // url: "/auth/reset-password",
98
+ // method: "POST",
99
+ // body: data,
100
+ // }),
101
+ // invalidatesTags: (result, err, args) => {
102
+ // return err ? [] : [{ type: "user", id: "me" }];
103
+ // },
104
+ // }),
105
+ // }),
106
+ // });
107
+ // export default authApi;
108
+ //# sourceMappingURL=auth.api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.api.js","sourceRoot":"","sources":["../../src/apis/auth.api.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,4DAA4D;AAC5D,+CAA+C;;AAE/C,6CAA6C;AAC7C,qCAAqC;AACrC,4BAA4B;AAC5B,eAAe;AACf,wBAAwB;AACxB,+BAA+B;AAC/B,6BAA6B;AAC7B,kCAAkC;AAClC,2CAA2C;AAC3C,sBAAsB;AACtB,WAAW;AACX,8CAA8C;AAC9C,0DAA0D;AAC1D,WAAW;AACX,UAAU;AACV,mCAAmC;AACnC,4BAA4B;AAC5B,4BAA4B;AAC5B,2BAA2B;AAC3B,sBAAsB;AACtB,YAAY;AACZ,+CAA+C;AAC/C,mDAAmD;AACnD,UAAU;AACV,gCAAgC;AAChC,mCAAmC;AACnC,8BAA8B;AAC9B,0BAA0B;AAC1B,6BAA6B;AAC7B,YAAY;AACZ,uDAAuD;AACvD,mCAAmC;AACnC,+EAA+E;AAC/E,wEAAwE;AACxE,sBAAsB;AACtB,WAAW;AACX,uDAAuD;AACvD,oCAAoC;AACpC,2BAA2B;AAC3B,mFAAmF;AACnF,kBAAkB;AAClB,mBAAmB;AACnB,2BAA2B;AAC3B,+EAA+E;AAC/E,kBAAkB;AAClB,YAAY;AACZ,sBAAsB;AACtB,WAAW;AACX,kDAAkD;AAClD,0DAA0D;AAC1D,WAAW;AACX,UAAU;AACV,iCAAiC;AACjC,wBAAwB;AACxB,+BAA+B;AAC/B,4BAA4B;AAC5B,YAAY;AACZ,kDAAkD;AAClD,8BAA8B;AAC9B,+CAA+C;AAC/C,WAAW;AACX,UAAU;AACV,iCAAiC;AACjC,4BAA4B;AAC5B,+BAA+B;AAC/B,0BAA0B;AAC1B,sBAAsB;AACtB,YAAY;AACZ,kDAAkD;AAClD,0DAA0D;AAC1D,WAAW;AACX,UAAU;AACV,sCAAsC;AACtC,4BAA4B;AAC5B,+BAA+B;AAC/B,2BAA2B;AAC3B,sBAAsB;AACtB,YAAY;AACZ,kDAAkD;AAClD,0DAA0D;AAC1D,WAAW;AACX,UAAU;AACV,yCAAyC;AACzC,4BAA4B;AAC5B,wCAAwC;AACxC,0BAA0B;AAC1B,sBAAsB;AACtB,YAAY;AACZ,UAAU;AACV,wCAAwC;AACxC,4BAA4B;AAC5B,uCAAuC;AACvC,0BAA0B;AAC1B,sBAAsB;AACtB,YAAY;AACZ,kDAAkD;AAClD,0DAA0D;AAC1D,WAAW;AACX,UAAU;AACV,QAAQ;AACR,MAAM;AAEN,0BAA0B"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Context value containing the RTK Query API instance.
3
+ */
4
+ export type ApiContextValue = {
5
+ /** RTK Query API instance with generated endpoints and hooks */
6
+ api: Record<string, any>;
7
+ };
8
+ /**
9
+ * Provider component that makes the RTK Query API available to all child components.
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * import { api } from './store/api';
14
+ *
15
+ * function App() {
16
+ * return (
17
+ * <ApiProvider api={api}>
18
+ * <YourComponents />
19
+ * </ApiProvider>
20
+ * );
21
+ * }
22
+ * ```
23
+ *
24
+ * @param children - React components that need access to the API
25
+ * @param api - RTK Query API instance created with createApi()
26
+ */
27
+ export default function ApiProvider({ children, api, }: {
28
+ children: React.ReactNode;
29
+ api: any;
30
+ }): import("react/jsx-runtime").JSX.Element;
31
+ /**
32
+ * Hook to access the RTK Query API instance from context.
33
+ * Must be used within an ApiProvider.
34
+ *
35
+ * @example
36
+ * ```tsx
37
+ * function MyComponent() {
38
+ * const { api } = useApi();
39
+ *
40
+ * // Access endpoints
41
+ * const { data } = api.useGetUsersQuery();
42
+ *
43
+ * return <div>{data?.length} users</div>;
44
+ * }
45
+ * ```
46
+ *
47
+ * @throws {Error} If used outside of ApiProvider
48
+ * @returns The API context value containing the RTK Query API instance
49
+ */
50
+ export declare const useApi: () => Record<string, any>;
51
+ //# sourceMappingURL=api-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-provider.d.ts","sourceRoot":"","sources":["../../src/components/api-provider.tsx"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,gEAAgE;IAChE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC1B,CAAC;AAQF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,GAAG,EAAE,GAAG,CAAC;CACV,2CAEA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,MAAM,2BAKlB,CAAC"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useApi = void 0;
4
+ exports.default = ApiProvider;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = require("react");
7
+ /**
8
+ * Context for sharing RTK Query API instance across the component tree.
9
+ * This allows components to access the API without prop drilling.
10
+ */
11
+ const ApiContext = (0, react_1.createContext)({});
12
+ /**
13
+ * Provider component that makes the RTK Query API available to all child components.
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * import { api } from './store/api';
18
+ *
19
+ * function App() {
20
+ * return (
21
+ * <ApiProvider api={api}>
22
+ * <YourComponents />
23
+ * </ApiProvider>
24
+ * );
25
+ * }
26
+ * ```
27
+ *
28
+ * @param children - React components that need access to the API
29
+ * @param api - RTK Query API instance created with createApi()
30
+ */
31
+ function ApiProvider({ children, api, }) {
32
+ return (0, jsx_runtime_1.jsx)(ApiContext.Provider, { value: { api }, children: children });
33
+ }
34
+ /**
35
+ * Hook to access the RTK Query API instance from context.
36
+ * Must be used within an ApiProvider.
37
+ *
38
+ * @example
39
+ * ```tsx
40
+ * function MyComponent() {
41
+ * const { api } = useApi();
42
+ *
43
+ * // Access endpoints
44
+ * const { data } = api.useGetUsersQuery();
45
+ *
46
+ * return <div>{data?.length} users</div>;
47
+ * }
48
+ * ```
49
+ *
50
+ * @throws {Error} If used outside of ApiProvider
51
+ * @returns The API context value containing the RTK Query API instance
52
+ */
53
+ const useApi = () => {
54
+ const context = (0, react_1.useContext)(ApiContext);
55
+ if (!context)
56
+ throw new Error("useApi must be used within ApiProvider");
57
+ return context.api;
58
+ };
59
+ exports.useApi = useApi;
60
+ //# sourceMappingURL=api-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-provider.js","sourceRoot":"","sources":["../../src/components/api-provider.tsx"],"names":[],"mappings":";;;AAmCA,8BAQC;;AA3CD,iCAAkD;AAUlD;;;GAGG;AACH,MAAM,UAAU,GAAG,IAAA,qBAAa,EAAkB,EAAS,CAAC,CAAC;AAE7D;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAwB,WAAW,CAAC,EAClC,QAAQ,EACR,GAAG,GAIJ;IACC,OAAO,uBAAC,UAAU,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,GAAG,EAAE,YAAG,QAAQ,GAAuB,CAAC;AAC/E,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACI,MAAM,MAAM,GAAG,GAAG,EAAE;IACzB,MAAM,OAAO,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;IACvC,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAExE,OAAO,OAAO,CAAC,GAAG,CAAC;AACrB,CAAC,CAAC;AALW,QAAA,MAAM,UAKjB"}
@@ -0,0 +1,69 @@
1
+ import React from "react";
2
+ import { UseFormReturn } from "react-hook-form";
3
+ import { z } from "zod";
4
+ /**
5
+ * Props for the CreateDataWrapper
6
+ */
7
+ type CreateDataWrapperProps = {
8
+ /** Optional ID for the component */
9
+ id?: string;
10
+ /** Name identifier used to generate the API mutation name if not provided */
11
+ name: string;
12
+ /** Form component to render for data creation */
13
+ Form: (props: any) => React.JSX.Element;
14
+ /**
15
+ * Redux API mutation name (e.g., 'useCreateProductMutation')
16
+ * If not provided, will be generated as `useCreate${pascalCase(name)}Mutation`
17
+ */
18
+ createMutation?: string;
19
+ /** Flag to show alert after successful creation */
20
+ showAlertAfterSuccessCreate?: boolean;
21
+ /** Callback function executed after successful data creation */
22
+ doAfterSuccessCreate?: (x: {
23
+ response: any;
24
+ data: any;
25
+ form: UseFormReturn;
26
+ }) => Promise<any> | void;
27
+ /** Function to transform form data before submission */
28
+ cleanDataBeforeCreate?: (data: any) => void;
29
+ /** CSS class name for the component */
30
+ className?: string;
31
+ /** Buttons to be displayed in the top-right corner */
32
+ topButtons?: React.ReactNode;
33
+ /** Props specific to the form component */
34
+ formProps: {
35
+ /** Label for the form's submit button */
36
+ buttonLabel: string;
37
+ /** Optional CSS class name for the form */
38
+ className?: string;
39
+ /** Flag to maintain loading state after submission */
40
+ keepIsLoading?: boolean;
41
+ /** Additional data to be passed to the form */
42
+ requiredData?: Record<string, any>;
43
+ /** Zod schema for form validation */
44
+ schema: z.ZodObject<any>;
45
+ };
46
+ };
47
+ /**
48
+ * A generic component that handles data creation logic using Redux API mutations
49
+ * Manages form submission, data transformation, and post-creation callbacks
50
+ * Also supports template-based default values from Redux state
51
+ *
52
+ * @param props Component props
53
+ * @returns A form component with data creation capabilities
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * <CreateDataWrapper
58
+ * name="product"
59
+ * Form={ProductForm}
60
+ * formProps={{
61
+ * buttonLabel: "Create Product",
62
+ * schema: productSchema
63
+ * }}
64
+ * />
65
+ * ```
66
+ */
67
+ export default function CreateDataWrapper({ name, Form, createMutation, doAfterSuccessCreate, cleanDataBeforeCreate, formProps, }: CreateDataWrapperProps): import("react/jsx-runtime").JSX.Element;
68
+ export {};
69
+ //# sourceMappingURL=create-data-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-data-wrapper.d.ts","sourceRoot":"","sources":["../../../src/components/data-manipulation/create-data-wrapper.tsx"],"names":[],"mappings":"AACA,OAAO,KAAiC,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB;;GAEG;AACH,KAAK,sBAAsB,GAAG;IAC5B,oCAAoC;IACpC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,IAAI,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;IACxC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mDAAmD;IACnD,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC,gEAAgE;IAChE,oBAAoB,CAAC,EAAE,CAAC,CAAC,EAAE;QACzB,QAAQ,EAAE,GAAG,CAAC;QACd,IAAI,EAAE,GAAG,CAAC;QACV,IAAI,EAAE,aAAa,CAAC;KACrB,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAC1B,wDAAwD;IACxD,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAC5C,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sDAAsD;IACtD,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B,2CAA2C;IAC3C,SAAS,EAAE;QACT,yCAAyC;QACzC,WAAW,EAAE,MAAM,CAAC;QACpB,2CAA2C;QAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,sDAAsD;QACtD,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,+CAA+C;QAC/C,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACnC,qCAAqC;QACrC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;KAC1B,CAAC;CACH,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,IAAI,EACJ,IAAI,EACJ,cAAc,EACd,oBAAoB,EACpB,qBAAsC,EACtC,SAAS,GACV,EAAE,sBAAsB,2CAwDxB"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = CreateDataWrapper;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const change_case_all_1 = require("change-case-all");
6
+ const react_1 = require("react");
7
+ const navigation_1 = require("next/navigation");
8
+ const react_redux_1 = require("react-redux");
9
+ const api_provider_1 = require("../api-provider");
10
+ /**
11
+ * A generic component that handles data creation logic using Redux API mutations
12
+ * Manages form submission, data transformation, and post-creation callbacks
13
+ * Also supports template-based default values from Redux state
14
+ *
15
+ * @param props Component props
16
+ * @returns A form component with data creation capabilities
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * <CreateDataWrapper
21
+ * name="product"
22
+ * Form={ProductForm}
23
+ * formProps={{
24
+ * buttonLabel: "Create Product",
25
+ * schema: productSchema
26
+ * }}
27
+ * />
28
+ * ```
29
+ */
30
+ function CreateDataWrapper({ name, Form, createMutation, doAfterSuccessCreate, cleanDataBeforeCreate = (data) => data, formProps, }) {
31
+ const api = (0, api_provider_1.useApi)();
32
+ const [createData, state] = api[createMutation || `useCreate${(0, change_case_all_1.pascalCase)(name)}Mutation`]();
33
+ const pathname = (0, navigation_1.usePathname)();
34
+ /**
35
+ * Handles form submission and data creation
36
+ * @param data The form data to be submitted
37
+ * @param form The react-hook-form form instance
38
+ * @returns The API response or error
39
+ */
40
+ const handleCreateData = (0, react_1.useCallback)(async function handleCreateData(data, form, onError) {
41
+ const cleanedData = cleanDataBeforeCreate(data);
42
+ try {
43
+ const response = await createData(data).unwrap();
44
+ doAfterSuccessCreate &&
45
+ (await doAfterSuccessCreate({ response, data: cleanedData, form }));
46
+ form.reset();
47
+ return response;
48
+ }
49
+ catch (err) {
50
+ onError?.(data, err);
51
+ return err;
52
+ }
53
+ }, [name, Form]);
54
+ (0, react_1.useEffect)(() => {
55
+ const listHref = pathname.split("/");
56
+ listHref.pop();
57
+ }, [pathname]);
58
+ // Get template data from Redux store if available
59
+ const template = (0, react_redux_1.useSelector)((state) => state.app.template);
60
+ return ((0, jsx_runtime_1.jsx)(Form, { ...state, ...formProps, ...(template &&
61
+ template.name === name && {
62
+ defaultValues: template.data,
63
+ }), onSubmit: handleCreateData }));
64
+ }
65
+ //# sourceMappingURL=create-data-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-data-wrapper.js","sourceRoot":"","sources":["../../../src/components/data-manipulation/create-data-wrapper.tsx"],"names":[],"mappings":";;AAwEA,oCA+DC;;AAvID,qDAA6C;AAC7C,iCAAsD;AAGtD,gDAA8C;AAC9C,6CAA0C;AAC1C,kDAAyC;AA8CzC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAwB,iBA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M,QAAQ,GAAG,IAAA,yBAAW,EAAC,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEjE,OAAO,CACL,uBAAC,IAAI,OACC,KAAK,KACL,SAAS,KACT,CAAC,QAAQ;YACX,QAAQ,CAAC,IAAI,KAAK,IAAI,IAAI;YACxB,aAAa,EAAE,QAAQ,CAAC,IAAI;SAC7B,CAAC,EACJ,QAAQ,EAAE,gBAAgB,GAC1B,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,91 @@
1
+ import React from "react";
2
+ import { UseFormReturn } from "react-hook-form";
3
+ import { z } from "zod";
4
+ /**
5
+ * Props for the form component rendered by UpdateDataWrapper
6
+ */
7
+ type FormComponentProps = {
8
+ /** Initial values for the form fields */
9
+ defaultValues?: any;
10
+ /** Form submission handler */
11
+ onSubmit: (data: any, form: UseFormReturn) => void;
12
+ /** Label for the submit button */
13
+ buttonLabel: string;
14
+ /** Optional CSS class name */
15
+ className?: string;
16
+ /** Loading state for the form */
17
+ isLoading?: boolean;
18
+ /** Zod schema for form validation */
19
+ schema: z.ZodObject<any>;
20
+ };
21
+ /**
22
+ * Props for the UpdateDataWrapper
23
+ */
24
+ type UpdateDataWrapperProps = {
25
+ /** ID of the record to update */
26
+ id?: string | number;
27
+ /** Name identifier used to generate API mutation name if not provided */
28
+ name: string;
29
+ /** Form component to render for data updating */
30
+ Form: (props: FormComponentProps) => React.JSX.Element;
31
+ /**
32
+ * Redux API mutation name (e.g., 'useUpdateProductMutation')
33
+ * If not provided, will be generated as `useUpdate${pascalCase(name)}Mutation`
34
+ */
35
+ updateMutation?: string;
36
+ /** Flag to show alert after successful update */
37
+ showAlertAfterSuccessUpdate?: boolean;
38
+ /** Callback function executed after successful data update */
39
+ doAfterSuccessUpdate?: (x: {
40
+ response: any;
41
+ data: any;
42
+ form: UseFormReturn;
43
+ }) => Promise<any> | void;
44
+ /** Function to transform form data before submission */
45
+ cleanDataBeforeUpdate?: (data: any) => void;
46
+ /** CSS class name for the component */
47
+ className?: string;
48
+ /** Buttons to be displayed in the top-right corner */
49
+ topButtons?: React.ReactNode;
50
+ /** Props specific to the form component */
51
+ formProps: {
52
+ /** Label for the form's submit button */
53
+ buttonLabel: string;
54
+ /** Optional CSS class name for the form */
55
+ className?: string;
56
+ /** Flag to maintain loading state after submission */
57
+ keepIsLoading?: boolean;
58
+ /** Additional data to be passed to the form */
59
+ requiredData?: Record<string, any>;
60
+ /** Zod schema for form validation */
61
+ schema: z.ZodObject<any>;
62
+ };
63
+ /** Additional parameters passed to QueryBaseComponent for data fetching */
64
+ params?: Record<string, any>;
65
+ };
66
+ /**
67
+ * A generic component for updating data with form validation and optimized API updates
68
+ *
69
+ * Features:
70
+ * - Integrates with QueryBaseComponent for initial data fetching
71
+ * - Only sends changed form values to the API
72
+ * - Supports custom mutation names and callbacks
73
+ * - Handles form validation with Zod
74
+ * - Ignores timestamp fields (createdAt, updatedAt, deletedAt) in change detection
75
+ *
76
+ * @example
77
+ * ```tsx
78
+ * <UpdateDataWrapper
79
+ * id="648339adsf043c8ed"
80
+ * name="product"
81
+ * Form={ProductForm}
82
+ * formProps={{
83
+ * buttonLabel: "Update Product",
84
+ * schema: productSchema
85
+ * }}
86
+ * />
87
+ * ```
88
+ */
89
+ export default function UpdateDataWrapper({ id, name, Form, updateMutation, doAfterSuccessUpdate, cleanDataBeforeUpdate, formProps, params, }: UpdateDataWrapperProps): import("react/jsx-runtime").JSX.Element;
90
+ export {};
91
+ //# sourceMappingURL=update-data-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-data-wrapper.d.ts","sourceRoot":"","sources":["../../../src/components/data-manipulation/update-data-wrapper.tsx"],"names":[],"mappings":"AACA,OAAO,KAA8B,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;GAEG;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,CAAC;QACpB,2CAA2C;QAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,sDAAsD;QACtD,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,+CAA+C;QAC/C,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACnC,qCAAqC;QACrC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;KACzB,CAAC;IACF,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,EAAE,EACF,IAAI,EACJ,IAAI,EACJ,cAAc,EACd,oBAAoB,EACpB,qBAAsC,EACtC,SAAS,EACT,MAAM,GACP,EAAE,sBAAsB,2CA4DxB"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = UpdateDataWrapper;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const change_case_all_1 = require("change-case-all");
9
+ const react_1 = require("react");
10
+ const api_provider_1 = require("../api-provider");
11
+ const query_boundary_1 = __importDefault(require("../query-boundary"));
12
+ /**
13
+ * A generic component for updating data with form validation and optimized API updates
14
+ *
15
+ * Features:
16
+ * - Integrates with QueryBaseComponent for initial data fetching
17
+ * - Only sends changed form values to the API
18
+ * - Supports custom mutation names and callbacks
19
+ * - Handles form validation with Zod
20
+ * - Ignores timestamp fields (createdAt, updatedAt, deletedAt) in change detection
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * <UpdateDataWrapper
25
+ * id="648339adsf043c8ed"
26
+ * name="product"
27
+ * Form={ProductForm}
28
+ * formProps={{
29
+ * buttonLabel: "Update Product",
30
+ * schema: productSchema
31
+ * }}
32
+ * />
33
+ * ```
34
+ */
35
+ function UpdateDataWrapper({ id, name, Form, updateMutation, doAfterSuccessUpdate, cleanDataBeforeUpdate = (data) => data, formProps, params, }) {
36
+ const api = (0, api_provider_1.useApi)();
37
+ const [updateData, state] = api[updateMutation || `useUpdate${(0, change_case_all_1.pascalCase)(name)}Mutation`]();
38
+ const [fetchedData, setFetchedData] = (0, react_1.useState)();
39
+ const [dataForm, setDataForm] = (0, react_1.useState)();
40
+ (0, react_1.useEffect)(() => {
41
+ dataForm?.reset(fetchedData);
42
+ }, [fetchedData]);
43
+ /**
44
+ * Handles form submission and data update
45
+ * Only sends changed fields to the API by comparing with initial values
46
+ *
47
+ * @param data Current form data
48
+ * @param form React Hook Form instance
49
+ */
50
+ function handleUpdateData(data, form) {
51
+ const cleanedData = cleanDataBeforeUpdate(data
52
+ // getFormChangedValues(
53
+ // formProps.schema.optional().safeParse(form?.formState?.defaultValues)
54
+ // .data,
55
+ // data
56
+ // )
57
+ );
58
+ // Submit update with ID in path and changed data in body
59
+ updateData({ id, body: cleanedData })
60
+ .unwrap()
61
+ .then(async (response) => {
62
+ doAfterSuccessUpdate &&
63
+ (await doAfterSuccessUpdate({ response, data: cleanedData, form }));
64
+ form.reset({ ...data, ...fetchedData });
65
+ setDataForm(form);
66
+ })
67
+ .catch(() => { });
68
+ }
69
+ return ((0, jsx_runtime_1.jsx)(query_boundary_1.default, { name: (0, change_case_all_1.camelCase)(name), successComponentProps: {
70
+ formProps: { ...state, ...formProps, onSubmit: handleUpdateData },
71
+ Form: Form,
72
+ fetchedData,
73
+ setFetchedData,
74
+ }, SuccessComponent: SuccessComponent, query: "useGetOne", params: { id, ...params }, showReloadAgainButton: false }));
75
+ }
76
+ /**
77
+ * Renders the form with fetched data
78
+ */
79
+ function SuccessComponent({ data, Form, formProps, setFetchedData, }) {
80
+ (0, react_1.useEffect)(() => {
81
+ setFetchedData(data.data);
82
+ }, [data]);
83
+ return (0, jsx_runtime_1.jsx)(Form, { ...formProps, defaultValues: data.data, source: data.data });
84
+ }
85
+ //# sourceMappingURL=update-data-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-data-wrapper.js","sourceRoot":"","sources":["../../../src/components/data-manipulation/update-data-wrapper.tsx"],"names":[],"mappings":";;;;;AA8FA,oCAqEC;;AAnKD,qDAAwD;AACxD,iCAAmD;AAGnD,kDAAyC;AACzC,uEAA8C;AAkE9C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAwB,iBAAiB,CAAC,EACxC,EAAE,EACF,IAAI,EACJ,IAAI,EACJ,cAAc,EACd,oBAAoB,EACpB,qBAAqB,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EACtC,SAAS,EACT,MAAM,GACiB;IACvB,MAAM,GAAG,GAAG,IAAA,qBAAM,GAAE,CAAC;IACrB,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,GAAI,GAAW,CACtC,cAAc,IAAI,YAAY,IAAA,4BAAU,EAAC,IAAI,CAAC,UAAU,CACzD,EAAE,CAAC;IACJ,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,GAAuB,CAAC;IACtE,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,GAAiB,CAAC;IAE1D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/B,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAElB;;;;;;OAMG;IACH,SAAS,gBAAgB,CACvB,IAAsC,EACtC,IAAmB;QAEnB,MAAM,WAAW,GAAG,qBAAqB,CACvC,IAAI;QACJ,wBAAwB;QACxB,0EAA0E;QAC1E,aAAa;QACb,SAAS;QACT,IAAI;SACL,CAAC;QAEF,yDAAyD;QACzD,UAAU,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAA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/modals";
4
+ /**
5
+ * Props for the CreateDataModal component
6
+ * @template DataType The type of data being created
7
+ */
8
+ export type CreateDataModalProps<T, FormProps = any> = {
9
+ /** Optional ID for the modal */
10
+ id?: string;
11
+ /** Name identifier for the form/modal - used to generate API mutation name if not provided */
12
+ name: string;
13
+ /** Form component to be rendered inside the modal for data creation */
14
+ Form: (props: any) => React.JSX.Element;
15
+ /**
16
+ * Redux API mutation name (e.g., 'useCreateProductMutation')
17
+ * If not provided, will be generated as `useCreate${pascalCase(name)}Mutation`
18
+ */
19
+ createMutation?: string;
20
+ /** Title displayed in the modal header */
21
+ title: string;
22
+ /** Optional description text for the modal */
23
+ description?: string;
24
+ /**
25
+ * When true, maintains the form button's loading state after submission
26
+ * Useful when additional processing is needed after data creation
27
+ */
28
+ keepIsLoading?: boolean;
29
+ /** Additional data to be passed to the form component */
30
+ requiredData?: Record<string, any>;
31
+ /** Flag to show alert after successful creation */
32
+ showAlertAfterSuccessCreate?: boolean;
33
+ /**
34
+ * Callback function executed after successful data creation
35
+ * Receives the created data and can perform additional operations
36
+ */
37
+ doAfterSuccessCreate?: (x: any) => Promise<any> | void;
38
+ /** Function to transform form data before submission */
39
+ cleanDataBeforeCreate?: (data: any) => void;
40
+ /** CSS class name for the modal */
41
+ className?: string;
42
+ /** Props for the modal dialog content */
43
+ contentProps?: ModalProps;
44
+ /** Zod schema for form validation */
45
+ schema: z.ZodObject<any>;
46
+ /** Buttons to be displayed in the top-right corner of the modal, next to the title */
47
+ topButtons?: React.ReactNode;
48
+ /** Props specific to the form component */
49
+ formProps?: FormProps;
50
+ };
51
+ /**
52
+ * A generic modal component for creating data with form validation
53
+ * @template DataType The type of data being created
54
+ * @param props Component props combining CreateDataModalProps and partial ModalProps
55
+ * @returns A Modal component containing a form for data creation
56
+ *
57
+ * @example
58
+ * ```tsx
59
+ * <CreateDataModal<UserData>
60
+ * name="user"
61
+ * title="Create New User"
62
+ * schema={userSchema}
63
+ * formProps={{ buttonLabel: "Create User" }}
64
+ * Form={UserForm}
65
+ * isOpen={isOpen}
66
+ * setIsOpen={setIsOpen}
67
+ * />
68
+ * ```
69
+ */
70
+ export default function CreateDataModal<DataType, FormProps = any>({ name, title, description, keepIsLoading, requiredData, schema, formProps, topButtons, isOpen, setIsOpen, showConfirmButton, doAfterSuccessCreate, contentProps, ...props }: CreateDataModalProps<DataType, FormProps> & Partial<ModalProps>): import("react/jsx-runtime").JSX.Element;
71
+ //# sourceMappingURL=create.modal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.modal.d.ts","sourceRoot":"","sources":["../../../src/components/modals/create.modal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAS,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG5D;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,EAAE,SAAS,GAAG,GAAG,IAAI;IACrD,gCAAgC;IAChC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8FAA8F;IAC9F,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,IAAI,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;IACxC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC,mDAAmD;IACnD,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAA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