@nomos-ui/uanela-redux-next 0.0.3 → 0.0.5

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.
@@ -2,68 +2,96 @@ import React from "react";
2
2
  import { UseFormReturn } from "react-hook-form";
3
3
  import { z } from "zod";
4
4
  /**
5
- * Props for the CreateDataWrapper
5
+ * Props for the CreateDataWrapper component
6
+ *
7
+ * @template Input - The shape of the form values / data being submitted
8
+ * @template Response - The shape of the API response returned after successful creation
9
+ * @template FormProps - Additional props accepted by the Form component
6
10
  */
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;
11
+ type CreateDataWrapperProps<Input, Response, FormProps extends Record<string, any> = Record<string, any>> = {
12
+ /**
13
+ * The form component to render.
14
+ * Receives all mutation state from the library (e.g. isLoading, isPending, error),
15
+ * formProps, and the onSubmit handler.
16
+ */
17
+ Form: (props: FormProps & {
18
+ onSubmit: any;
19
+ } & Record<string, any>) => React.JSX.Element;
14
20
  /**
15
- * Redux API mutation name (e.g., 'useCreateProductMutation')
16
- * If not provided, will be generated as `useCreate${pascalCase(name)}Mutation`
21
+ * The mutation hook to call for data creation.
22
+ * Pass the hook itself (e.g. useCreateProductMutation), not its result.
23
+ * The component will call it internally following React's rules of hooks.
24
+ *
25
+ * @example
26
+ * useMutation={useCreateProductMutation}
27
+ */
28
+ useMutation: () => any;
29
+ /**
30
+ * Callback executed after a successful creation.
31
+ * Receives the API response, the cleaned submitted data, and the form instance.
32
+ *
33
+ * @param x.response - The raw API response
34
+ * @param x.data - The cleaned data that was submitted
35
+ * @param x.form - The react-hook-form instance typed to Input
17
36
  */
18
- createMutation?: string;
19
- /** Flag to show alert after successful creation */
20
- showAlertAfterSuccessCreate?: boolean;
21
- /** Callback function executed after successful data creation */
22
37
  doAfterSuccessCreate?: (x: {
23
- response: any;
24
- data: any;
25
- form: UseFormReturn;
38
+ response: Response;
39
+ data: Input;
40
+ form: UseFormReturn<Input extends Record<string, any> ? Input : any>;
26
41
  }) => 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: {
42
+ /**
43
+ * Optional function to transform or clean the form data before submission.
44
+ * Defaults to an identity function (returns data as-is).
45
+ *
46
+ * @param data - Raw form data
47
+ * @returns Cleaned data to be submitted
48
+ */
49
+ cleanDataBeforeCreate?: (data: Input) => Promise<Input>;
50
+ /**
51
+ * Props passed directly to the Form component.
52
+ */
53
+ formProps: FormProps & {
35
54
  /** Label for the form's submit button */
36
55
  buttonLabel: string;
37
56
  /** Optional CSS class name for the form */
38
57
  className?: string;
39
- /** Flag to maintain loading state after submission */
58
+ /** If true, keeps the loading state active after submission */
40
59
  keepIsLoading?: boolean;
41
- /** Additional data to be passed to the form */
60
+ /** Additional data required by the form (e.g. select options, related records) */
42
61
  requiredData?: Record<string, any>;
43
- /** Zod schema for form validation */
62
+ /** Zod schema used for form validation */
44
63
  schema: z.ZodObject<any>;
45
64
  };
46
65
  };
47
66
  /**
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
67
+ * A generic wrapper that handles data creation logic independently of the query library.
68
+ * Supports both RTK Query and TanStack Query via the provider config.
69
+ *
70
+ * Responsibilities:
71
+ * - Calls the provided mutation hook
72
+ * - Extracts and normalizes the trigger function based on the query library
73
+ * - Passes all raw mutation state directly to the Form (no normalization)
74
+ * - Handles submit orchestration: cleaning data, triggering mutation, running callbacks, resetting form
75
+ *
76
+ * The Form component receives everything the mutation hook provides plus `onSubmit`.
51
77
  *
52
- * @param props Component props
53
- * @returns A form component with data creation capabilities
78
+ * @template Input - The shape of the form values / data being submitted
79
+ * @template Response - The shape of the API response returned after successful creation
80
+ * @template FormProps - Additional props accepted by the Form component
54
81
  *
55
82
  * @example
56
83
  * ```tsx
57
- * <CreateDataWrapper
58
- * name="product"
84
+ * <CreateDataWrapper<CreateProductInput, Product, ProductFormProps>
59
85
  * Form={ProductForm}
86
+ * useMutation={useCreateProductMutation}
87
+ * doAfterSuccessCreate={({ response }) => router.push(`/products/${response.id}`)}
60
88
  * formProps={{
61
89
  * buttonLabel: "Create Product",
62
- * schema: productSchema
90
+ * schema: productSchema,
63
91
  * }}
64
92
  * />
65
93
  * ```
66
94
  */
67
- export default function CreateDataWrapper({ name, Form, createMutation, doAfterSuccessCreate, cleanDataBeforeCreate, formProps, }: CreateDataWrapperProps): import("react/jsx-runtime").JSX.Element;
95
+ export default function CreateDataWrapper<Input, Response, FormProps extends Record<string, any> = Record<string, any>>({ Form, useMutation, doAfterSuccessCreate, cleanDataBeforeCreate, formProps, }: CreateDataWrapperProps<Input, Response, FormProps>): import("react/jsx-runtime").JSX.Element;
68
96
  export {};
69
97
  //# sourceMappingURL=create-data-wrapper.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"create-data-wrapper.d.ts","sourceRoot":"","sources":["../../../src/components/data-manipulation/create-data-wrapper.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB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UAAU,iBAAiB,CACvC,KAAK,EACL,QAAQ,EACR,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3D,EACA,IAAI,EACJ,WAAW,EACX,oBAAoB,EACpB,qBAA4C,EAC5C,SAAS,GACV,EAAE,sBAAsB,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,2CAuCpD"}
@@ -2,47 +2,56 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = CreateDataWrapper;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- const change_case_all_1 = require("change-case-all");
5
+ const core_1 = require("@nomos-ui/core");
6
+ const utils_1 = require("@nomos-ui/core/utils");
6
7
  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
8
  /**
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
9
+ * A generic wrapper that handles data creation logic independently of the query library.
10
+ * Supports both RTK Query and TanStack Query via the provider config.
14
11
  *
15
- * @param props Component props
16
- * @returns A form component with data creation capabilities
12
+ * Responsibilities:
13
+ * - Calls the provided mutation hook
14
+ * - Extracts and normalizes the trigger function based on the query library
15
+ * - Passes all raw mutation state directly to the Form (no normalization)
16
+ * - Handles submit orchestration: cleaning data, triggering mutation, running callbacks, resetting form
17
+ *
18
+ * The Form component receives everything the mutation hook provides plus `onSubmit`.
19
+ *
20
+ * @template Input - The shape of the form values / data being submitted
21
+ * @template Response - The shape of the API response returned after successful creation
22
+ * @template FormProps - Additional props accepted by the Form component
17
23
  *
18
24
  * @example
19
25
  * ```tsx
20
- * <CreateDataWrapper
21
- * name="product"
26
+ * <CreateDataWrapper<CreateProductInput, Product, ProductFormProps>
22
27
  * Form={ProductForm}
28
+ * useMutation={useCreateProductMutation}
29
+ * doAfterSuccessCreate={({ response }) => router.push(`/products/${response.id}`)}
23
30
  * formProps={{
24
31
  * buttonLabel: "Create Product",
25
- * schema: productSchema
32
+ * schema: productSchema,
26
33
  * }}
27
34
  * />
28
35
  * ```
29
36
  */
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)();
37
+ function CreateDataWrapper({ Form, useMutation, doAfterSuccessCreate, cleanDataBeforeCreate = async (data) => data, formProps, }) {
38
+ const { config } = (0, core_1.useProvider)();
39
+ const mutationResult = useMutation();
40
+ const { trigger, state } = (0, utils_1.extractMutation)(mutationResult, config.queryLibrary);
34
41
  /**
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
42
+ * Handles form submission.
43
+ * Cleans the data, triggers the mutation, runs the success callback, and resets the form.
44
+ * Calls onError if provided and the mutation fails.
45
+ *
46
+ * @param data - The validated form data
47
+ * @param form - The react-hook-form instance typed to Input
48
+ * @param onError - Optional callback invoked with the original data and error on failure
39
49
  */
40
- const handleCreateData = (0, react_1.useCallback)(async function handleCreateData(data, form, onError) {
41
- const cleanedData = cleanDataBeforeCreate(data);
50
+ const handleCreateData = (0, react_1.useCallback)(async function (data, form, onError) {
51
+ const cleanedData = await cleanDataBeforeCreate(data);
42
52
  try {
43
- const response = await createData(data).unwrap();
44
- doAfterSuccessCreate &&
45
- (await doAfterSuccessCreate({ response, data: cleanedData, form }));
53
+ const response = await trigger(cleanedData);
54
+ await doAfterSuccessCreate?.({ response, data: cleanedData, form });
46
55
  form.reset();
47
56
  return response;
48
57
  }
@@ -50,16 +59,7 @@ function CreateDataWrapper({ name, Form, createMutation, doAfterSuccessCreate, c
50
59
  onError?.(data, err);
51
60
  return err;
52
61
  }
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 }));
62
+ }, [trigger]);
63
+ return (0, jsx_runtime_1.jsx)(Form, { ...state, ...formProps, onSubmit: handleCreateData });
64
64
  }
65
65
  //# sourceMappingURL=create-data-wrapper.js.map
@@ -1 +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,iBAAiB,CAAC,EACxC,IAAI,EACJ,IAAI,EACJ,cAAc,EACd,oBAAoB,EACpB,qBAAqB,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EACtC,SAAS,GACc;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,QAAQ,GAAG,IAAA,wBAAW,GAAE,CAAC;IAE/B;;;;;OAKG;IACH,MAAM,gBAAgB,GAAG,IAAA,mBAAW,EAClC,KAAK,UAAU,gBAAgB,CAC7B,IAAsC,EACtC,IAAmB,EACnB,OAAsE;QAEtE,MAAM,WAAW,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAEhD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;YAEjD,oBAAoB;gBAClB,CAAC,MAAM,oBAAoB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAEtE,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YACrB,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC,EACD,CAAC,IAAI,EAAE,IAAI,CAAC,CACb,CAAC;IAEF,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrC,QAAQ,CAAC,GAAG,EAAE,CAAC;IACjB,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,kDAAkD;IAClD,MAAM,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"}
1
+ {"version":3,"file":"create-data-wrapper.js","sourceRoot":"","sources":["../../../src/components/data-manipulation/create-data-wrapper.tsx"],"names":[],"mappings":";;AAsGA,oCAiDC;;AAvJD,yCAA6C;AAC7C,gDAAuD;AACvD,iCAA2C;AAuE3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAwB,iBAAiB,CAIvC,EACA,IAAI,EACJ,WAAW,EACX,oBAAoB,EACpB,qBAAqB,GAAG,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAC5C,SAAS,GAC0C;IACnD,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,kBAAW,GAAE,CAAC;IACjC,MAAM,cAAc,GAAG,WAAW,EAAE,CAAC;IAErC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAA,uBAAe,EACxC,cAAc,EACd,MAAM,CAAC,YAAY,CACpB,CAAC;IAEF;;;;;;;;OAQG;IACH,MAAM,gBAAgB,GAAG,IAAA,mBAAW,EAClC,KAAK,WACH,IAAW,EACX,IAAoE,EACpE,OAA2C;QAE3C,MAAM,WAAW,GAAG,MAAM,qBAAqB,CAAC,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;YAC5C,MAAM,oBAAoB,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;YACpE,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YACrB,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC,EACD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,OAAO,uBAAC,IAAI,OAAK,KAAK,KAAM,SAAS,EAAE,QAAQ,EAAE,gBAAgB,GAAI,CAAC;AACxE,CAAC"}
@@ -1,71 +1,79 @@
1
1
  import React from "react";
2
2
  import { z } from "zod";
3
3
  import { ModalProps } from "@nomos-ui/common/modals";
4
+ import { UseFormReturn } from "react-hook-form";
4
5
  /**
5
6
  * Props for the CreateDataModal component
6
- * @template DataType The type of data being created
7
+ *
8
+ * @template Input - The shape of the form values / data being submitted
9
+ * @template Response - The shape of the API response returned after successful creation
10
+ * @template FormProps - Additional props accepted by the Form component
7
11
  */
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;
12
+ export type CreateDataModalProps<Input, Response, FormProps extends Record<string, any> = Record<string, any>> = {
13
13
  /** Form component to be rendered inside the modal for data creation */
14
14
  Form: (props: any) => React.JSX.Element;
15
15
  /**
16
- * Redux API mutation name (e.g., 'useCreateProductMutation')
17
- * If not provided, will be generated as `useCreate${pascalCase(name)}Mutation`
16
+ * The mutation hook to call for data creation.
17
+ * Pass the hook itself (e.g. useCreateProductMutation), not its result.
18
+ * The component will call it internally following React's rules of hooks.
19
+ *
20
+ * @example
21
+ * useMutation={useCreateProductMutation}
18
22
  */
19
- createMutation?: string;
23
+ useMutation: () => any;
20
24
  /** Title displayed in the modal header */
21
25
  title: string;
22
26
  /** Optional description text for the modal */
23
27
  description?: string;
24
28
  /**
25
- * When true, maintains the form button's loading state after submission
26
- * Useful when additional processing is needed after data creation
29
+ * When true, maintains the form button's loading state after submission.
30
+ * Useful when additional processing is needed after data creation.
27
31
  */
28
32
  keepIsLoading?: boolean;
29
33
  /** Additional data to be passed to the form component */
30
34
  requiredData?: Record<string, any>;
31
- /** Flag to show alert after successful creation */
32
- showAlertAfterSuccessCreate?: boolean;
33
35
  /**
34
- * Callback function executed after successful data creation
35
- * Receives the created data and can perform additional operations
36
+ * Callback executed after successful data creation and modal close.
37
+ * Receives the API response, the cleaned submitted data, and the form instance.
38
+ *
39
+ * @param x.response - The raw API response
40
+ * @param x.data - The cleaned data that was submitted
41
+ * @param x.form - The react-hook-form instance typed to Input
36
42
  */
37
- doAfterSuccessCreate?: (x: any) => Promise<any> | void;
43
+ doAfterSuccessCreate?: (x: {
44
+ response: Response;
45
+ data: Input;
46
+ form: UseFormReturn<Input extends Record<string, any> ? Input : any>;
47
+ }) => Promise<any> | void;
38
48
  /** Function to transform form data before submission */
39
- cleanDataBeforeCreate?: (data: any) => void;
40
- /** CSS class name for the modal */
41
- className?: string;
49
+ cleanDataBeforeCreate?: (data: Input) => Promise<Input>;
42
50
  /** Props for the modal dialog content */
43
- contentProps?: ModalProps;
51
+ contentProps?: Omit<ModalProps, "children">;
44
52
  /** Zod schema for form validation */
45
53
  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
54
  /** Props specific to the form component */
49
55
  formProps?: FormProps;
50
56
  };
51
57
  /**
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
58
+ * A generic modal component for creating data with form validation.
59
+ * Wraps CreateDataWrapper inside a Modal, handling modal close after successful creation.
60
+ *
61
+ * @template Input - The shape of the form values / data being submitted
62
+ * @template Response - The shape of the API response returned after successful creation
63
+ * @template FormProps - Additional props accepted by the Form component
56
64
  *
57
65
  * @example
58
66
  * ```tsx
59
- * <CreateDataModal<UserData>
60
- * name="user"
61
- * title="Create New User"
62
- * schema={userSchema}
63
- * formProps={{ buttonLabel: "Create User" }}
64
- * Form={UserForm}
67
+ * <CreateDataModal<CreateProductInput, Product, ProductFormProps>
68
+ * title="Create New Product"
69
+ * schema={productSchema}
70
+ * Form={ProductForm}
71
+ * useMutation={useCreateProductMutation}
72
+ * formProps={{ buttonLabel: "Create Product" }}
65
73
  * isOpen={isOpen}
66
74
  * setIsOpen={setIsOpen}
67
75
  * />
68
76
  * ```
69
77
  */
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;
78
+ export default function CreateDataModal<Input, Response, FormProps extends Record<string, any> = Record<string, any>>({ title, description, keepIsLoading, requiredData, schema, formProps, isOpen, setIsOpen, showConfirmButton, doAfterSuccessCreate, cleanDataBeforeCreate, contentProps, Form, useMutation, }: CreateDataModalProps<Input, Response, FormProps> & Partial<ModalProps>): import("react/jsx-runtime").JSX.Element;
71
79
  //# sourceMappingURL=create.modal.d.ts.map
@@ -1 +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,CAAC,GAAG,IAAI,CAAC;IACvD,wDAAwD;IACxD,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAC5C,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;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E,QAAQ,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,2CA+CxE"}
@@ -1,4 +1,3 @@
1
- "use client";
2
1
  "use strict";
3
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -11,41 +10,44 @@ const tailwind_merge_1 = require("tailwind-merge");
11
10
  const modals_1 = require("@nomos-ui/common/modals");
12
11
  const create_data_wrapper_1 = __importDefault(require("../data-manipulation/create-data-wrapper"));
13
12
  /**
14
- * A generic modal component for creating data with form validation
15
- * @template DataType The type of data being created
16
- * @param props Component props combining CreateDataModalProps and partial ModalProps
17
- * @returns A Modal component containing a form for data creation
13
+ * A generic modal component for creating data with form validation.
14
+ * Wraps CreateDataWrapper inside a Modal, handling modal close after successful creation.
15
+ *
16
+ * @template Input - The shape of the form values / data being submitted
17
+ * @template Response - The shape of the API response returned after successful creation
18
+ * @template FormProps - Additional props accepted by the Form component
18
19
  *
19
20
  * @example
20
21
  * ```tsx
21
- * <CreateDataModal<UserData>
22
- * name="user"
23
- * title="Create New User"
24
- * schema={userSchema}
25
- * formProps={{ buttonLabel: "Create User" }}
26
- * Form={UserForm}
22
+ * <CreateDataModal<CreateProductInput, Product, ProductFormProps>
23
+ * title="Create New Product"
24
+ * schema={productSchema}
25
+ * Form={ProductForm}
26
+ * useMutation={useCreateProductMutation}
27
+ * formProps={{ buttonLabel: "Create Product" }}
27
28
  * isOpen={isOpen}
28
29
  * setIsOpen={setIsOpen}
29
30
  * />
30
31
  * ```
31
32
  */
32
- function CreateDataModal({ name, title, description, keepIsLoading, requiredData, schema, formProps, topButtons, isOpen, setIsOpen, showConfirmButton, doAfterSuccessCreate = () => { }, contentProps, ...props }) {
33
+ function CreateDataModal({ title, description, keepIsLoading, requiredData, schema, formProps, isOpen, setIsOpen, showConfirmButton, doAfterSuccessCreate, cleanDataBeforeCreate, contentProps, Form, useMutation, }) {
33
34
  /**
34
- * Handles modal closure and executes post-creation callback
35
- * @param data The created data
35
+ * Closes the modal then fires the post-creation callback if provided.
36
+ *
37
+ * @param x - The object received from CreateDataWrapper's doAfterSuccessCreate
36
38
  */
37
- const handleCloseModal = (0, react_1.useCallback)(function handleCloseModal(data) {
39
+ const handleCloseModal = (0, react_1.useCallback)(async function handleCloseModal(x) {
38
40
  setIsOpen(false);
39
- doAfterSuccessCreate(data);
40
- }, [name]);
41
+ await doAfterSuccessCreate?.(x);
42
+ }, [doAfterSuccessCreate, setIsOpen]);
41
43
  return ((0, jsx_runtime_1.jsx)(modals_1.Modal, { title: title, description: description, setIsOpen: setIsOpen, isOpen: isOpen, showConfirmButton: showConfirmButton, contentProps: {
42
44
  ...contentProps,
43
45
  className: (0, tailwind_merge_1.twMerge)(contentProps?.className, "max-h-[80vh] md:max-h-[90vh] overflow-auto"),
44
- }, children: (0, jsx_runtime_1.jsx)(create_data_wrapper_1.default, { ...props, name: name, doAfterSuccessCreate: handleCloseModal, formProps: {
46
+ }, children: (0, jsx_runtime_1.jsx)(create_data_wrapper_1.default, { Form: Form, useMutation: useMutation, cleanDataBeforeCreate: cleanDataBeforeCreate, doAfterSuccessCreate: handleCloseModal, formProps: {
45
47
  ...formProps,
46
- keepIsLoading: keepIsLoading,
47
- requiredData: requiredData,
48
- schema: schema,
48
+ keepIsLoading,
49
+ requiredData,
50
+ schema,
49
51
  } }) }));
50
52
  }
51
53
  //# sourceMappingURL=create.modal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.modal.js","sourceRoot":"","sources":["../../../src/components/modals/create.modal.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AA4Eb,kCAwDC;;AAlID,iCAA2C;AAE3C,mDAAyC;AACzC,oDAA4D;AAC5D,mGAAyE;AAmDzE;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAwB,eAAe,CAA4B,EACjE,IAAI,EACJ,KAAK,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,MAAM,EACN,SAAS,EACT,UAAU,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,oBAAoB,GAAG,GAAG,EAAE,GAAE,CAAC,EAC/B,YAAY,EACZ,GAAG,KAAK,EACwD;IAChE;;;OAGG;IACH,MAAM,gBAAgB,GAAG,IAAA,mBAAW,EAClC,SAAS,gBAAgB,CAAC,IAAS;QACjC,SAAU,CAAC,KAAK,CAAC,CAAC;QAClB,oBAAqB,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC,EACD,CAAC,IAAI,CAAC,CACP,CAAC;IAEF,OAAO,CACL,uBAAC,cAAK,IACJ,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,iBAAiB,EACpC,YAAY,EAAE;YACZ,GAAG,YAAY;YACf,SAAS,EAAE,IAAA,wBAAO,EAChB,YAAY,EAAE,SAAS,EACvB,4CAA4C,CAC7C;SACF,YAED,uBAAC,6BAAiB,OACZ,KAAK,EACT,IAAI,EAAE,IAAI,EACV,oBAAoB,EAAE,gBAAgB,EACtC,SAAS,EAAE;gBACT,GAAI,SAAiB;gBACrB,aAAa,EAAE,aAAa;gBAC5B,YAAY,EAAE,YAAY;gBAC1B,MAAM,EAAE,MAAM;aACf,GACD,GACI,CACT,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"create.modal.js","sourceRoot":"","sources":["../../../src/components/modals/create.modal.tsx"],"names":[],"mappings":";;;;;AAqFA,kCAkEC;;AAvJD,iCAA2C;AAE3C,mDAAyC;AACzC,oDAA4D;AAC5D,mGAAyE;AA4DzE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAwB,eAAe,CAIrC,EACA,KAAK,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,MAAM,EACN,SAAS,EACT,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,YAAY,EACZ,IAAI,EACJ,WAAW,GAC4D;IACvE;;;;OAIG;IACH,MAAM,gBAAgB,GAAG,IAAA,mBAAW,EAClC,KAAK,UAAU,gBAAgB,CAAC,CAI/B;QACC,SAAU,CAAC,KAAK,CAAC,CAAC;QAClB,MAAM,oBAAoB,EAAE,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC,EACD,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAClC,CAAC;IAEF,OAAO,CACL,uBAAC,cAAK,IACJ,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,iBAAiB,EACpC,YAAY,EAAE;YACZ,GAAG,YAAY;YACf,SAAS,EAAE,IAAA,wBAAO,EAChB,YAAY,EAAE,SAAS,EACvB,4CAA4C,CAC7C;SACF,YAED,uBAAC,6BAAiB,IAChB,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,WAAW,EACxB,qBAAqB,EAAE,qBAAqB,EAC5C,oBAAoB,EAAE,gBAAgB,EACtC,SAAS,EAAE;gBACT,GAAI,SAAiB;gBACrB,aAAa;gBACb,YAAY;gBACZ,MAAM;aACP,GACD,GACI,CACT,CAAC;AACJ,CAAC"}
@@ -46,7 +46,7 @@ export type UpdateDataModalProps<DataType, FormProps = any> = {
46
46
  /** Additional props forwarded to the form */
47
47
  formProps?: FormProps;
48
48
  /** Props that apply to Radix Dialog content wrapper */
49
- contentProps?: ModalProps;
49
+ contentProps?: Omit<ModalProps, "children">;
50
50
  };
51
51
  /**
52
52
  * A generic modal component for updating data with form validation.
@@ -1 +1 @@
1
- {"version":3,"file":"update.modal.d.ts","sourceRoot":"","sources":["../../../src/components/modals/update.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,M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AK,IAAI,CAAC;IAC5C,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACzB,gDAAgD;IAChD,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC7B,6CAA6C;IAC7C,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,uDAAuD;IACvD,YAAY,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,QAAQ,EAAE,SAAS,GAAG,GAAG,EAAE,EACjE,IAAI,EACJ,KAAK,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,MAAM,EACN,SAAS,EACT,UAAU,EACV,MAAM,EACN,SAAS,EACT,iBAAiB,EACjB,oBAA+B,EAC/B,YAAY,EACZ,GAAG,KAAK,EACT,EAAE,oBAAoB,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,2CAyCjE"}
@@ -1,25 +1,86 @@
1
1
  import React from "react";
2
2
  import { z } from "zod";
3
- type CreateDataPageProps<DataType> = {
4
- id?: string;
5
- name: string;
3
+ import { UseFormReturn } from "react-hook-form";
4
+ /**
5
+ * Props for the CreateDataPage component
6
+ *
7
+ * @template Input - The shape of the form values / data being submitted
8
+ * @template Response - The shape of the API response returned after successful creation
9
+ * @template FormProps - Additional props accepted by the Form component
10
+ */
11
+ type CreateDataPageProps<Input, Response, FormProps extends Record<string, any> = Record<string, any>> = {
12
+ /** Form component to render for data creation */
6
13
  Form: (props: any) => React.JSX.Element;
7
- createMutation?: string;
14
+ /**
15
+ * The mutation hook to call for data creation.
16
+ * Pass the hook itself (e.g. useCreateProductMutation), not its result.
17
+ * The component will call it internally following React's rules of hooks.
18
+ *
19
+ * @example
20
+ * useMutation={useCreateProductMutation}
21
+ */
22
+ useMutation: () => any;
23
+ /** Title displayed in the page header */
8
24
  title: string;
25
+ /** Description displayed below the page title */
9
26
  description: string;
27
+ /**
28
+ * When true, maintains the form button's loading state after submission.
29
+ * Useful when additional processing is needed after data creation.
30
+ */
10
31
  keepIsLoading?: boolean;
32
+ /** Additional data to be passed to the form component */
11
33
  requiredData?: Record<string, any>;
12
- showAlertAfterSuccessCreate?: boolean;
13
- doAfterSuccessCreate?: (x: any) => Promise<any> | void;
14
- cleanDataBeforeCreate?: (data: any) => void;
15
- className?: string;
34
+ /**
35
+ * Callback executed after successful data creation.
36
+ * Receives the API response, the cleaned submitted data, and the form instance.
37
+ *
38
+ * @param x.response - The raw API response
39
+ * @param x.data - The cleaned data that was submitted
40
+ * @param x.form - The react-hook-form instance typed to Input
41
+ */
42
+ doAfterSuccessCreate?: (x: {
43
+ response: Response;
44
+ data: Input;
45
+ form: UseFormReturn<Input extends Record<string, any> ? Input : any>;
46
+ }) => Promise<any> | void;
47
+ /**
48
+ * Optional function to transform or clean the form data before submission.
49
+ * Defaults to an identity function (returns data as-is).
50
+ */
51
+ cleanDataBeforeCreate?: (data: Input) => Promise<Input>;
52
+ /** Zod schema used for form validation */
16
53
  schema: z.ZodObject<any>;
17
- topButtons?: any;
18
- formProps: {
54
+ /** Buttons to be displayed in the top-right corner of the page, next to the title */
55
+ topButtons?: React.ReactNode[];
56
+ /** Props passed directly to the Form component */
57
+ formProps: FormProps & {
58
+ /** Label for the form's submit button */
19
59
  buttonLabel: string;
60
+ /** Optional CSS class name for the form */
20
61
  className?: string;
21
62
  };
22
63
  };
23
- export default function CreateDataPage<DataType>({ name, title, description, keepIsLoading, requiredData, schema, formProps, topButtons, ...props }: CreateDataPageProps<DataType>): import("react/jsx-runtime").JSX.Element;
64
+ /**
65
+ * A generic page component for creating data with form validation.
66
+ * Wraps CreateDataWrapper inside a page layout with a title, description, and optional top buttons.
67
+ *
68
+ * @template Input - The shape of the form values / data being submitted
69
+ * @template Response - The shape of the API response returned after successful creation
70
+ * @template FormProps - Additional props accepted by the Form component
71
+ *
72
+ * @example
73
+ * ```tsx
74
+ * <CreateDataPage<CreateProductInput, Product, ProductFormProps>
75
+ * title="Create Product"
76
+ * description="Fill in the details to create a new product"
77
+ * schema={productSchema}
78
+ * Form={ProductForm}
79
+ * useMutation={useCreateProductMutation}
80
+ * formProps={{ buttonLabel: "Create Product" }}
81
+ * />
82
+ * ```
83
+ */
84
+ export default function CreateDataPage<Input, Response, FormProps extends Record<string, any> = Record<string, any>>({ title, description, keepIsLoading, requiredData, schema, formProps, topButtons, Form, useMutation, doAfterSuccessCreate, cleanDataBeforeCreate, }: CreateDataPageProps<Input, Response, FormProps>): import("react/jsx-runtime").JSX.Element;
24
85
  export {};
25
86
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/pages/create-data-page/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,KAAK,mBAAmB,CAAC,QAAQ,IAAI;IACnC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;IACxC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC,2BAA2B,CAAC,EAAE,OAAO,CAAC;IACtC,oBAAoB,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACvD,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IACxB,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,SAAS,EAAE;QACT,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,QAAQ,EAAE,EAC/C,IAAI,EACJ,KAAK,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,MAAM,EACN,SAAS,EACT,UAAU,EACV,GAAG,KAAK,EACT,EAAE,mBAAmB,CAAC,QAAQ,CAAC,2CAwC/B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/pages/create-data-page/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAKhD;;;;;;GAMG;AACH,KAAK,mBAAmB,CACtB,KAAK,EACL,QAAQ,EACR,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IACzD;IACF,iDAAiD;IACjD,IAAI,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;IACxC;;;;;;;OAOG;IACH,WAAW,EAAE,MAAM,GAAG,CAAC;IACvB,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACnC;;;;;;;OAOG;IACH,oBAAoB,CAAC,EAAE,CAAC,CAAC,EAAE;QACzB,QAAQ,EAAE,QAAQ,CAAC;QACnB,IAAI,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,aAAa,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,KAAK,GAAG,GAAG,CAAC,CAAC;KACtE,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAC1B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC;IACxD,0CAA0C;IAC1C,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACzB,qFAAqF;IACrF,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC;IAC/B,kDAAkD;IAClD,SAAS,EAAE,SAAS,GAAG;QACrB,yCAAyC;QACzC,WAAW,EAAE,MAAM,CAAC;QACpB,2CAA2C;QAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,KAAK,EACL,QAAQ,EACR,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3D,EACA,KAAK,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,MAAM,EACN,SAAS,EACT,UAAU,EACV,IAAI,EACJ,WAAW,EACX,oBAAoB,EACpB,qBAAqB,GACtB,EAAE,mBAAmB,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,2CAwCjD"}
@@ -8,15 +8,35 @@ const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const navigation_1 = require("next/navigation");
9
9
  const create_data_wrapper_1 = __importDefault(require("../../data-manipulation/create-data-wrapper"));
10
10
  const page_title_and_description_1 = __importDefault(require("../components/page-title-and-description"));
11
- function CreateDataPage({ name, title, description, keepIsLoading, requiredData, schema, formProps, topButtons, ...props }) {
11
+ /**
12
+ * A generic page component for creating data with form validation.
13
+ * Wraps CreateDataWrapper inside a page layout with a title, description, and optional top buttons.
14
+ *
15
+ * @template Input - The shape of the form values / data being submitted
16
+ * @template Response - The shape of the API response returned after successful creation
17
+ * @template FormProps - Additional props accepted by the Form component
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * <CreateDataPage<CreateProductInput, Product, ProductFormProps>
22
+ * title="Create Product"
23
+ * description="Fill in the details to create a new product"
24
+ * schema={productSchema}
25
+ * Form={ProductForm}
26
+ * useMutation={useCreateProductMutation}
27
+ * formProps={{ buttonLabel: "Create Product" }}
28
+ * />
29
+ * ```
30
+ */
31
+ function CreateDataPage({ title, description, keepIsLoading, requiredData, schema, formProps, topButtons, Form, useMutation, doAfterSuccessCreate, cleanDataBeforeCreate, }) {
12
32
  const pathname = (0, navigation_1.usePathname)();
13
33
  const listHref = pathname.split("/");
14
34
  listHref.pop();
15
- return ((0, jsx_runtime_1.jsxs)("div", { className: "grid md:gap-4 gap-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "flex justify-between items-center", children: (0, jsx_runtime_1.jsx)(page_title_and_description_1.default, { title: title, description: description }) }), (0, jsx_runtime_1.jsx)("div", { className: "bg-background rounded-lg lg:h-[calc(100vh-154px)] h-[calc(100vh-140px)] md:p-4 p-2 border-input border ", children: (0, jsx_runtime_1.jsx)("div", { className: "main-container-content", children: (0, jsx_runtime_1.jsx)(create_data_wrapper_1.default, { ...props, name: name, formProps: {
35
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "grid md:gap-4 gap-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "flex justify-between items-center", children: (0, jsx_runtime_1.jsx)(page_title_and_description_1.default, { title: title, description: description }) }), (0, jsx_runtime_1.jsx)("div", { className: "bg-background rounded-lg lg:h-[calc(100vh-154px)] h-[calc(100vh-140px)] md:p-4 p-2 border-input border", children: (0, jsx_runtime_1.jsx)("div", { className: "main-container-content", children: (0, jsx_runtime_1.jsx)(create_data_wrapper_1.default, { Form: Form, useMutation: useMutation, cleanDataBeforeCreate: cleanDataBeforeCreate, doAfterSuccessCreate: doAfterSuccessCreate, formProps: {
16
36
  ...formProps,
17
- keepIsLoading: keepIsLoading,
18
- requiredData: requiredData,
19
- schema: schema,
37
+ keepIsLoading,
38
+ requiredData,
39
+ schema,
20
40
  } }) }) })] }));
21
41
  }
22
42
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/pages/create-data-page/index.tsx"],"names":[],"mappings":";;;;;AA2BA,iCAkDC;;AA3ED,gDAA8C;AAC9C,sGAA4E;AAC5E,0GAA+E;AAuB/E,SAAwB,cAAc,CAAW,EAC/C,IAAI,EACJ,KAAK,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,MAAM,EACN,SAAS,EACT,UAAU,EACV,GAAG,KAAK,EACsB;IAC9B,MAAM,QAAQ,GAAG,IAAA,wBAAW,GAAE,CAAC;IAE/B,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,CAAC;IAEf,OAAO,CACL,iCAAK,SAAS,EAAC,qBAAqB,aAClC,gCAAK,SAAS,EAAC,mCAAmC,YAChD,uBAAC,oCAAuB,IAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,GAAI,GAc/D,EACN,gCAAK,SAAS,EAAC,yGAAyG,YACtH,gCAAK,SAAS,EAAC,wBAAwB,YACrC,uBAAC,6BAAiB,OACZ,KAAK,EACT,IAAI,EAAE,IAAI,EACV,SAAS,EAAE;4BACT,GAAG,SAAS;4BACZ,aAAa,EAAE,aAAa;4BAC5B,YAAY,EAAE,YAAY;4BAC1B,MAAM,EAAE,MAAM;yBACf,GACD,GACE,GACF,IACF,CACP,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/pages/create-data-page/index.tsx"],"names":[],"mappings":";;;;;AA4FA,iCAwDC;;AAjJD,gDAA8C;AAC9C,sGAA4E;AAC5E,0GAA+E;AAmE/E;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAwB,cAAc,CAIpC,EACA,KAAK,EACL,WAAW,EACX,aAAa,EACb,YAAY,EACZ,MAAM,EACN,SAAS,EACT,UAAU,EACV,IAAI,EACJ,WAAW,EACX,oBAAoB,EACpB,qBAAqB,GAC2B;IAChD,MAAM,QAAQ,GAAG,IAAA,wBAAW,GAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,CAAC;IAEf,OAAO,CACL,iCAAK,SAAS,EAAC,qBAAqB,aAClC,gCAAK,SAAS,EAAC,mCAAmC,YAChD,uBAAC,oCAAuB,IAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,GAAI,GAa/D,EACN,gCAAK,SAAS,EAAC,wGAAwG,YACrH,gCAAK,SAAS,EAAC,wBAAwB,YACrC,uBAAC,6BAAiB,IAChB,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,WAAW,EACxB,qBAAqB,EAAE,qBAAqB,EAC5C,oBAAoB,EAAE,oBAAoB,EAC1C,SAAS,EAAE;4BACT,GAAG,SAAS;4BACZ,aAAa;4BACb,YAAY;4BACZ,MAAM;yBACP,GACD,GACE,GACF,IACF,CACP,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nomos-ui/uanela-redux-next",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Uanela Como Redux & Next ToolKit",
5
5
  "module": "dist/exports/index.js",
6
6
  "types": "dist/exports/index.d.ts",
@@ -69,6 +69,7 @@
69
69
  "zod": "^4.3.5"
70
70
  },
71
71
  "dependencies": {
72
+ "@nomos-ui/core": "^0.0.8",
72
73
  "uuid4": "^2.0.3"
73
74
  }
74
75
  }