@compill/admin 1.0.57 → 1.0.59
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/index.cjs.js +19 -169
- package/index.esm.js +19 -170
- package/package.json +1 -1
- package/src/index.d.ts +8 -7
- package/src/lib/modal/ItemEditDialog.d.ts +0 -33
package/index.cjs.js
CHANGED
@@ -951,12 +951,13 @@ function PageSidebarSection(_a) {
|
|
951
951
|
function PageTitle(_a) {
|
952
952
|
var {
|
953
953
|
children
|
954
|
-
} = _a
|
955
|
-
__rest$1(_a, ["children"]);
|
956
|
-
return jsxRuntime.jsx("div", {
|
957
|
-
trait: "typo.h5"
|
954
|
+
} = _a,
|
955
|
+
props = __rest$1(_a, ["children"]);
|
956
|
+
return jsxRuntime.jsx("div", Object.assign({
|
957
|
+
trait: "typo.h5"
|
958
|
+
}, props, {
|
958
959
|
children: children
|
959
|
-
});
|
960
|
+
}));
|
960
961
|
}
|
961
962
|
|
962
963
|
function PageTopBar(_a) {
|
@@ -1940,8 +1941,8 @@ function TableMassActions({
|
|
1940
1941
|
});
|
1941
1942
|
}
|
1942
1943
|
|
1943
|
-
const defaultErrorMsg$
|
1944
|
-
function nonNullValues
|
1944
|
+
const defaultErrorMsg$1 = "Oops, something went wrong...";
|
1945
|
+
function nonNullValues(data) {
|
1945
1946
|
var _a;
|
1946
1947
|
if (data) {
|
1947
1948
|
const nonNullData = Object.assign({}, data);
|
@@ -1950,7 +1951,7 @@ function nonNullValues$1(data) {
|
|
1950
1951
|
}
|
1951
1952
|
return data;
|
1952
1953
|
}
|
1953
|
-
function ItemEditDialog
|
1954
|
+
function ItemEditDialog(_a) {
|
1954
1955
|
var _b, _c, _d, _e;
|
1955
1956
|
var {
|
1956
1957
|
initialValues,
|
@@ -1961,9 +1962,9 @@ function ItemEditDialog$1(_a) {
|
|
1961
1962
|
querySaveOptions,
|
1962
1963
|
onSuccess,
|
1963
1964
|
onFetchError,
|
1964
|
-
fetchErrorMsg = defaultErrorMsg$
|
1965
|
+
fetchErrorMsg = defaultErrorMsg$1,
|
1965
1966
|
onSaveError,
|
1966
|
-
saveErrorMsg = defaultErrorMsg$
|
1967
|
+
saveErrorMsg = defaultErrorMsg$1,
|
1967
1968
|
fetchToFormData,
|
1968
1969
|
formToQueryData,
|
1969
1970
|
invalidateQueriesOnSuccess = true,
|
@@ -2051,7 +2052,7 @@ function ItemEditDialog$1(_a) {
|
|
2051
2052
|
// initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
|
2052
2053
|
, Object.assign({
|
2053
2054
|
// initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
|
2054
|
-
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues
|
2055
|
+
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : (_e = nonNullValues(initialValues(data))) !== null && _e !== void 0 ? _e : {},
|
2055
2056
|
onSubmit: saveItem
|
2056
2057
|
}, formikProps, {
|
2057
2058
|
children: ({
|
@@ -2120,7 +2121,7 @@ function QueryWrapperDialog({
|
|
2120
2121
|
}, [data, fn, transformFn]);
|
2121
2122
|
if (isFetching) return null;
|
2122
2123
|
// @ts-ignore
|
2123
|
-
return jsxRuntime.jsx(ItemEditDialog
|
2124
|
+
return jsxRuntime.jsx(ItemEditDialog, Object.assign({}, config(transformedData), {
|
2124
2125
|
queryId: queryId,
|
2125
2126
|
invalidateQueryKey: invalidateQueryKey,
|
2126
2127
|
show: true,
|
@@ -2158,7 +2159,7 @@ function MultiQueryWrapperDialog({
|
|
2158
2159
|
// if (isFetching)
|
2159
2160
|
// return null
|
2160
2161
|
// @ts-ignore
|
2161
|
-
return jsxRuntime.jsx(ItemEditDialog
|
2162
|
+
return jsxRuntime.jsx(ItemEditDialog, Object.assign({
|
2162
2163
|
isPreloading: isFetching
|
2163
2164
|
}, config(...transformedData), {
|
2164
2165
|
queryId: queryId,
|
@@ -2175,7 +2176,7 @@ function DialogRenderer({
|
|
2175
2176
|
queryId
|
2176
2177
|
}) {
|
2177
2178
|
const props = __rest$1(config, ["type"]);
|
2178
|
-
if (config.type === "dialog") return jsxRuntime.jsx(ItemEditDialog
|
2179
|
+
if (config.type === "dialog") return jsxRuntime.jsx(ItemEditDialog, Object.assign({}, props, {
|
2179
2180
|
queryId: queryId,
|
2180
2181
|
invalidateQueryKey: invalidateQueryKey,
|
2181
2182
|
show: true,
|
@@ -3050,7 +3051,7 @@ function LeftPanel({
|
|
3050
3051
|
});
|
3051
3052
|
}
|
3052
3053
|
|
3053
|
-
const defaultErrorMsg
|
3054
|
+
const defaultErrorMsg = "Oops, something went wrong...";
|
3054
3055
|
function AttachDialog(_a) {
|
3055
3056
|
var {
|
3056
3057
|
queryId,
|
@@ -3066,9 +3067,9 @@ function AttachDialog(_a) {
|
|
3066
3067
|
itemLabel,
|
3067
3068
|
onSuccess,
|
3068
3069
|
onFetchError,
|
3069
|
-
fetchErrorMsg = defaultErrorMsg
|
3070
|
+
fetchErrorMsg = defaultErrorMsg,
|
3070
3071
|
onSaveError,
|
3071
|
-
saveErrorMsg = defaultErrorMsg
|
3072
|
+
saveErrorMsg = defaultErrorMsg,
|
3072
3073
|
invalidateQueriesOnSuccess = true,
|
3073
3074
|
retryText = "Retry",
|
3074
3075
|
cancelLabel = "Cancel",
|
@@ -3295,158 +3296,6 @@ function FormActionDialog(_a) {
|
|
3295
3296
|
}));
|
3296
3297
|
}
|
3297
3298
|
|
3298
|
-
const defaultErrorMsg = "Oops, something went wrong...";
|
3299
|
-
function nonNullValues(data) {
|
3300
|
-
var _a;
|
3301
|
-
if (data) {
|
3302
|
-
const nonNullData = Object.assign({}, data);
|
3303
|
-
for (const key in data) nonNullData[key] = (_a = nonNullData[key]) !== null && _a !== void 0 ? _a : "";
|
3304
|
-
return nonNullData;
|
3305
|
-
}
|
3306
|
-
return data;
|
3307
|
-
}
|
3308
|
-
function ItemEditDialog(_a) {
|
3309
|
-
var _b, _c, _d, _e;
|
3310
|
-
var {
|
3311
|
-
initialValues,
|
3312
|
-
itemLabel,
|
3313
|
-
queryId = "",
|
3314
|
-
queryKey,
|
3315
|
-
queryFetchFn,
|
3316
|
-
queryFetchOptions,
|
3317
|
-
querySaveFn,
|
3318
|
-
querySaveOptions,
|
3319
|
-
onSuccess,
|
3320
|
-
onFetchError,
|
3321
|
-
fetchErrorMsg = defaultErrorMsg,
|
3322
|
-
onSaveError,
|
3323
|
-
saveErrorMsg = defaultErrorMsg,
|
3324
|
-
fetchToFormData,
|
3325
|
-
formToQueryData,
|
3326
|
-
invalidateQueriesOnSuccess = true,
|
3327
|
-
invalidateQueryKey,
|
3328
|
-
retryText = "Retry",
|
3329
|
-
cancelLabel = "Cancel",
|
3330
|
-
saveLabel,
|
3331
|
-
size = "lg",
|
3332
|
-
title,
|
3333
|
-
form: form$1,
|
3334
|
-
show,
|
3335
|
-
onClose,
|
3336
|
-
formikProps
|
3337
|
-
} = _a,
|
3338
|
-
props = __rest$1(_a, ["initialValues", "itemLabel", "queryId", "queryKey", "queryFetchFn", "queryFetchOptions", "querySaveFn", "querySaveOptions", "onSuccess", "onFetchError", "fetchErrorMsg", "onSaveError", "saveErrorMsg", "fetchToFormData", "formToQueryData", "invalidateQueriesOnSuccess", "invalidateQueryKey", "retryText", "cancelLabel", "saveLabel", "size", "title", "form", "show", "onClose", "formikProps"]);
|
3339
|
-
const {
|
3340
|
-
isInitialLoading,
|
3341
|
-
isFetching,
|
3342
|
-
data,
|
3343
|
-
isError,
|
3344
|
-
error /*, error*/,
|
3345
|
-
refetch
|
3346
|
-
} = api.useApiQuery(queryKey, queryFetchFn, queryId, Object.assign({
|
3347
|
-
enabled: !( /*queryId == 0 || */queryId == "" || queryId == null || queryId == undefined),
|
3348
|
-
onError: onFetchError
|
3349
|
-
}, queryFetchOptions));
|
3350
|
-
// const [activeTab, setActiveTab] = React.useState(form && Array.isArray(form) ? form[0].key : "");
|
3351
|
-
// const [showTab, setShowTab] = React.useState(true);
|
3352
|
-
const mutation = invalidateQueriesOnSuccess ? api.useInvalidateParentMutation(querySaveFn, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : queryKey, querySaveOptions) : api.useApiMutation(querySaveFn, queryKey, queryId, querySaveOptions);
|
3353
|
-
const retry = React__default["default"].useCallback(() => refetch(), [refetch]);
|
3354
|
-
const saveItem = React__default["default"].useCallback((item, actions) => {
|
3355
|
-
// Clear mutation error if any
|
3356
|
-
mutation.reset();
|
3357
|
-
const formItem = formToQueryData ? formToQueryData(item) : Object.assign({}, item);
|
3358
|
-
mutation.mutateAsync(formItem).then(response => {
|
3359
|
-
var _a;
|
3360
|
-
if (onSuccess) onSuccess(formItem, response);else reactToastify.toast.success(`${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title} ${queryId ? "saved" : "created"}`);
|
3361
|
-
// closing delete modal
|
3362
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
3363
|
-
}).catch(error => {
|
3364
|
-
var _a;
|
3365
|
-
console.error("on error", error);
|
3366
|
-
if (onSaveError) onSaveError(item);else reactToastify.toast.error(`Couldn't save ${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title}`);
|
3367
|
-
actions.setSubmitting(false);
|
3368
|
-
});
|
3369
|
-
}, [mutation, formToQueryData, onSuccess, onSaveError, onClose]);
|
3370
|
-
// const switchTab = React.useCallback((tab: string) =>
|
3371
|
-
// {
|
3372
|
-
// setActiveTab(tab);
|
3373
|
-
// setShowTab(false);
|
3374
|
-
// setTimeout(function ()
|
3375
|
-
// {
|
3376
|
-
// setActiveTab(tab);
|
3377
|
-
// setShowTab(true);
|
3378
|
-
// }, 150);
|
3379
|
-
// }, [setActiveTab])
|
3380
|
-
return jsxRuntime.jsxs(ui.Modal, Object.assign({
|
3381
|
-
size: size,
|
3382
|
-
show: show,
|
3383
|
-
onClose: onClose,
|
3384
|
-
scheme: "light",
|
3385
|
-
transition: true
|
3386
|
-
}, props, {
|
3387
|
-
children: [jsxRuntime.jsxs(ui.Modal.Header, {
|
3388
|
-
children: [!isInitialLoading && queryId && `Edit ${title ? title(data) : (_c = (_b = data === null || data === void 0 ? void 0 : data["name"]) !== null && _b !== void 0 ? _b : data === null || data === void 0 ? void 0 : data["title"]) !== null && _c !== void 0 ? _c : ""}`, !queryId && `Create new ${itemLabel !== null && itemLabel !== void 0 ? itemLabel : "item"}`, Array.isArray(form$1) && jsxRuntime.jsx(jsxRuntime.Fragment, {})
|
3389
|
-
// <ul className="nav nav-bold nav-pills">
|
3390
|
-
// {form.map(item =>
|
3391
|
-
// <li key={item.key} className="nav-item cursor-pointer bg-hover-light rounded" onClick={() => switchTab(item.key)}>
|
3392
|
-
// <span className={clsx("nav-link", activeTab === item.key && "active")} data-toggle="tab">{item.label}</span>
|
3393
|
-
// </li>
|
3394
|
-
// )}
|
3395
|
-
// </ul>
|
3396
|
-
]
|
3397
|
-
}), isInitialLoading && jsxRuntime.jsx(ui.Modal.Body, {
|
3398
|
-
children: jsxRuntime.jsx(components.QueryLoadingState, {
|
3399
|
-
minW: "72"
|
3400
|
-
})
|
3401
|
-
}), isError && jsxRuntime.jsx(ui.Modal.Body, {
|
3402
|
-
children: jsxRuntime.jsx(components.RetryOnError, {
|
3403
|
-
label: `${fetchErrorMsg} ${error}`,
|
3404
|
-
onClick: retry
|
3405
|
-
})
|
3406
|
-
}), !isInitialLoading && !isError && jsxRuntime.jsx(jsxRuntime.Fragment, {
|
3407
|
-
children: jsxRuntime.jsx(formik.Formik, Object.assign({
|
3408
|
-
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : (_e = (_d = nonNullValues(data)) !== null && _d !== void 0 ? _d : initialValues) !== null && _e !== void 0 ? _e : {},
|
3409
|
-
onSubmit: saveItem
|
3410
|
-
}, formikProps, {
|
3411
|
-
children: ({
|
3412
|
-
setFieldValue,
|
3413
|
-
dirty,
|
3414
|
-
handleSubmit,
|
3415
|
-
isValid,
|
3416
|
-
values
|
3417
|
-
}) => jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
3418
|
-
children: [jsxRuntime.jsx(ui.Modal.Body, {
|
3419
|
-
pb: "6",
|
3420
|
-
children: jsxRuntime.jsxs(formik.Form, {
|
3421
|
-
children: [/*#__PURE__*/React__default["default"].isValidElement(form$1) && form$1, Array.isArray(form$1) && jsxRuntime.jsx(form.FormRenderer, {
|
3422
|
-
form: form$1
|
3423
|
-
}), react.isFunction(form$1) && jsxRuntime.jsx(form.FormRenderer, {
|
3424
|
-
form: form$1(data !== null && data !== void 0 ? data : values)
|
3425
|
-
})]
|
3426
|
-
})
|
3427
|
-
}), jsxRuntime.jsxs(ui.Modal.Footer, {
|
3428
|
-
dflex: true,
|
3429
|
-
placeContent: "end",
|
3430
|
-
spaceX: "3",
|
3431
|
-
children: [jsxRuntime.jsx(ui.Button, {
|
3432
|
-
disabled: mutation.isLoading,
|
3433
|
-
onClick: onClose,
|
3434
|
-
variant: "borderless",
|
3435
|
-
me: "2",
|
3436
|
-
children: cancelLabel
|
3437
|
-
}), jsxRuntime.jsx(ui.Button, {
|
3438
|
-
type: "submit",
|
3439
|
-
disabled: !dirty || mutation.isLoading /* || !isValid*/,
|
3440
|
-
onClick: () => handleSubmit(),
|
3441
|
-
children: saveLabel ? saveLabel : queryId ? "Update" : "Create"
|
3442
|
-
})]
|
3443
|
-
})]
|
3444
|
-
})
|
3445
|
-
}))
|
3446
|
-
}), mutation.isLoading && jsxRuntime.jsx(components.ModalLoadingOverlay, {})]
|
3447
|
-
}));
|
3448
|
-
}
|
3449
|
-
|
3450
3299
|
function PageSectionTitle(_a) {
|
3451
3300
|
var {
|
3452
3301
|
children
|
@@ -3696,6 +3545,7 @@ exports.ButtonBarDialogButton = ButtonBarDialogButton;
|
|
3696
3545
|
exports.DialogButton = DialogButton;
|
3697
3546
|
exports.FormActionDialog = FormActionDialog;
|
3698
3547
|
exports.InvalidateButton = InvalidateButton;
|
3548
|
+
exports.ItemDeleteDialog = ItemDeleteDialog;
|
3699
3549
|
exports.ItemEditDialog = ItemEditDialog;
|
3700
3550
|
exports.NavigateButton = NavigateButton;
|
3701
3551
|
exports.OrderCell = OrderCell;
|
package/index.esm.js
CHANGED
@@ -942,12 +942,13 @@ function PageSidebarSection(_a) {
|
|
942
942
|
function PageTitle(_a) {
|
943
943
|
var {
|
944
944
|
children
|
945
|
-
} = _a
|
946
|
-
__rest$1(_a, ["children"]);
|
947
|
-
return jsx("div", {
|
948
|
-
trait: "typo.h5"
|
945
|
+
} = _a,
|
946
|
+
props = __rest$1(_a, ["children"]);
|
947
|
+
return jsx("div", Object.assign({
|
948
|
+
trait: "typo.h5"
|
949
|
+
}, props, {
|
949
950
|
children: children
|
950
|
-
});
|
951
|
+
}));
|
951
952
|
}
|
952
953
|
|
953
954
|
function PageTopBar(_a) {
|
@@ -1931,8 +1932,8 @@ function TableMassActions({
|
|
1931
1932
|
});
|
1932
1933
|
}
|
1933
1934
|
|
1934
|
-
const defaultErrorMsg$
|
1935
|
-
function nonNullValues
|
1935
|
+
const defaultErrorMsg$1 = "Oops, something went wrong...";
|
1936
|
+
function nonNullValues(data) {
|
1936
1937
|
var _a;
|
1937
1938
|
if (data) {
|
1938
1939
|
const nonNullData = Object.assign({}, data);
|
@@ -1941,7 +1942,7 @@ function nonNullValues$1(data) {
|
|
1941
1942
|
}
|
1942
1943
|
return data;
|
1943
1944
|
}
|
1944
|
-
function ItemEditDialog
|
1945
|
+
function ItemEditDialog(_a) {
|
1945
1946
|
var _b, _c, _d, _e;
|
1946
1947
|
var {
|
1947
1948
|
initialValues,
|
@@ -1952,9 +1953,9 @@ function ItemEditDialog$1(_a) {
|
|
1952
1953
|
querySaveOptions,
|
1953
1954
|
onSuccess,
|
1954
1955
|
onFetchError,
|
1955
|
-
fetchErrorMsg = defaultErrorMsg$
|
1956
|
+
fetchErrorMsg = defaultErrorMsg$1,
|
1956
1957
|
onSaveError,
|
1957
|
-
saveErrorMsg = defaultErrorMsg$
|
1958
|
+
saveErrorMsg = defaultErrorMsg$1,
|
1958
1959
|
fetchToFormData,
|
1959
1960
|
formToQueryData,
|
1960
1961
|
invalidateQueriesOnSuccess = true,
|
@@ -2042,7 +2043,7 @@ function ItemEditDialog$1(_a) {
|
|
2042
2043
|
// initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
|
2043
2044
|
, Object.assign({
|
2044
2045
|
// initialValues={fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : nonNullValues(data) ?? initialValues(data) ?? {}}
|
2045
|
-
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues
|
2046
|
+
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : (_e = nonNullValues(initialValues(data))) !== null && _e !== void 0 ? _e : {},
|
2046
2047
|
onSubmit: saveItem
|
2047
2048
|
}, formikProps, {
|
2048
2049
|
children: ({
|
@@ -2111,7 +2112,7 @@ function QueryWrapperDialog({
|
|
2111
2112
|
}, [data, fn, transformFn]);
|
2112
2113
|
if (isFetching) return null;
|
2113
2114
|
// @ts-ignore
|
2114
|
-
return jsx(ItemEditDialog
|
2115
|
+
return jsx(ItemEditDialog, Object.assign({}, config(transformedData), {
|
2115
2116
|
queryId: queryId,
|
2116
2117
|
invalidateQueryKey: invalidateQueryKey,
|
2117
2118
|
show: true,
|
@@ -2149,7 +2150,7 @@ function MultiQueryWrapperDialog({
|
|
2149
2150
|
// if (isFetching)
|
2150
2151
|
// return null
|
2151
2152
|
// @ts-ignore
|
2152
|
-
return jsx(ItemEditDialog
|
2153
|
+
return jsx(ItemEditDialog, Object.assign({
|
2153
2154
|
isPreloading: isFetching
|
2154
2155
|
}, config(...transformedData), {
|
2155
2156
|
queryId: queryId,
|
@@ -2166,7 +2167,7 @@ function DialogRenderer({
|
|
2166
2167
|
queryId
|
2167
2168
|
}) {
|
2168
2169
|
const props = __rest$1(config, ["type"]);
|
2169
|
-
if (config.type === "dialog") return jsx(ItemEditDialog
|
2170
|
+
if (config.type === "dialog") return jsx(ItemEditDialog, Object.assign({}, props, {
|
2170
2171
|
queryId: queryId,
|
2171
2172
|
invalidateQueryKey: invalidateQueryKey,
|
2172
2173
|
show: true,
|
@@ -3041,7 +3042,7 @@ function LeftPanel({
|
|
3041
3042
|
});
|
3042
3043
|
}
|
3043
3044
|
|
3044
|
-
const defaultErrorMsg
|
3045
|
+
const defaultErrorMsg = "Oops, something went wrong...";
|
3045
3046
|
function AttachDialog(_a) {
|
3046
3047
|
var {
|
3047
3048
|
queryId,
|
@@ -3057,9 +3058,9 @@ function AttachDialog(_a) {
|
|
3057
3058
|
itemLabel,
|
3058
3059
|
onSuccess,
|
3059
3060
|
onFetchError,
|
3060
|
-
fetchErrorMsg = defaultErrorMsg
|
3061
|
+
fetchErrorMsg = defaultErrorMsg,
|
3061
3062
|
onSaveError,
|
3062
|
-
saveErrorMsg = defaultErrorMsg
|
3063
|
+
saveErrorMsg = defaultErrorMsg,
|
3063
3064
|
invalidateQueriesOnSuccess = true,
|
3064
3065
|
retryText = "Retry",
|
3065
3066
|
cancelLabel = "Cancel",
|
@@ -3286,158 +3287,6 @@ function FormActionDialog(_a) {
|
|
3286
3287
|
}));
|
3287
3288
|
}
|
3288
3289
|
|
3289
|
-
const defaultErrorMsg = "Oops, something went wrong...";
|
3290
|
-
function nonNullValues(data) {
|
3291
|
-
var _a;
|
3292
|
-
if (data) {
|
3293
|
-
const nonNullData = Object.assign({}, data);
|
3294
|
-
for (const key in data) nonNullData[key] = (_a = nonNullData[key]) !== null && _a !== void 0 ? _a : "";
|
3295
|
-
return nonNullData;
|
3296
|
-
}
|
3297
|
-
return data;
|
3298
|
-
}
|
3299
|
-
function ItemEditDialog(_a) {
|
3300
|
-
var _b, _c, _d, _e;
|
3301
|
-
var {
|
3302
|
-
initialValues,
|
3303
|
-
itemLabel,
|
3304
|
-
queryId = "",
|
3305
|
-
queryKey,
|
3306
|
-
queryFetchFn,
|
3307
|
-
queryFetchOptions,
|
3308
|
-
querySaveFn,
|
3309
|
-
querySaveOptions,
|
3310
|
-
onSuccess,
|
3311
|
-
onFetchError,
|
3312
|
-
fetchErrorMsg = defaultErrorMsg,
|
3313
|
-
onSaveError,
|
3314
|
-
saveErrorMsg = defaultErrorMsg,
|
3315
|
-
fetchToFormData,
|
3316
|
-
formToQueryData,
|
3317
|
-
invalidateQueriesOnSuccess = true,
|
3318
|
-
invalidateQueryKey,
|
3319
|
-
retryText = "Retry",
|
3320
|
-
cancelLabel = "Cancel",
|
3321
|
-
saveLabel,
|
3322
|
-
size = "lg",
|
3323
|
-
title,
|
3324
|
-
form,
|
3325
|
-
show,
|
3326
|
-
onClose,
|
3327
|
-
formikProps
|
3328
|
-
} = _a,
|
3329
|
-
props = __rest$1(_a, ["initialValues", "itemLabel", "queryId", "queryKey", "queryFetchFn", "queryFetchOptions", "querySaveFn", "querySaveOptions", "onSuccess", "onFetchError", "fetchErrorMsg", "onSaveError", "saveErrorMsg", "fetchToFormData", "formToQueryData", "invalidateQueriesOnSuccess", "invalidateQueryKey", "retryText", "cancelLabel", "saveLabel", "size", "title", "form", "show", "onClose", "formikProps"]);
|
3330
|
-
const {
|
3331
|
-
isInitialLoading,
|
3332
|
-
isFetching,
|
3333
|
-
data,
|
3334
|
-
isError,
|
3335
|
-
error /*, error*/,
|
3336
|
-
refetch
|
3337
|
-
} = useApiQuery(queryKey, queryFetchFn, queryId, Object.assign({
|
3338
|
-
enabled: !( /*queryId == 0 || */queryId == "" || queryId == null || queryId == undefined),
|
3339
|
-
onError: onFetchError
|
3340
|
-
}, queryFetchOptions));
|
3341
|
-
// const [activeTab, setActiveTab] = React.useState(form && Array.isArray(form) ? form[0].key : "");
|
3342
|
-
// const [showTab, setShowTab] = React.useState(true);
|
3343
|
-
const mutation = invalidateQueriesOnSuccess ? useInvalidateParentMutation(querySaveFn, invalidateQueryKey !== null && invalidateQueryKey !== void 0 ? invalidateQueryKey : queryKey, querySaveOptions) : useApiMutation(querySaveFn, queryKey, queryId, querySaveOptions);
|
3344
|
-
const retry = React.useCallback(() => refetch(), [refetch]);
|
3345
|
-
const saveItem = React.useCallback((item, actions) => {
|
3346
|
-
// Clear mutation error if any
|
3347
|
-
mutation.reset();
|
3348
|
-
const formItem = formToQueryData ? formToQueryData(item) : Object.assign({}, item);
|
3349
|
-
mutation.mutateAsync(formItem).then(response => {
|
3350
|
-
var _a;
|
3351
|
-
if (onSuccess) onSuccess(formItem, response);else toast.success(`${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title} ${queryId ? "saved" : "created"}`);
|
3352
|
-
// closing delete modal
|
3353
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
3354
|
-
}).catch(error => {
|
3355
|
-
var _a;
|
3356
|
-
console.error("on error", error);
|
3357
|
-
if (onSaveError) onSaveError(item);else toast.error(`Couldn't save ${title ? title(formItem) : (_a = formItem.name) !== null && _a !== void 0 ? _a : formItem.title}`);
|
3358
|
-
actions.setSubmitting(false);
|
3359
|
-
});
|
3360
|
-
}, [mutation, formToQueryData, onSuccess, onSaveError, onClose]);
|
3361
|
-
// const switchTab = React.useCallback((tab: string) =>
|
3362
|
-
// {
|
3363
|
-
// setActiveTab(tab);
|
3364
|
-
// setShowTab(false);
|
3365
|
-
// setTimeout(function ()
|
3366
|
-
// {
|
3367
|
-
// setActiveTab(tab);
|
3368
|
-
// setShowTab(true);
|
3369
|
-
// }, 150);
|
3370
|
-
// }, [setActiveTab])
|
3371
|
-
return jsxs(Modal, Object.assign({
|
3372
|
-
size: size,
|
3373
|
-
show: show,
|
3374
|
-
onClose: onClose,
|
3375
|
-
scheme: "light",
|
3376
|
-
transition: true
|
3377
|
-
}, props, {
|
3378
|
-
children: [jsxs(Modal.Header, {
|
3379
|
-
children: [!isInitialLoading && queryId && `Edit ${title ? title(data) : (_c = (_b = data === null || data === void 0 ? void 0 : data["name"]) !== null && _b !== void 0 ? _b : data === null || data === void 0 ? void 0 : data["title"]) !== null && _c !== void 0 ? _c : ""}`, !queryId && `Create new ${itemLabel !== null && itemLabel !== void 0 ? itemLabel : "item"}`, Array.isArray(form) && jsx(Fragment, {})
|
3380
|
-
// <ul className="nav nav-bold nav-pills">
|
3381
|
-
// {form.map(item =>
|
3382
|
-
// <li key={item.key} className="nav-item cursor-pointer bg-hover-light rounded" onClick={() => switchTab(item.key)}>
|
3383
|
-
// <span className={clsx("nav-link", activeTab === item.key && "active")} data-toggle="tab">{item.label}</span>
|
3384
|
-
// </li>
|
3385
|
-
// )}
|
3386
|
-
// </ul>
|
3387
|
-
]
|
3388
|
-
}), isInitialLoading && jsx(Modal.Body, {
|
3389
|
-
children: jsx(QueryLoadingState, {
|
3390
|
-
minW: "72"
|
3391
|
-
})
|
3392
|
-
}), isError && jsx(Modal.Body, {
|
3393
|
-
children: jsx(RetryOnError, {
|
3394
|
-
label: `${fetchErrorMsg} ${error}`,
|
3395
|
-
onClick: retry
|
3396
|
-
})
|
3397
|
-
}), !isInitialLoading && !isError && jsx(Fragment, {
|
3398
|
-
children: jsx(Formik, Object.assign({
|
3399
|
-
initialValues: fetchToFormData && queryId && data ? fetchToFormData(nonNullValues(data)) : (_e = (_d = nonNullValues(data)) !== null && _d !== void 0 ? _d : initialValues) !== null && _e !== void 0 ? _e : {},
|
3400
|
-
onSubmit: saveItem
|
3401
|
-
}, formikProps, {
|
3402
|
-
children: ({
|
3403
|
-
setFieldValue,
|
3404
|
-
dirty,
|
3405
|
-
handleSubmit,
|
3406
|
-
isValid,
|
3407
|
-
values
|
3408
|
-
}) => jsxs(Fragment, {
|
3409
|
-
children: [jsx(Modal.Body, {
|
3410
|
-
pb: "6",
|
3411
|
-
children: jsxs(Form, {
|
3412
|
-
children: [/*#__PURE__*/React.isValidElement(form) && form, Array.isArray(form) && jsx(FormRenderer, {
|
3413
|
-
form: form
|
3414
|
-
}), isFunction(form) && jsx(FormRenderer, {
|
3415
|
-
form: form(data !== null && data !== void 0 ? data : values)
|
3416
|
-
})]
|
3417
|
-
})
|
3418
|
-
}), jsxs(Modal.Footer, {
|
3419
|
-
dflex: true,
|
3420
|
-
placeContent: "end",
|
3421
|
-
spaceX: "3",
|
3422
|
-
children: [jsx(Button, {
|
3423
|
-
disabled: mutation.isLoading,
|
3424
|
-
onClick: onClose,
|
3425
|
-
variant: "borderless",
|
3426
|
-
me: "2",
|
3427
|
-
children: cancelLabel
|
3428
|
-
}), jsx(Button, {
|
3429
|
-
type: "submit",
|
3430
|
-
disabled: !dirty || mutation.isLoading /* || !isValid*/,
|
3431
|
-
onClick: () => handleSubmit(),
|
3432
|
-
children: saveLabel ? saveLabel : queryId ? "Update" : "Create"
|
3433
|
-
})]
|
3434
|
-
})]
|
3435
|
-
})
|
3436
|
-
}))
|
3437
|
-
}), mutation.isLoading && jsx(ModalLoadingOverlay, {})]
|
3438
|
-
}));
|
3439
|
-
}
|
3440
|
-
|
3441
3290
|
function PageSectionTitle(_a) {
|
3442
3291
|
var {
|
3443
3292
|
children
|
@@ -3678,4 +3527,4 @@ function TableRowPublishPostButton(_a) {
|
|
3678
3527
|
}, props));
|
3679
3528
|
}
|
3680
3529
|
|
3681
|
-
export { AdminLayout, AttachDialog, Breadcrumbs, ButtonBar, ButtonBarButton, ButtonBarDialogButton, DialogButton, FormActionDialog, InvalidateButton, ItemEditDialog, NavigateButton, OrderCell, PageContainer, PageContentEditor, PageMain, PageQueryStateContainer, PageSectionTitle, PageSidebar, PageSidebarSection, PageStateContainer, PageSubSectionTitle, PageTabbedTopBar, PageTabbedTopBarProvider, PageTitle, PageTopBar, PageTopBarToolbar, PublishButton, ScreenRenderer, SectionTitle, StatusBadge, TableContainer, TableCreateButton, TableFilterButton, TableRowActionBar, TableRowActionButton, TableRowActionDialogButton, TableRowDeleteButton, TableRowEditButton, TableRowNavigateButton, TableRowPublishPostButton, TableRowViewButton, TableTopBar, UpdateButton, ViewButton };
|
3530
|
+
export { AdminLayout, AttachDialog, Breadcrumbs, ButtonBar, ButtonBarButton, ButtonBarDialogButton, DialogButton, FormActionDialog, InvalidateButton, ItemDeleteDialog, ItemEditDialog, NavigateButton, OrderCell, PageContainer, PageContentEditor, PageMain, PageQueryStateContainer, PageSectionTitle, PageSidebar, PageSidebarSection, PageStateContainer, PageSubSectionTitle, PageTabbedTopBar, PageTabbedTopBarProvider, PageTitle, PageTopBar, PageTopBarToolbar, PublishButton, ScreenRenderer, SectionTitle, StatusBadge, TableContainer, TableCreateButton, TableFilterButton, TableRowActionBar, TableRowActionButton, TableRowActionDialogButton, TableRowDeleteButton, TableRowEditButton, TableRowNavigateButton, TableRowPublishPostButton, TableRowViewButton, TableTopBar, UpdateButton, ViewButton };
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
@@ -7,21 +7,22 @@ export * from "./lib/buttons/PublishButton";
|
|
7
7
|
export * from "./lib/buttons/UpdateButton";
|
8
8
|
export * from "./lib/buttons/ViewButton";
|
9
9
|
export * from "./lib/cells/OrderCell";
|
10
|
-
export * from "./lib/json/
|
11
|
-
export * from "./lib/json/
|
12
|
-
export * from "./lib/json/
|
13
|
-
export * from "./lib/json/types/TabbedView";
|
10
|
+
export * from "./lib/json/ScreenRenderer";
|
11
|
+
export * from "./lib/json/dialog/ItemEditDialog";
|
12
|
+
export * from "./lib/json/dialog/ItemDeleteDialog";
|
14
13
|
export * from "./lib/json/types/DetailsView";
|
14
|
+
export * from "./lib/json/types/EditItemDialog";
|
15
|
+
export * from "./lib/json/types/MultiQueryWrapper";
|
15
16
|
export * from "./lib/json/types/QueryWrapper";
|
16
17
|
export * from "./lib/json/types/QueryWrapperDialog";
|
17
|
-
export * from "./lib/json/types/
|
18
|
-
export * from "./lib/json/
|
18
|
+
export * from "./lib/json/types/ScreenConfig";
|
19
|
+
export * from "./lib/json/types/TabbedView";
|
20
|
+
export * from "./lib/json/types/TableView";
|
19
21
|
export * from "./lib/layout/AdminLayout";
|
20
22
|
export * from "./lib/layout/ButtonBar";
|
21
23
|
export { MenuConfig } from "./lib/layout/Menu";
|
22
24
|
export * from "./lib/modal/AttachDialog";
|
23
25
|
export * from "./lib/modal/FormActionDialog";
|
24
|
-
export * from "./lib/modal/ItemEditDialog";
|
25
26
|
export * from "./lib/page/PageContainer";
|
26
27
|
export * from "./lib/page/PageContentEditor";
|
27
28
|
export * from "./lib/page/PageMain";
|
@@ -1,33 +0,0 @@
|
|
1
|
-
import { FormRendererConfig } from "@compill/form";
|
2
|
-
import { UseMutationOptions, UseQueryOptions } from "@tanstack/react-query";
|
3
|
-
import { ModalProps } from "@valerya/ui";
|
4
|
-
import { FormikConfig } from "formik";
|
5
|
-
import React from "react";
|
6
|
-
export interface ItemEditDialogProps<TFormData extends {} = any, TResultData extends {} = any> extends Omit<ModalProps, "id" | "children" | "title" | "position"> {
|
7
|
-
itemLabel?: string;
|
8
|
-
queryId?: string;
|
9
|
-
queryKey: string[];
|
10
|
-
initialValues?: any;
|
11
|
-
queryFetchFn: (...args: any[]) => Promise<TResultData>;
|
12
|
-
queryFetchOptions?: UseQueryOptions;
|
13
|
-
querySaveFn: (item: TFormData) => Promise<TResultData>;
|
14
|
-
querySaveOptions?: UseMutationOptions<TResultData, unknown, TFormData>;
|
15
|
-
onSuccess?: (item: TResultData, response: any) => void;
|
16
|
-
onFetchError?: () => void;
|
17
|
-
fetchErrorMsg?: string;
|
18
|
-
onSaveError?: (item: TFormData) => void;
|
19
|
-
saveErrorMsg?: string;
|
20
|
-
fetchToFormData?: (item: TResultData) => TFormData;
|
21
|
-
formToQueryData?: (TFormData: any) => Partial<TResultData>;
|
22
|
-
invalidateQueriesOnSuccess?: boolean;
|
23
|
-
invalidateQueryKey?: string[];
|
24
|
-
retryText?: string;
|
25
|
-
cancelLabel?: string;
|
26
|
-
saveLabel?: string;
|
27
|
-
title?: ((item?: TResultData) => string);
|
28
|
-
formikProps: Omit<FormikConfig<any>, "initialValues" | "onSubmit">;
|
29
|
-
form: React.ReactNode | FormRendererConfig | ((item: TResultData) => FormRendererConfig);
|
30
|
-
show: boolean;
|
31
|
-
onClose: () => void;
|
32
|
-
}
|
33
|
-
export declare function ItemEditDialog<TFormData extends {}, TResultData extends {}>({ initialValues, itemLabel, queryId, queryKey, queryFetchFn, queryFetchOptions, querySaveFn, querySaveOptions, onSuccess, onFetchError, fetchErrorMsg, onSaveError, saveErrorMsg, fetchToFormData, formToQueryData, invalidateQueriesOnSuccess, invalidateQueryKey, retryText, cancelLabel, saveLabel, size, title, form, show, onClose, formikProps, ...props }: ItemEditDialogProps<TFormData, TResultData>): JSX.Element;
|