@nomos-ui/uanela-redux-next 0.0.5 → 0.1.1
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/dist/components/data-manipulation/update-data-wrapper.d.ts +68 -57
- package/dist/components/data-manipulation/update-data-wrapper.d.ts.map +1 -1
- package/dist/components/data-manipulation/update-data-wrapper.js +46 -41
- package/dist/components/data-manipulation/update-data-wrapper.js.map +1 -1
- package/dist/components/modals/update.modal.d.ts +58 -33
- package/dist/components/modals/update.modal.d.ts.map +1 -1
- package/dist/components/modals/update.modal.js +20 -16
- package/dist/components/modals/update.modal.js.map +1 -1
- package/dist/components/pages/create-data-page/index.js +2 -2
- package/dist/components/pages/create-data-page/index.js.map +1 -1
- package/dist/components/pages/list-page/header-action-buttons.d.ts +11 -0
- package/dist/components/pages/list-page/header-action-buttons.d.ts.map +1 -1
- package/dist/components/pages/list-page/header-action-buttons.js +12 -7
- package/dist/components/pages/list-page/header-action-buttons.js.map +1 -1
- package/dist/components/pages/list-page/list-page.d.ts +29 -4
- package/dist/components/pages/list-page/list-page.d.ts.map +1 -1
- package/dist/components/pages/list-page/list-page.js +22 -5
- package/dist/components/pages/list-page/list-page.js.map +1 -1
- package/dist/components/pages/list-page/table/table.d.ts +3 -8
- package/dist/components/pages/list-page/table/table.d.ts.map +1 -1
- package/dist/components/pages/list-page/table/table.js +18 -17
- package/dist/components/pages/list-page/table/table.js.map +1 -1
- package/dist/components/pages/list-page/template.d.ts +59 -3
- package/dist/components/pages/list-page/template.d.ts.map +1 -1
- package/dist/components/pages/list-page/template.js +31 -24
- package/dist/components/pages/list-page/template.js.map +1 -1
- package/dist/components/pages/update-data-page/index.d.ts +84 -11
- package/dist/components/pages/update-data-page/index.d.ts.map +1 -1
- package/dist/components/pages/update-data-page/index.js +30 -11
- package/dist/components/pages/update-data-page/index.js.map +1 -1
- package/dist/components/query-boundary.d.ts +29 -20
- package/dist/components/query-boundary.d.ts.map +1 -1
- package/dist/components/query-boundary.js +30 -37
- package/dist/components/query-boundary.js.map +1 -1
- package/package.json +10 -6
- package/dist/hooks/use-update-search-params.d.ts +0 -5
- package/dist/hooks/use-update-search-params.d.ts.map +0 -1
- package/dist/hooks/use-update-search-params.js +0 -13
- package/dist/hooks/use-update-search-params.js.map +0 -1
|
@@ -1,91 +1,102 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { UseFormReturn } from "react-hook-form";
|
|
2
|
+
import { FieldValues, UseFormReturn } from "react-hook-form";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
/**
|
|
5
|
-
* Props for the
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
5
|
+
* Props for the UpdateDataWrapper 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 update
|
|
9
|
+
* @template FormProps - Additional props accepted by the Form component
|
|
23
10
|
*/
|
|
24
|
-
type UpdateDataWrapperProps = {
|
|
11
|
+
type UpdateDataWrapperProps<Input extends FieldValues, Response, FormProps extends Record<string, any> = Record<string, any>> = {
|
|
25
12
|
/** ID of the record to update */
|
|
26
13
|
id?: string | number;
|
|
27
|
-
/** Name identifier used to generate API mutation name if not provided */
|
|
28
|
-
name: string;
|
|
29
14
|
/** Form component to render for data updating */
|
|
30
|
-
Form: (props:
|
|
15
|
+
Form: (props: any) => React.JSX.Element;
|
|
31
16
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
17
|
+
* The mutation hook to call for data update.
|
|
18
|
+
* Pass the hook itself (e.g. useUpdateProductMutation), not its result.
|
|
19
|
+
* The component will call it internally following React's rules of hooks.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* useMutation={useUpdateProductMutation}
|
|
23
|
+
*/
|
|
24
|
+
useMutation: () => any;
|
|
25
|
+
/**
|
|
26
|
+
* The query hook to fetch the existing record.
|
|
27
|
+
* Pass the hook itself (e.g. useGetProductQuery), not its result.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* useQuery={useGetProductQuery}
|
|
31
|
+
*/
|
|
32
|
+
useQuery: (params: any) => any;
|
|
33
|
+
/**
|
|
34
|
+
* Callback executed after successful data update.
|
|
35
|
+
* Receives the API response, the cleaned submitted data, and the form instance.
|
|
36
|
+
*
|
|
37
|
+
* @param x.response - The raw API response
|
|
38
|
+
* @param x.data - The cleaned data that was submitted
|
|
39
|
+
* @param x.form - The react-hook-form instance typed to Input
|
|
34
40
|
*/
|
|
35
|
-
updateMutation?: string;
|
|
36
|
-
/** Flag to show alert after successful update */
|
|
37
|
-
showAlertAfterSuccessUpdate?: boolean;
|
|
38
|
-
/** Callback function executed after successful data update */
|
|
39
41
|
doAfterSuccessUpdate?: (x: {
|
|
40
|
-
response:
|
|
41
|
-
data:
|
|
42
|
-
form: UseFormReturn
|
|
42
|
+
response: Response;
|
|
43
|
+
data: Input;
|
|
44
|
+
form: UseFormReturn<Input>;
|
|
43
45
|
}) => Promise<any> | void;
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Optional function to transform or clean the form data before submission.
|
|
48
|
+
* Defaults to an identity function (returns data as-is).
|
|
49
|
+
*
|
|
50
|
+
* @param data - Raw form data
|
|
51
|
+
* @returns Cleaned data to be submitted
|
|
52
|
+
*/
|
|
53
|
+
cleanDataBeforeUpdate?: (data: Input) => Input;
|
|
54
|
+
/** Additional parameters passed to the query hook for data fetching */
|
|
55
|
+
params?: Record<string, any>;
|
|
56
|
+
/** Props passed directly to the Form component */
|
|
57
|
+
formProps: FormProps & {
|
|
52
58
|
/** Label for the form's submit button */
|
|
53
59
|
buttonLabel: string;
|
|
54
60
|
/** Optional CSS class name for the form */
|
|
55
61
|
className?: string;
|
|
56
|
-
/**
|
|
62
|
+
/** If true, keeps the loading state active after submission */
|
|
57
63
|
keepIsLoading?: boolean;
|
|
58
|
-
/** Additional data
|
|
64
|
+
/** Additional data required by the form (e.g. select options, related records) */
|
|
59
65
|
requiredData?: Record<string, any>;
|
|
60
|
-
/** Zod schema for form validation */
|
|
66
|
+
/** Zod schema used for form validation */
|
|
61
67
|
schema: z.ZodObject<any>;
|
|
62
68
|
};
|
|
63
|
-
/** Additional parameters passed to QueryBaseComponent for data fetching */
|
|
64
|
-
params?: Record<string, any>;
|
|
65
69
|
};
|
|
66
70
|
/**
|
|
67
|
-
* A generic
|
|
71
|
+
* A generic wrapper that handles data update logic independently of the query library.
|
|
72
|
+
* Supports both RTK Query and TanStack Query via the provider config.
|
|
73
|
+
*
|
|
74
|
+
* Responsibilities:
|
|
75
|
+
* - Fetches existing record via useQuery and populates form default values
|
|
76
|
+
* - Calls the provided mutation hook
|
|
77
|
+
* - Extracts and normalizes the trigger function based on the query library
|
|
78
|
+
* - Passes all raw mutation state directly to the Form (no normalization)
|
|
79
|
+
* - Handles submit orchestration: cleaning data, triggering mutation, running callbacks, resetting form
|
|
68
80
|
*
|
|
69
|
-
*
|
|
70
|
-
* -
|
|
71
|
-
*
|
|
72
|
-
* - Supports custom mutation names and callbacks
|
|
73
|
-
* - Handles form validation with Zod
|
|
74
|
-
* - Ignores timestamp fields (createdAt, updatedAt, deletedAt) in change detection
|
|
81
|
+
* @template Input - The shape of the form values / data being submitted
|
|
82
|
+
* @template Response - The shape of the API response returned after successful update
|
|
83
|
+
* @template FormProps - Additional props accepted by the Form component
|
|
75
84
|
*
|
|
76
85
|
* @example
|
|
77
86
|
* ```tsx
|
|
78
|
-
* <UpdateDataWrapper
|
|
79
|
-
* id=
|
|
80
|
-
* name="product"
|
|
87
|
+
* <UpdateDataWrapper<UpdateProductInput, Product, ProductFormProps>
|
|
88
|
+
* id={productId}
|
|
81
89
|
* Form={ProductForm}
|
|
90
|
+
* useMutation={useUpdateProductMutation}
|
|
91
|
+
* useQuery={useGetProductQuery}
|
|
92
|
+
* doAfterSuccessUpdate={({ response }) => router.push(`/products`)}
|
|
82
93
|
* formProps={{
|
|
83
94
|
* buttonLabel: "Update Product",
|
|
84
|
-
* schema: productSchema
|
|
95
|
+
* schema: productSchema,
|
|
85
96
|
* }}
|
|
86
97
|
* />
|
|
87
98
|
* ```
|
|
88
99
|
*/
|
|
89
|
-
export default function UpdateDataWrapper({ id,
|
|
100
|
+
export default function UpdateDataWrapper<Input extends FieldValues, Response, FormProps extends Record<string, any> = Record<string, any>>({ id, Form, useMutation, useQuery, doAfterSuccessUpdate, cleanDataBeforeUpdate, formProps, params, }: UpdateDataWrapperProps<Input, Response, FormProps>): import("react/jsx-runtime").JSX.Element;
|
|
90
101
|
export {};
|
|
91
102
|
//# sourceMappingURL=update-data-wrapper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-data-wrapper.d.ts","sourceRoot":"","sources":["../../../src/components/data-manipulation/update-data-wrapper.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update-data-wrapper.d.ts","sourceRoot":"","sources":["../../../src/components/data-manipulation/update-data-wrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB;;;;;;GAMG;AACH,KAAK,sBAAsB,CACzB,KAAK,SAAS,WAAW,EACzB,QAAQ,EACR,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IACzD;IACF,iCAAiC;IACjC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,iDAAiD;IACjD,IAAI,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;IACxC;;;;;;;OAOG;IACH,WAAW,EAAE,MAAM,GAAG,CAAC;IACvB;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAC/B;;;;;;;OAOG;IACH,oBAAoB,CAAC,EAAE,CAAC,CAAC,EAAE;QACzB,QAAQ,EAAE,QAAQ,CAAC;QACnB,IAAI,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;KAC5B,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAC1B;;;;;;OAMG;IACH,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,KAAK,CAAC;IAC/C,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,kDAAkD;IAClD,SAAS,EAAE,SAAS,GAAG;QACrB,yCAAyC;QACzC,WAAW,EAAE,MAAM,CAAC;QACpB,2CAA2C;QAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,+DAA+D;QAC/D,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,kFAAkF;QAClF,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACnC,0CAA0C;QAC1C,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;KAC1B,CAAC;CACH,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACvC,KAAK,SAAS,WAAW,EACzB,QAAQ,EACR,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3D,EACA,EAAE,EACF,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,oBAAoB,EACpB,qBAAsC,EACtC,SAAS,EACT,MAAM,GACP,EAAE,sBAAsB,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,2CA0DpD"}
|
|
@@ -5,76 +5,81 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = UpdateDataWrapper;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
const change_case_all_1 = require("change-case-all");
|
|
9
8
|
const react_1 = require("react");
|
|
10
|
-
const
|
|
9
|
+
const core_1 = require("@nomos-ui/core");
|
|
10
|
+
const utils_1 = require("@nomos-ui/core/utils");
|
|
11
11
|
const query_boundary_1 = __importDefault(require("../query-boundary"));
|
|
12
12
|
/**
|
|
13
|
-
* A generic
|
|
13
|
+
* A generic wrapper that handles data update logic independently of the query library.
|
|
14
|
+
* Supports both RTK Query and TanStack Query via the provider config.
|
|
14
15
|
*
|
|
15
|
-
*
|
|
16
|
-
* -
|
|
17
|
-
* -
|
|
18
|
-
* -
|
|
19
|
-
* -
|
|
20
|
-
* -
|
|
16
|
+
* Responsibilities:
|
|
17
|
+
* - Fetches existing record via useQuery and populates form default values
|
|
18
|
+
* - Calls the provided mutation hook
|
|
19
|
+
* - Extracts and normalizes the trigger function based on the query library
|
|
20
|
+
* - Passes all raw mutation state directly to the Form (no normalization)
|
|
21
|
+
* - Handles submit orchestration: cleaning data, triggering mutation, running callbacks, resetting form
|
|
22
|
+
*
|
|
23
|
+
* @template Input - The shape of the form values / data being submitted
|
|
24
|
+
* @template Response - The shape of the API response returned after successful update
|
|
25
|
+
* @template FormProps - Additional props accepted by the Form component
|
|
21
26
|
*
|
|
22
27
|
* @example
|
|
23
28
|
* ```tsx
|
|
24
|
-
* <UpdateDataWrapper
|
|
25
|
-
* id=
|
|
26
|
-
* name="product"
|
|
29
|
+
* <UpdateDataWrapper<UpdateProductInput, Product, ProductFormProps>
|
|
30
|
+
* id={productId}
|
|
27
31
|
* Form={ProductForm}
|
|
32
|
+
* useMutation={useUpdateProductMutation}
|
|
33
|
+
* useQuery={useGetProductQuery}
|
|
34
|
+
* doAfterSuccessUpdate={({ response }) => router.push(`/products`)}
|
|
28
35
|
* formProps={{
|
|
29
36
|
* buttonLabel: "Update Product",
|
|
30
|
-
* schema: productSchema
|
|
37
|
+
* schema: productSchema,
|
|
31
38
|
* }}
|
|
32
39
|
* />
|
|
33
40
|
* ```
|
|
34
41
|
*/
|
|
35
|
-
function UpdateDataWrapper({ id,
|
|
36
|
-
const
|
|
37
|
-
const
|
|
42
|
+
function UpdateDataWrapper({ id, Form, useMutation, useQuery, doAfterSuccessUpdate, cleanDataBeforeUpdate = (data) => data, formProps, params, }) {
|
|
43
|
+
const { config } = (0, core_1.useProvider)();
|
|
44
|
+
const mutationResult = useMutation();
|
|
45
|
+
const { trigger, state } = (0, utils_1.extractMutation)(mutationResult, config.queryLibrary);
|
|
38
46
|
const [fetchedData, setFetchedData] = (0, react_1.useState)();
|
|
39
47
|
const [dataForm, setDataForm] = (0, react_1.useState)();
|
|
40
48
|
(0, react_1.useEffect)(() => {
|
|
41
49
|
dataForm?.reset(fetchedData);
|
|
42
50
|
}, [fetchedData]);
|
|
43
51
|
/**
|
|
44
|
-
* Handles form submission and data update
|
|
45
|
-
*
|
|
52
|
+
* Handles form submission and data update.
|
|
53
|
+
* Cleans the data, triggers the mutation with id + body, runs the success callback, and resets the form.
|
|
46
54
|
*
|
|
47
|
-
* @param data
|
|
48
|
-
* @param form
|
|
55
|
+
* @param data - The validated form data
|
|
56
|
+
* @param form - The react-hook-form instance
|
|
57
|
+
* @param onError - Optional callback invoked with the original data and error on failure
|
|
49
58
|
*/
|
|
50
|
-
|
|
51
|
-
const cleanedData = cleanDataBeforeUpdate(data
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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 }));
|
|
59
|
+
const handleUpdateData = (0, react_1.useCallback)(async function (data, form, onError) {
|
|
60
|
+
const cleanedData = cleanDataBeforeUpdate(data);
|
|
61
|
+
try {
|
|
62
|
+
const response = await trigger({ id, body: cleanedData });
|
|
63
|
+
await doAfterSuccessUpdate?.({ response, data: cleanedData, form });
|
|
64
64
|
form.reset({ ...data, ...fetchedData });
|
|
65
65
|
setDataForm(form);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
return response;
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
onError?.(data, err);
|
|
70
|
+
return err;
|
|
71
|
+
}
|
|
72
|
+
}, [trigger, id, fetchedData]);
|
|
73
|
+
return ((0, jsx_runtime_1.jsx)(query_boundary_1.default, { useQuery: useQuery, successComponentProps: {
|
|
70
74
|
formProps: { ...state, ...formProps, onSubmit: handleUpdateData },
|
|
71
|
-
Form
|
|
75
|
+
Form,
|
|
72
76
|
fetchedData,
|
|
73
77
|
setFetchedData,
|
|
74
|
-
}, SuccessComponent: SuccessComponent,
|
|
78
|
+
}, SuccessComponent: SuccessComponent, params: { id, ...params }, showReloadAgainButton: false }));
|
|
75
79
|
}
|
|
76
80
|
/**
|
|
77
|
-
*
|
|
81
|
+
* Internal component that renders the form with fetched data.
|
|
82
|
+
* Sets the fetched data on mount so the form can populate default values.
|
|
78
83
|
*/
|
|
79
84
|
function SuccessComponent({ data, Form, formProps, setFetchedData, }) {
|
|
80
85
|
(0, react_1.useEffect)(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-data-wrapper.js","sourceRoot":"","sources":["../../../src/components/data-manipulation/update-data-wrapper.tsx"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"update-data-wrapper.js","sourceRoot":"","sources":["../../../src/components/data-manipulation/update-data-wrapper.tsx"],"names":[],"mappings":";;;;;AA4GA,oCAuEC;;AAnLD,iCAAgE;AAGhE,yCAA6C;AAC7C,gDAAuD;AACvD,uEAA8C;AAyE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,SAAwB,iBAAiB,CAIvC,EACA,EAAE,EACF,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,oBAAoB,EACpB,qBAAqB,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EACtC,SAAS,EACT,MAAM,GAC6C;IACnD,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,kBAAW,GAAE,CAAC;IACjC,MAAM,cAAc,GAAG,WAAW,EAAE,CAAC;IACrC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAA,uBAAe,EACxC,cAAc,EACd,MAAM,CAAC,YAAY,CACpB,CAAC;IAEF,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;;;;;;;OAOG;IACH,MAAM,gBAAgB,GAAG,IAAA,mBAAW,EAClC,KAAK,WACH,IAAW,EACX,IAA0B,EAC1B,OAA2C;QAE3C,MAAM,WAAW,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,EAAS,CAAC,CAAC;YACjE,MAAM,oBAAoB,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;YACpE,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,WAAW,EAAE,CAAC,CAAC;YACxC,WAAW,CAAC,IAAW,CAAC,CAAC;YACzB,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,EAAE,EAAE,EAAE,WAAW,CAAC,CAC3B,CAAC;IAEF,OAAO,CACL,uBAAC,wBAAa,IACZ,QAAQ,EAAE,QAAQ,EAClB,qBAAqB,EAAE;YACrB,SAAS,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,SAAS,EAAE,QAAQ,EAAE,gBAAgB,EAAE;YACjE,IAAI;YACJ,WAAW;YACX,cAAc;SACf,EACD,gBAAgB,EAAE,gBAAgB,EAClC,MAAM,EAAE,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,EACzB,qBAAqB,EAAE,KAAK,GAC5B,CACH,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CAAC,EACxB,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,cAAc,GASf;IACC,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,OAAO,uBAAC,IAAI,OAAK,SAAS,EAAE,aAAa,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,GAAI,CAAC;AAC9E,CAAC"}
|
|
@@ -1,71 +1,96 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { FieldValues, UseFormReturn } from "react-hook-form";
|
|
3
4
|
import { ModalProps } from "@nomos-ui/common/modals";
|
|
4
5
|
/**
|
|
5
6
|
* Props for the UpdateDataModal component
|
|
6
|
-
*
|
|
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 update
|
|
10
|
+
* @template FormProps - Additional props accepted by the Form component
|
|
7
11
|
*/
|
|
8
|
-
export type UpdateDataModalProps<
|
|
9
|
-
/**
|
|
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 UpdateDataModalProps<Input extends FieldValues, Response, FormProps extends Record<string, any> = Record<string, any>> = {
|
|
13
|
+
/** ID of the record to update */
|
|
14
|
+
id?: string | number;
|
|
13
15
|
/** Form component rendered inside the modal */
|
|
14
16
|
Form: (props: any) => React.JSX.Element;
|
|
15
17
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
+
* The mutation hook to call for data update.
|
|
19
|
+
* Pass the hook itself (e.g. useUpdateProductMutation), not its result.
|
|
20
|
+
* The component will call it internally following React's rules of hooks.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* useMutation={useUpdateProductMutation}
|
|
24
|
+
*/
|
|
25
|
+
useMutation: () => any;
|
|
26
|
+
/**
|
|
27
|
+
* The query hook to fetch the existing record.
|
|
28
|
+
* Pass the hook itself (e.g. useGetProductQuery), not its result.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* useQuery={useGetProductQuery}
|
|
18
32
|
*/
|
|
19
|
-
|
|
33
|
+
useQuery: (params: any, options?: any) => any;
|
|
20
34
|
/** Title displayed in the modal header */
|
|
21
35
|
title: string;
|
|
22
36
|
/** Optional description displayed under the title */
|
|
23
37
|
description?: string;
|
|
24
38
|
/**
|
|
25
|
-
* When true, maintains the form button loading state after submission
|
|
26
|
-
* Useful for extra processing after data update
|
|
39
|
+
* When true, maintains the form button loading state after submission.
|
|
40
|
+
* Useful for extra processing after data update.
|
|
27
41
|
*/
|
|
28
42
|
keepIsLoading?: boolean;
|
|
29
43
|
/** Additional data passed to the form */
|
|
30
44
|
requiredData?: Record<string, any>;
|
|
31
|
-
/** Whether to show alert after success */
|
|
32
|
-
showAlertAfterSuccessUpdate?: boolean;
|
|
33
45
|
/**
|
|
34
|
-
* Callback executed after successful update
|
|
35
|
-
* Receives
|
|
46
|
+
* Callback executed after successful update and modal close.
|
|
47
|
+
* Receives the API response, the cleaned submitted data, and the form instance.
|
|
48
|
+
*
|
|
49
|
+
* @param x.response - The raw API response
|
|
50
|
+
* @param x.data - The cleaned data that was submitted
|
|
51
|
+
* @param x.form - The react-hook-form instance typed to Input
|
|
36
52
|
*/
|
|
37
|
-
doAfterSuccessUpdate?: (x:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
doAfterSuccessUpdate?: (x: {
|
|
54
|
+
response: Response;
|
|
55
|
+
data: Input;
|
|
56
|
+
form: UseFormReturn<Input>;
|
|
57
|
+
}) => Promise<any> | void;
|
|
58
|
+
/**
|
|
59
|
+
* Optional function to transform or clean the form data before submission.
|
|
60
|
+
* Defaults to an identity function (returns data as-is).
|
|
61
|
+
*/
|
|
62
|
+
cleanDataBeforeUpdate?: (data: Input) => Input;
|
|
63
|
+
/** Props that apply to Radix Dialog content wrapper */
|
|
64
|
+
contentProps?: Omit<ModalProps, "children">;
|
|
42
65
|
/** Zod schema for form validation */
|
|
43
66
|
schema: z.ZodObject<any>;
|
|
44
|
-
/** Buttons displayed next to the modal title */
|
|
45
|
-
topButtons?: React.ReactNode;
|
|
46
67
|
/** Additional props forwarded to the form */
|
|
47
68
|
formProps?: FormProps;
|
|
48
|
-
/**
|
|
49
|
-
|
|
69
|
+
/** Additional parameters passed to the query hook for data fetching */
|
|
70
|
+
params?: Record<string, any>;
|
|
50
71
|
};
|
|
51
72
|
/**
|
|
52
73
|
* A generic modal component for updating data with form validation.
|
|
74
|
+
* Wraps UpdateDataWrapper inside a Modal, handling modal close after successful update.
|
|
53
75
|
*
|
|
54
|
-
* @template
|
|
55
|
-
* @
|
|
76
|
+
* @template Input - The shape of the form values / data being submitted
|
|
77
|
+
* @template Response - The shape of the API response returned after successful update
|
|
78
|
+
* @template FormProps - Additional props accepted by the Form component
|
|
56
79
|
*
|
|
57
80
|
* @example
|
|
58
81
|
* ```tsx
|
|
59
|
-
* <UpdateDataModal<
|
|
60
|
-
*
|
|
61
|
-
* title="Edit
|
|
62
|
-
* schema={
|
|
63
|
-
* Form={
|
|
82
|
+
* <UpdateDataModal<UpdateProductInput, Product, ProductFormProps>
|
|
83
|
+
* id={productId}
|
|
84
|
+
* title="Edit Product"
|
|
85
|
+
* schema={productSchema}
|
|
86
|
+
* Form={ProductForm}
|
|
87
|
+
* useMutation={useUpdateProductMutation}
|
|
88
|
+
* useQuery={useGetProductQuery}
|
|
89
|
+
* formProps={{ buttonLabel: "Save Changes" }}
|
|
64
90
|
* isOpen={isOpen}
|
|
65
91
|
* setIsOpen={setIsOpen}
|
|
66
|
-
* formProps={{ buttonLabel: "Save Changes" }}
|
|
67
92
|
* />
|
|
68
93
|
* ```
|
|
69
94
|
*/
|
|
70
|
-
export default function UpdateDataModal<
|
|
95
|
+
export default function UpdateDataModal<Input extends FieldValues, Response, FormProps extends Record<string, any> = Record<string, any>>({ id, title, description, keepIsLoading, requiredData, schema, formProps, isOpen, setIsOpen, showConfirmButton, doAfterSuccessUpdate, cleanDataBeforeUpdate, contentProps, Form, useMutation, useQuery, params, }: UpdateDataModalProps<Input, Response, FormProps> & Partial<ModalProps>): import("react/jsx-runtime").JSX.Element;
|
|
71
96
|
//# sourceMappingURL=update.modal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.modal.d.ts","sourceRoot":"","sources":["../../../src/components/modals/update.modal.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update.modal.d.ts","sourceRoot":"","sources":["../../../src/components/modals/update.modal.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsB,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,EAAS,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAG5D;;;;;;GAMG;AACH,MAAM,MAAM,oBAAoB,CAC9B,KAAK,SAAS,WAAW,EACzB,QAAQ,EACR,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IACzD;IACF,iCAAiC;IACjC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,+CAA+C;IAC/C,IAAI,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;IACxC;;;;;;;OAOG;IACH,WAAW,EAAE,MAAM,GAAG,CAAC;IACvB;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC;IAC9C,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,yCAAyC;IACzC,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,CAAC,CAAC;KAC5B,KAAK,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAC1B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,KAAK,CAAC;IAC/C,uDAAuD;IACvD,YAAY,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC5C,qCAAqC;IACrC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACzB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,KAAK,SAAS,WAAW,EACzB,QAAQ,EACR,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3D,EACA,EAAE,EACF,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,EACX,QAAQ,EACR,MAAM,GACP,EAAE,oBAAoB,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,2CAkDxE"}
|
|
@@ -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 };
|
|
@@ -12,36 +11,41 @@ const modals_1 = require("@nomos-ui/common/modals");
|
|
|
12
11
|
const update_data_wrapper_1 = __importDefault(require("../data-manipulation/update-data-wrapper"));
|
|
13
12
|
/**
|
|
14
13
|
* A generic modal component for updating data with form validation.
|
|
14
|
+
* Wraps UpdateDataWrapper inside a Modal, handling modal close after successful update.
|
|
15
15
|
*
|
|
16
|
-
* @template
|
|
17
|
-
* @
|
|
16
|
+
* @template Input - The shape of the form values / data being submitted
|
|
17
|
+
* @template Response - The shape of the API response returned after successful update
|
|
18
|
+
* @template FormProps - Additional props accepted by the Form component
|
|
18
19
|
*
|
|
19
20
|
* @example
|
|
20
21
|
* ```tsx
|
|
21
|
-
* <UpdateDataModal<
|
|
22
|
-
*
|
|
23
|
-
* title="Edit
|
|
24
|
-
* schema={
|
|
25
|
-
* Form={
|
|
22
|
+
* <UpdateDataModal<UpdateProductInput, Product, ProductFormProps>
|
|
23
|
+
* id={productId}
|
|
24
|
+
* title="Edit Product"
|
|
25
|
+
* schema={productSchema}
|
|
26
|
+
* Form={ProductForm}
|
|
27
|
+
* useMutation={useUpdateProductMutation}
|
|
28
|
+
* useQuery={useGetProductQuery}
|
|
29
|
+
* formProps={{ buttonLabel: "Save Changes" }}
|
|
26
30
|
* isOpen={isOpen}
|
|
27
31
|
* setIsOpen={setIsOpen}
|
|
28
|
-
* formProps={{ buttonLabel: "Save Changes" }}
|
|
29
32
|
* />
|
|
30
33
|
* ```
|
|
31
34
|
*/
|
|
32
|
-
function UpdateDataModal({
|
|
35
|
+
function UpdateDataModal({ id, title, description, keepIsLoading, requiredData, schema, formProps, isOpen, setIsOpen, showConfirmButton, doAfterSuccessUpdate, cleanDataBeforeUpdate, contentProps, Form, useMutation, useQuery, params, }) {
|
|
33
36
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
37
|
+
* Closes the modal then fires the post-update callback if provided.
|
|
38
|
+
*
|
|
39
|
+
* @param x - The object received from UpdateDataWrapper's doAfterSuccessUpdate
|
|
36
40
|
*/
|
|
37
|
-
const handleCloseModal = (0, react_1.useCallback)(function handleCloseModal(
|
|
41
|
+
const handleCloseModal = (0, react_1.useCallback)(async function handleCloseModal(x) {
|
|
38
42
|
setIsOpen(false);
|
|
39
|
-
doAfterSuccessUpdate(
|
|
40
|
-
}, [
|
|
43
|
+
await doAfterSuccessUpdate?.(x);
|
|
44
|
+
}, [doAfterSuccessUpdate, setIsOpen]);
|
|
41
45
|
return ((0, jsx_runtime_1.jsx)(modals_1.Modal, { title: title, description: description, setIsOpen: setIsOpen, isOpen: isOpen, showConfirmButton: showConfirmButton, contentProps: {
|
|
42
46
|
...contentProps,
|
|
43
47
|
className: (0, tailwind_merge_1.twMerge)(contentProps?.className, "max-h-[80vh] md:max-h-[90vh] overflow-auto"),
|
|
44
|
-
}, children: (0, jsx_runtime_1.jsx)(update_data_wrapper_1.default, {
|
|
48
|
+
}, children: (0, jsx_runtime_1.jsx)(update_data_wrapper_1.default, { id: id, Form: Form, useMutation: useMutation, useQuery: useQuery, cleanDataBeforeUpdate: cleanDataBeforeUpdate, doAfterSuccessUpdate: handleCloseModal, params: params, formProps: {
|
|
45
49
|
...formProps,
|
|
46
50
|
keepIsLoading,
|
|
47
51
|
requiredData,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.modal.js","sourceRoot":"","sources":["../../../src/components/modals/update.modal.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update.modal.js","sourceRoot":"","sources":["../../../src/components/modals/update.modal.tsx"],"names":[],"mappings":";;;;;AAsGA,kCAwEC;;AA9KD,iCAA2C;AAG3C,mDAAyC;AACzC,oDAA4D;AAC5D,mGAAyE;AA0EzE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAwB,eAAe,CAIrC,EACA,EAAE,EACF,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,EACX,QAAQ,EACR,MAAM,GACiE;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,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,QAAQ,EAClB,qBAAqB,EAAE,qBAAqB,EAC5C,oBAAoB,EAAE,gBAAgB,EACtC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE;gBACT,GAAI,SAAiB;gBACrB,aAAa;gBACb,YAAY;gBACZ,MAAM;aACP,GACD,GACI,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = CreateDataPage;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
const navigation_1 = require("next/navigation");
|
|
9
8
|
const create_data_wrapper_1 = __importDefault(require("../../data-manipulation/create-data-wrapper"));
|
|
10
9
|
const page_title_and_description_1 = __importDefault(require("../components/page-title-and-description"));
|
|
10
|
+
const hooks_1 = require("@nomos-ui/core/hooks");
|
|
11
11
|
/**
|
|
12
12
|
* A generic page component for creating data with form validation.
|
|
13
13
|
* Wraps CreateDataWrapper inside a page layout with a title, description, and optional top buttons.
|
|
@@ -29,7 +29,7 @@ const page_title_and_description_1 = __importDefault(require("../components/page
|
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
function CreateDataPage({ title, description, keepIsLoading, requiredData, schema, formProps, topButtons, Form, useMutation, doAfterSuccessCreate, cleanDataBeforeCreate, }) {
|
|
32
|
-
const pathname = (0,
|
|
32
|
+
const pathname = (0, hooks_1.usePathname)();
|
|
33
33
|
const listHref = pathname.split("/");
|
|
34
34
|
listHref.pop();
|
|
35
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: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/pages/create-data-page/index.tsx"],"names":[],"mappings":";;;;;AA4FA,iCAwDC;;AAjJD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/pages/create-data-page/index.tsx"],"names":[],"mappings":";;;;;AA4FA,iCAwDC;;AAjJD,sGAA4E;AAC5E,0GAA+E;AAC/E,gDAAmD;AAmEnD;;;;;;;;;;;;;;;;;;;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,mBAAW,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"}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
import { ListPageProps } from "./list-page";
|
|
2
2
|
import { ListPageTemplateProps } from "./template";
|
|
3
3
|
import { BaseData } from "./table/table";
|
|
4
|
+
/**
|
|
5
|
+
* Props for the HeaderActionButtons component
|
|
6
|
+
*
|
|
7
|
+
* @template T - The type of data being listed
|
|
8
|
+
*/
|
|
4
9
|
type HeaderActionButtonsProps<T extends BaseData> = Partial<ListPageTemplateProps<T>>;
|
|
10
|
+
/**
|
|
11
|
+
* Renders the create button and optional top buttons in the list page header.
|
|
12
|
+
* Navigates to the create page by default, or calls the provided onClickCreate callback.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The type of data being listed
|
|
15
|
+
*/
|
|
5
16
|
export default function HeaderActionButtons<T extends BaseData>({ topButtons, onClickCreate, }: HeaderActionButtonsProps<T> & Partial<ListPageProps<T>>): import("react/jsx-runtime").JSX.Element;
|
|
6
17
|
export {};
|
|
7
18
|
//# sourceMappingURL=header-action-buttons.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"header-action-buttons.d.ts","sourceRoot":"","sources":["../../../../src/components/pages/list-page/header-action-buttons.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"header-action-buttons.d.ts","sourceRoot":"","sources":["../../../../src/components/pages/list-page/header-action-buttons.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;GAIG;AACH,KAAK,wBAAwB,CAAC,CAAC,SAAS,QAAQ,IAAI,OAAO,CACzD,qBAAqB,CAAC,CAAC,CAAC,CACzB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,CAAC,SAAS,QAAQ,EAAE,EAC9D,UAAU,EACV,aAAa,GACd,EAAE,wBAAwB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,2CAuBzD"}
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
"use client";
|
|
2
1
|
"use strict";
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.default = HeaderActionButtons;
|
|
5
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
5
|
const lucide_react_1 = require("lucide-react");
|
|
7
|
-
const
|
|
6
|
+
const hooks_1 = require("@nomos-ui/core/hooks");
|
|
8
7
|
const common_1 = require("@nomos-ui/common");
|
|
8
|
+
/**
|
|
9
|
+
* Renders the create button and optional top buttons in the list page header.
|
|
10
|
+
* Navigates to the create page by default, or calls the provided onClickCreate callback.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The type of data being listed
|
|
13
|
+
*/
|
|
9
14
|
function HeaderActionButtons({ topButtons, onClickCreate, }) {
|
|
10
|
-
const pathname = (0,
|
|
11
|
-
const
|
|
12
|
-
return ((0, jsx_runtime_1.jsx)("div", { className: "
|
|
15
|
+
const pathname = (0, hooks_1.usePathname)();
|
|
16
|
+
const navigate = (0, hooks_1.useNavigate)();
|
|
17
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "flex items-center justify-between small-sm:mb-2 overflow-auto", children: (0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2", children: [(0, jsx_runtime_1.jsxs)(common_1.Button, { onClick: (e) => {
|
|
13
18
|
if (!onClickCreate)
|
|
14
|
-
|
|
19
|
+
navigate(`${pathname}/create`);
|
|
15
20
|
else
|
|
16
21
|
onClickCreate(e);
|
|
17
|
-
}, children: [(0, jsx_runtime_1.jsx)(lucide_react_1.PlusIcon, { size: 16 }), (0, jsx_runtime_1.jsx)("span", { className: "hidden sm:inline", children: "Adicionar
|
|
22
|
+
}, children: [(0, jsx_runtime_1.jsx)(lucide_react_1.PlusIcon, { size: 16 }), (0, jsx_runtime_1.jsx)("span", { className: "hidden sm:inline", children: "Adicionar" })] }), topButtons &&
|
|
18
23
|
topButtons.map((button, i) => ((0, jsx_runtime_1.jsx)("div", { children: button }, i)))] }) }));
|
|
19
24
|
}
|
|
20
25
|
//# sourceMappingURL=header-action-buttons.js.map
|