@acvl/frontend-components 0.0.35 → 0.0.37

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/cjs/index.js CHANGED
@@ -69,8 +69,8 @@ var iconsMaterial = require('@mui/icons-material');
69
69
  var merge$1 = require('lodash/merge');
70
70
  var UploadFileIcon = require('@mui/icons-material/UploadFile');
71
71
  var ClearIcon$1 = require('@mui/icons-material/Clear');
72
- var SaveIcon = require('@mui/icons-material/Save');
73
72
  var AddIcon = require('@mui/icons-material/Add');
73
+ var SaveIcon = require('@mui/icons-material/Save');
74
74
  var KeyboardArrowDownIcon = require('@mui/icons-material/KeyboardArrowDown');
75
75
  var LinearProgress = require('@mui/material/LinearProgress');
76
76
  var AttachFileIcon = require('@mui/icons-material/AttachFile');
@@ -98,6 +98,7 @@ var DrawIcon = require('@mui/icons-material/Draw');
98
98
  var CloseIcon = require('@mui/icons-material/Close');
99
99
  var ErrorOutlineIcon = require('@mui/icons-material/ErrorOutline');
100
100
  var query$1 = require('@reduxjs/toolkit/query');
101
+ var OpenInNewIcon = require('@mui/icons-material/OpenInNew');
101
102
  var TabList = require('@mui/lab/TabList');
102
103
  var TabPanel = require('@mui/lab/TabPanel');
103
104
  var TabContext = require('@mui/lab/TabContext');
@@ -25514,8 +25515,8 @@ const useHasPermission = (path) => {
25514
25515
  };
25515
25516
 
25516
25517
  const APIContext = React.createContext(null);
25517
- const APIProvider = ({ children, hooks }) => {
25518
- return (jsxRuntime.jsx(APIContext.Provider, { value: hooks, children: children }));
25518
+ const APIProvider = ({ children, hooks, }) => {
25519
+ return jsxRuntime.jsx(APIContext.Provider, { value: hooks, children: children });
25519
25520
  };
25520
25521
 
25521
25522
  const useAPI = () => {
@@ -26538,7 +26539,19 @@ const VisuallyHiddenInput = material.styled("input")({
26538
26539
  });
26539
26540
  const ControlledFileField = (props) => {
26540
26541
  return (jsxRuntime.jsx(reactHookForm.Controller, { control: props.control, name: props.name, render: ({ field: { value, onChange, onBlur, ref }, fieldState: { error } }) => {
26541
- return (jsxRuntime.jsxs(material.FormGroup, { sx: { width: 1 }, color: "secondary", children: [value ? (jsxRuntime.jsxs(material.Stack, { direction: "row", spacing: 1, width: 1, alignItems: "center", children: [jsxRuntime.jsx(material.Typography, { children: value.name }), jsxRuntime.jsx(material.IconButton, { onClick: () => onChange(null), children: jsxRuntime.jsx(ClearIcon$1, { color: "error" }) })] })) : (jsxRuntime.jsxs(material.Button, { component: "label", variant: "contained", startIcon: jsxRuntime.jsx(UploadFileIcon, {}), sx: { maxWidth: 200 }, ...props.extraProps?.slotProps?.button, children: ["Cargar", jsxRuntime.jsx(VisuallyHiddenInput, { type: "file", accept: "image/*", ref: ref, onBlur: onBlur, onChange: (e) => onChange(e.target.files && e.target.files[0]), ...props.extraProps?.slotProps?.input })] })), jsxRuntime.jsx(material.FormHelperText, { error: !!error, children: error ? error.message : " " })] }));
26542
+ if (props.extraProps?.multiple) {
26543
+ const files = value ?? [];
26544
+ const handleAdd = (e) => {
26545
+ const incoming = e.target.files ? Array.from(e.target.files) : [];
26546
+ onChange([...files, ...incoming]);
26547
+ e.target.value = "";
26548
+ };
26549
+ const handleRemove = (index) => {
26550
+ onChange(files.filter((_, i) => i !== index));
26551
+ };
26552
+ return (jsxRuntime.jsxs(material.FormGroup, { sx: { width: 1 }, children: [jsxRuntime.jsxs(material.Stack, { spacing: 1, width: 1, children: [files.map((file, index) => (jsxRuntime.jsxs(material.Stack, { direction: "row", spacing: 1, alignItems: "center", sx: { minWidth: 0 }, children: [jsxRuntime.jsx(material.Typography, { noWrap: true, sx: { flex: 1 }, children: file.name }), jsxRuntime.jsx(material.IconButton, { onClick: () => handleRemove(index), children: jsxRuntime.jsx(ClearIcon$1, { color: "error" }) })] }, index))), jsxRuntime.jsxs(material.Button, { component: "label", variant: "contained", startIcon: jsxRuntime.jsx(UploadFileIcon, {}), sx: { maxWidth: 200 }, ...props.extraProps?.slotProps?.button, children: ["Cargar", jsxRuntime.jsx(VisuallyHiddenInput, { type: "file", multiple: true, accept: "image/*", ref: ref, onBlur: onBlur, onChange: handleAdd, ...props.extraProps?.slotProps?.input })] })] }), jsxRuntime.jsx(material.FormHelperText, { error: !!error, children: error ? error.message : " " })] }));
26553
+ }
26554
+ return (jsxRuntime.jsxs(material.FormGroup, { sx: { width: 1 }, color: "secondary", children: [value ? (jsxRuntime.jsxs(material.Stack, { direction: "row", spacing: 1, width: 1, alignItems: "center", sx: { minWidth: 0 }, children: [jsxRuntime.jsx(material.Typography, { noWrap: true, sx: { flex: 1 }, children: value.name }), jsxRuntime.jsx(material.IconButton, { onClick: () => onChange(null), children: jsxRuntime.jsx(ClearIcon$1, { color: "error" }) })] })) : (jsxRuntime.jsxs(material.Button, { component: "label", variant: "contained", startIcon: jsxRuntime.jsx(UploadFileIcon, {}), sx: { maxWidth: 200 }, ...props.extraProps?.slotProps?.button, children: ["Cargar", jsxRuntime.jsx(VisuallyHiddenInput, { type: "file", accept: "image/*", ref: ref, onBlur: onBlur, onChange: (e) => onChange(e.target.files && e.target.files[0]), ...props.extraProps?.slotProps?.input })] })), jsxRuntime.jsx(material.FormHelperText, { error: !!error, children: error ? error.message : " " })] }));
26542
26555
  } }));
26543
26556
  };
26544
26557
  ControlledFileField.displayName = "ControlledFileField";
@@ -26552,6 +26565,161 @@ const ControlledSlider = (props) => {
26552
26565
  } }));
26553
26566
  };
26554
26567
 
26568
+ const CREATE_OPTION = { value: "__create__", label: "" };
26569
+ const CrudDropdown = (props) => {
26570
+ const { name, label, control, fieldProps, extraProps: { queryArgs, crudExtraArgs = {}, labelField = "nombre", disableHT }, } = props;
26571
+ const [inputValue, setInputValue] = React.useState("");
26572
+ const [options, setOptions] = React.useState([]);
26573
+ const [open, setOpen] = React.useState(false);
26574
+ const [createOpen, setCreateOpen] = React.useState(false);
26575
+ const [editOpen, setEditOpen] = React.useState(false);
26576
+ const [deleteOpen, setDeleteOpen] = React.useState(false);
26577
+ const [activeOption, setActiveOption] = React.useState(null);
26578
+ const [dialogInput, setDialogInput] = React.useState("");
26579
+ const formValueRef = React.useRef(null);
26580
+ const formOnChangeRef = React.useRef(() => { });
26581
+ const api = useAPI();
26582
+ const [getOpciones, { isLoading, isFetching, isError }] = api.useLazyGetComoOpcionesQuery();
26583
+ const [genericCrud, { isLoading: isMutating }] = api.useGenericCrudMutation();
26584
+ const notifications = core.useNotifications();
26585
+ const args = React.useMemo(() => ({
26586
+ ...queryArgs,
26587
+ filters: { ...queryArgs.filters, nombre__icontains: inputValue },
26588
+ }), [inputValue, queryArgs]);
26589
+ const fetchOptions = React.useCallback(lodash.debounce((fetchArgs, cb) => {
26590
+ setOptions([]);
26591
+ getOpciones(fetchArgs)
26592
+ .unwrap()
26593
+ .then(cb)
26594
+ .catch(() => { });
26595
+ }, 500), []);
26596
+ const refreshOptions = () => {
26597
+ getOpciones(args, false)
26598
+ .unwrap()
26599
+ .then((fresh) => setOptions(fresh))
26600
+ .catch(() => { });
26601
+ };
26602
+ React.useEffect(() => {
26603
+ if (open)
26604
+ fetchOptions(args, setOptions);
26605
+ }, [args, fetchOptions, open]);
26606
+ const handleCreate = () => {
26607
+ genericCrud({
26608
+ endpoint: props.extraProps.queryArgs.endpoint,
26609
+ method: "POST",
26610
+ body: { [labelField]: dialogInput, ...crudExtraArgs },
26611
+ })
26612
+ .unwrap()
26613
+ .then(() => {
26614
+ notifications.show("Opción creada.", { severity: "success" });
26615
+ setCreateOpen(false);
26616
+ setDialogInput("");
26617
+ refreshOptions();
26618
+ })
26619
+ .catch(() => notifications.show("Error al crear.", { severity: "error" }));
26620
+ };
26621
+ const handleEdit = () => {
26622
+ if (!activeOption)
26623
+ return;
26624
+ genericCrud({
26625
+ endpoint: props.extraProps.queryArgs.endpoint,
26626
+ method: "PATCH",
26627
+ id: activeOption.value,
26628
+ body: { [labelField]: dialogInput, ...crudExtraArgs },
26629
+ })
26630
+ .unwrap()
26631
+ .then(() => {
26632
+ if (formValueRef.current?.value === activeOption.value) {
26633
+ formOnChangeRef.current({ value: activeOption.value, label: dialogInput });
26634
+ }
26635
+ notifications.show("Opción actualizada.", { severity: "success" });
26636
+ setEditOpen(false);
26637
+ setDialogInput("");
26638
+ setActiveOption(null);
26639
+ refreshOptions();
26640
+ })
26641
+ .catch(() => notifications.show("Error al actualizar.", { severity: "error" }));
26642
+ };
26643
+ const handleDelete = () => {
26644
+ if (!activeOption)
26645
+ return;
26646
+ genericCrud({
26647
+ endpoint: props.extraProps.queryArgs.endpoint,
26648
+ method: "DELETE",
26649
+ id: activeOption.value,
26650
+ })
26651
+ .unwrap()
26652
+ .then(() => {
26653
+ if (formValueRef.current?.value === activeOption.value) {
26654
+ formOnChangeRef.current(null);
26655
+ }
26656
+ notifications.show("Opción eliminada.", { severity: "success" });
26657
+ setDeleteOpen(false);
26658
+ setActiveOption(null);
26659
+ refreshOptions();
26660
+ })
26661
+ .catch(() => notifications.show("Error al eliminar.", { severity: "error" }));
26662
+ };
26663
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(reactHookForm.Controller, { name: name, control: control, render: ({ field: { value, onChange }, fieldState: { error } }) => {
26664
+ formValueRef.current = value;
26665
+ formOnChangeRef.current = onChange;
26666
+ const handleChange = (_event, newValue) => {
26667
+ if (newValue?.value === "__create__") {
26668
+ setDialogInput("");
26669
+ setCreateOpen(true);
26670
+ return;
26671
+ }
26672
+ onChange(newValue);
26673
+ };
26674
+ return (jsxRuntime.jsx(material.Autocomplete, { id: name, open: open, onOpen: () => setOpen(true), onClose: () => setOpen(false), options: options, loading: isLoading || isFetching, value: value, onChange: handleChange, inputValue: inputValue, onInputChange: (_event, newInputValue) => setInputValue(newInputValue), isOptionEqualToValue: (option, val) => option.value === val.value, filterOptions: (x) => [CREATE_OPTION, ...x], getOptionLabel: (option) => option.value === "__create__" ? "" : option.label || "", fullWidth: true, size: "small", disabled: isError, renderOption: (optionProps, option) => {
26675
+ const { key, ...rest } = optionProps;
26676
+ if (option.value === "__create__") {
26677
+ return (jsxRuntime.jsxs(material.Box, { component: "li", ...rest, onClick: () => {
26678
+ setDialogInput("");
26679
+ setCreateOpen(true);
26680
+ }, sx: {
26681
+ justifyContent: "center !important",
26682
+ color: "primary.main",
26683
+ borderBottom: "1px solid",
26684
+ borderColor: "divider",
26685
+ py: "6px !important",
26686
+ gap: 0.5,
26687
+ }, children: [jsxRuntime.jsx(AddIcon, { fontSize: "small" }), jsxRuntime.jsx(material.Typography, { variant: "body2", children: "Agregar nuevo" })] }, key));
26688
+ }
26689
+ return (jsxRuntime.jsxs(material.Box, { component: "li", ...rest, sx: {
26690
+ display: "flex",
26691
+ alignItems: "center",
26692
+ pr: "4px !important",
26693
+ }, children: [jsxRuntime.jsx(material.Box, { sx: {
26694
+ flex: 1,
26695
+ overflow: "hidden",
26696
+ textOverflow: "ellipsis",
26697
+ }, children: option.label }), jsxRuntime.jsx(material.IconButton, { size: "small", tabIndex: -1, onMouseDown: (e) => {
26698
+ e.stopPropagation();
26699
+ e.preventDefault();
26700
+ }, onClick: (e) => {
26701
+ e.stopPropagation();
26702
+ setActiveOption(option);
26703
+ setDialogInput(option.label);
26704
+ setEditOpen(true);
26705
+ }, children: jsxRuntime.jsx(EditIcon, { fontSize: "inherit" }) }), jsxRuntime.jsx(material.IconButton, { size: "small", tabIndex: -1, onMouseDown: (e) => {
26706
+ e.stopPropagation();
26707
+ e.preventDefault();
26708
+ }, onClick: (e) => {
26709
+ e.stopPropagation();
26710
+ setActiveOption(option);
26711
+ setDeleteOpen(true);
26712
+ }, children: jsxRuntime.jsx(DeleteIcon, { fontSize: "inherit" }) })] }, key));
26713
+ }, renderInput: (params) => (jsxRuntime.jsx(material.TextField, { ...params, label: label, error: !!error, helperText: error ? error.message : disableHT ? "" : " ", slotProps: {
26714
+ input: {
26715
+ ...params.InputProps,
26716
+ endAdornment: (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [isLoading || isFetching ? (jsxRuntime.jsx(material.CircularProgress, { color: "inherit", size: 20 })) : null, params.InputProps.endAdornment] })),
26717
+ },
26718
+ } })), ...fieldProps }));
26719
+ } }), jsxRuntime.jsxs(material.Dialog, { open: createOpen, onClose: () => setCreateOpen(false), maxWidth: "xs", fullWidth: true, children: [jsxRuntime.jsx(material.DialogTitle, { children: "Agregar opci\u00F3n" }), jsxRuntime.jsx(material.DialogContent, { children: jsxRuntime.jsx(material.TextField, { autoFocus: true, fullWidth: true, size: "small", label: label, value: dialogInput, onChange: (e) => setDialogInput(e.target.value), onKeyDown: (e) => e.key === "Enter" && !!dialogInput && handleCreate(), sx: { mt: 1 } }) }), jsxRuntime.jsxs(material.DialogActions, { children: [jsxRuntime.jsx(material.Button, { color: "error", onClick: () => setCreateOpen(false), children: "Cancelar" }), jsxRuntime.jsx(material.Button, { color: "secondary", disabled: !dialogInput, loading: isMutating, onClick: handleCreate, children: "Guardar" })] })] }), jsxRuntime.jsxs(material.Dialog, { open: editOpen, onClose: () => setEditOpen(false), maxWidth: "xs", fullWidth: true, children: [jsxRuntime.jsx(material.DialogTitle, { children: "Editar opci\u00F3n" }), jsxRuntime.jsx(material.DialogContent, { children: jsxRuntime.jsx(material.TextField, { autoFocus: true, fullWidth: true, size: "small", label: label, value: dialogInput, onChange: (e) => setDialogInput(e.target.value), onKeyDown: (e) => e.key === "Enter" && !!dialogInput && handleEdit(), sx: { mt: 1 } }) }), jsxRuntime.jsxs(material.DialogActions, { children: [jsxRuntime.jsx(material.Button, { color: "error", onClick: () => setEditOpen(false), children: "Cancelar" }), jsxRuntime.jsx(material.Button, { color: "secondary", disabled: !dialogInput, loading: isMutating, onClick: handleEdit, children: "Guardar" })] })] }), jsxRuntime.jsxs(material.Dialog, { open: deleteOpen, onClose: () => setDeleteOpen(false), maxWidth: "xs", fullWidth: true, children: [jsxRuntime.jsx(material.DialogTitle, { children: "Eliminar opci\u00F3n" }), jsxRuntime.jsx(material.DialogContent, { children: jsxRuntime.jsxs(material.Typography, { children: ["\u00BFEliminar ", jsxRuntime.jsx("strong", { children: activeOption?.label }), "?"] }) }), jsxRuntime.jsxs(material.DialogActions, { children: [jsxRuntime.jsx(material.Button, { onClick: () => setDeleteOpen(false), children: "Cancelar" }), jsxRuntime.jsx(material.Button, { color: "error", loading: isMutating, onClick: handleDelete, children: "Eliminar" })] })] })] }));
26720
+ };
26721
+ CrudDropdown.displayName = "CrudDropdown";
26722
+
26555
26723
  const DeleteConfirmationDialog = (props) => {
26556
26724
  const notifications = core.useNotifications();
26557
26725
  const { pathname } = reactRouterDom.useLocation();
@@ -27675,7 +27843,12 @@ const CreateGridWrapper = (props) => {
27675
27843
  }), jsxRuntime.jsxs(MenuItem, { onClick: () => {
27676
27844
  navigate(props.navigation ? `${props.navigation}crear` : `crear`);
27677
27845
  handleClose();
27678
- }, disableRipple: true, children: [jsxRuntime.jsx(material.ListItemIcon, { children: jsxRuntime.jsx(DrawIcon, {}) }), "Manual"] })] }), props.csv_upload?.enable && (jsxRuntime.jsx(CSVUpload, { open: csv.open, drawerToggle: handleToggleClose, data: csv.data })), props.renderFunction({ dataGridProps: createGridProps })] }));
27846
+ }, disableRipple: true, children: [jsxRuntime.jsx(material.ListItemIcon, { children: jsxRuntime.jsx(DrawIcon, {}) }), "Manual"] }), props.extraOptions?.map((option, index) => {
27847
+ return (jsxRuntime.jsxs(MenuItem, { onClick: () => {
27848
+ option.onClick();
27849
+ handleClose();
27850
+ }, disableRipple: true, children: [jsxRuntime.jsx(material.ListItemIcon, { children: option.icon }), option.title] }, index));
27851
+ })] }), props.csv_upload?.enable && (jsxRuntime.jsx(CSVUpload, { open: csv.open, drawerToggle: handleToggleClose, data: csv.data })), props.renderFunction({ dataGridProps: createGridProps })] }));
27679
27852
  };
27680
27853
 
27681
27854
  const Base = (props) => {
@@ -28019,6 +28192,7 @@ const LinkField = ({ url, value, text }) => {
28019
28192
  return jsxRuntime.jsx(material.Link, { href: `${url}/${value}`, children: text });
28020
28193
  };
28021
28194
  const DetailField = (props) => {
28195
+ const [anchor, setAnchor] = React.useState(null);
28022
28196
  const hasLinkToViewPermission = useHasPermission(`${props.navigation?.permission}.view`);
28023
28197
  const value = React.useCallback(() => {
28024
28198
  const { fieldData, type, extraProps, detail_name } = props;
@@ -28038,7 +28212,7 @@ const DetailField = (props) => {
28038
28212
  ? dayjs(fieldData).format("YYYY-MM-DD HH:mm")
28039
28213
  : dayjs(fieldData).format("YYYY-MM-DD");
28040
28214
  case "ControlledFileField":
28041
- return fieldData ? "Archivo" : "N/A";
28215
+ return fieldData ? "Archivo(s)" : "N/A";
28042
28216
  default:
28043
28217
  if (!fieldData)
28044
28218
  return "N/A";
@@ -28056,7 +28230,13 @@ const DetailField = (props) => {
28056
28230
  return (jsxRuntime.jsx(LinkField, { url: props.navigation.url, value: lodash.get(props.fieldData, "value"), text: content }));
28057
28231
  }
28058
28232
  else if (props.type.displayName == "ControlledFileField" && content !== "N/A") {
28059
- return (jsxRuntime.jsx(material.Link, { href: props.fieldData, target: "_blank", rel: "noopener noreferrer", children: content }));
28233
+ const archivos = Array.isArray(props.fieldData)
28234
+ ? props.fieldData.filter(Boolean)
28235
+ : [props.fieldData];
28236
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(material.Badge, { badgeContent: archivos.length, color: "primary", sx: { "& .MuiBadge-badge": { fontSize: 10, minWidth: 16, height: 16 } }, children: jsxRuntime.jsx(material.Button, { size: "small", onClick: (e) => {
28237
+ e.stopPropagation();
28238
+ setAnchor(e.currentTarget);
28239
+ }, children: content }) }), jsxRuntime.jsx(material.Popover, { open: Boolean(anchor), anchorEl: anchor, onClose: () => setAnchor(null), anchorOrigin: { vertical: "bottom", horizontal: "center" }, transformOrigin: { vertical: "top", horizontal: "center" }, onClick: (e) => e.stopPropagation(), children: jsxRuntime.jsx(material.List, { dense: true, disablePadding: true, sx: { minWidth: 140 }, children: archivos.map((archivo, i) => (jsxRuntime.jsxs(material.ListItemButton, { component: "a", href: archivo.imagen, target: "_blank", rel: "noopener noreferrer", onClick: (e) => e.stopPropagation(), children: [jsxRuntime.jsx(material.ListItemText, { primary: `Archivo ${i + 1}` }), jsxRuntime.jsx(OpenInNewIcon, { fontSize: "small", sx: { ml: 1, opacity: 0.6 } })] }, i))) }) })] }));
28060
28240
  }
28061
28241
  else {
28062
28242
  if (Array.isArray(props.fieldData)) {
@@ -28104,6 +28284,8 @@ const Field = (props) => {
28104
28284
  const formData = props.form.watch();
28105
28285
  const show = React.useMemo(() => {
28106
28286
  if (props.dependantOn) {
28287
+ if (props.dependantOn.showOnDetail && props.pageType === "detail")
28288
+ return true;
28107
28289
  return props.dependantOn.method(lodash.get(props.data || formData, props.dependantOn.fieldName), props.dependantOn.value);
28108
28290
  }
28109
28291
  return true;
@@ -28132,6 +28314,7 @@ const FieldArrayField = (props) => {
28132
28314
  keyName: "_id",
28133
28315
  });
28134
28316
  const errors = props.form.formState.errors;
28317
+ const errorMessage = lodash.get(props.form.formState.errors, props.name + ".message");
28135
28318
  const getIndex = React.useCallback((id) => lodash.findIndex(fields, function (field) {
28136
28319
  return field._id == id;
28137
28320
  }), [fields]);
@@ -28212,31 +28395,27 @@ const FieldArrayField = (props) => {
28212
28395
  fieldProps: field.fieldProps,
28213
28396
  extraProps: field.extraProps,
28214
28397
  }) })] }, `grid-${index}`));
28215
- }) }) }), jsxRuntime.jsxs(material.Grid, { rowSpacing: 1, container: true, size: "grow", direction: "column", ...props.gridProps, children: [jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(material.Typography, { variant: "body1", fontWeight: "bold", children: props.label }) }), jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(xDataGrid.DataGrid, { ...dataGridProps }) })] })] }));
28398
+ }) }) }), jsxRuntime.jsxs(material.Grid, { rowSpacing: 1, container: true, size: "grow", direction: "column", ...props.gridProps, children: [jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(material.Typography, { variant: "body1", fontWeight: "bold", children: props.label }) }), errorMessage && (jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(material.Typography, { variant: "body1", color: "error", children: errorMessage }) })), jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(xDataGrid.DataGrid, { ...dataGridProps }) })] })] }));
28216
28399
  };
28217
28400
 
28218
28401
  const Section = (props) => {
28219
28402
  const [expanded, setExpanded] = React.useState(true);
28220
28403
  const handleExpandChange = () => {
28221
- setExpanded(prevState => !prevState);
28404
+ setExpanded((prevState) => !prevState);
28222
28405
  };
28223
28406
  const renderField = (field, index) => {
28224
28407
  if (props.first && index == 0)
28225
- lodash.merge(lodash.get(field, 'fieldProps', {}), { autoFocus: true });
28408
+ lodash.merge(lodash.get(field, "fieldProps", {}), { autoFocus: true });
28226
28409
  return (jsxRuntime.jsx(Field, { fieldData: props.data && lodash.get(props.data, field.name), ...field, readOnly:
28227
28410
  // props.validation?.readOnlyFields.includes(field.name) ||
28228
- (props.edit?.readOnlyFields?.names.includes(field.name) && props.edit.readOnlyFields.validator.method(lodash.get(props.data, props.edit.readOnlyFields.validator.field), props.edit.readOnlyFields.validator.value)), form: props.form, pageType: props.pageType, data: props.data }, `F-${index}`));
28411
+ props.edit?.readOnlyFields?.names.includes(field.name) &&
28412
+ props.edit.readOnlyFields.validator.method(lodash.get(props.data, props.edit.readOnlyFields.validator.field), props.edit.readOnlyFields.validator.value), form: props.form, pageType: props.pageType, data: props.data }, `F-${index}`));
28229
28413
  };
28230
28414
  const renderArrayField = (field, index) => (jsxRuntime.jsx(FieldArrayField, { ...field, form: props.form, pageType: props.pageType }, `FA-${index}`));
28231
- return (jsxRuntime.jsxs(material.Grid, { size: 12, container: true, spacing: 2, bgcolor: props.bgColor, p: 2, borderRadius: 1, children: [(props.title || props.description) &&
28232
- jsxRuntime.jsxs(material.Grid, { size: 12, container: true, spacing: 0, children: [props.title &&
28233
- jsxRuntime.jsxs(material.Grid, { size: 12, container: true, onClick: handleExpandChange, sx: {
28234
- cursor: 'pointer'
28235
- }, children: [jsxRuntime.jsx(material.Grid, { children: expanded ? jsxRuntime.jsx(ExpandLessIcon, { fontSize: 'small' }) : jsxRuntime.jsx(ExpandMoreIcon, { fontSize: 'small' }) }), jsxRuntime.jsx(material.Grid, { children: jsxRuntime.jsx(material.Typography, { variant: 'h5', children: props.title }) })] }), props.description &&
28236
- jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(material.Typography, { variant: 'caption', color: 'secondary.main', children: props.description }) })] }), expanded &&
28237
- jsxRuntime.jsxs(material.Grid, { size: 12, container: true, direction: 'row', children: [props.fields &&
28238
- props.fields.map((field, index) => renderField(field, index)), props.arrayFields &&
28239
- props.arrayFields.map((arrayField, index) => renderArrayField(arrayField, index)), props.content && props.content(props.data)] })] }));
28415
+ return (jsxRuntime.jsxs(material.Grid, { size: 12, container: true, spacing: 2, bgcolor: props.bgColor, p: 2, borderRadius: 1, children: [(props.title || props.description) && (jsxRuntime.jsxs(material.Grid, { size: 12, container: true, spacing: 0, children: [props.title && (jsxRuntime.jsxs(material.Grid, { size: 12, container: true, onClick: handleExpandChange, sx: {
28416
+ cursor: "pointer",
28417
+ }, children: [jsxRuntime.jsx(material.Grid, { children: expanded ? (jsxRuntime.jsx(ExpandLessIcon, { fontSize: "small" })) : (jsxRuntime.jsx(ExpandMoreIcon, { fontSize: "small" })) }), jsxRuntime.jsx(material.Grid, { children: jsxRuntime.jsx(material.Typography, { variant: "h5", children: props.title }) })] })), props.description && (jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(material.Typography, { variant: "caption", color: "secondary.main", children: props.description }) }))] })), expanded && (jsxRuntime.jsxs(material.Grid, { size: 12, container: true, direction: "row", children: [props.fields && props.fields.map((field, index) => renderField(field, index)), props.arrayFields &&
28418
+ props.arrayFields.map((arrayField, index) => renderArrayField(arrayField, index)), props.content && props.content(props.data)] }))] }));
28240
28419
  };
28241
28420
 
28242
28421
  // ==============================|| VALIDATION ||============================== //
@@ -28445,7 +28624,7 @@ function DetailPage(props) {
28445
28624
  }
28446
28625
  }
28447
28626
  }, [data, dispatch, form, props.slots?.title]);
28448
- const [mutation, { isLoading: mutationIsLoading, isSuccess, data: mutationResponse },] = props.api.mutate.mutation();
28627
+ const [mutation, { isLoading: mutationIsLoading, isSuccess, data: mutationResponse }] = props.api.mutate.mutation();
28449
28628
  const handleCancel = () => {
28450
28629
  form.reset();
28451
28630
  navigate(-1);
@@ -28455,8 +28634,7 @@ function DetailPage(props) {
28455
28634
  // ==============================|| VALIDATION ||============================== //
28456
28635
  useValidateFieldData(props, form);
28457
28636
  // ==============================|| QUICK RETURN ||============================== //
28458
- if ((!canEdit && props.pageType == "edit") ||
28459
- (fetchError && fetchError.originalStatus == 403))
28637
+ if ((!canEdit && props.pageType == "edit") || (fetchError && fetchError.originalStatus == 403))
28460
28638
  return jsxRuntime.jsx(NotAllowed, {});
28461
28639
  if (fetchError && fetchError.originalStatus == 404)
28462
28640
  return jsxRuntime.jsx(NotFound, {});
@@ -28470,9 +28648,7 @@ function DetailPage(props) {
28470
28648
  props: props.slotProps?.parser,
28471
28649
  };
28472
28650
  const dataToSend = formParser(params);
28473
- mutation(props.edit.useFormData
28474
- ? dataToSend
28475
- : { ...dataToSend, ...props.api.mutate.args })
28651
+ mutation(props.edit.useFormData ? dataToSend : { ...dataToSend, ...props.api.mutate.args })
28476
28652
  .unwrap()
28477
28653
  .then(() => {
28478
28654
  if (!props.slotProps?.button?.save?.disableNavBack)
@@ -28498,17 +28674,26 @@ function DetailPage(props) {
28498
28674
  };
28499
28675
  const onError = (errors) => console.log("Validation Errors:", errors);
28500
28676
  // ==============================|| RENDER SECTIONS ||============================== //
28677
+ const validateDisplay = (field, method, value) => {
28678
+ const validateAgainst = form.watch(field)?.toString();
28679
+ return method(validateAgainst, value);
28680
+ };
28501
28681
  const renderContent = () => {
28502
28682
  let displayed_sections = -1;
28503
28683
  return (jsxRuntime.jsxs(material.Grid, { size: 12, container: true, direction: "column", position: "relative", pb: 2, children: [props.pageType == "detail" && data?.has_history && (jsxRuntime.jsx(HistorialDrawer, { ...props.slotProps?.historial })), props.sections.map((section, index) => {
28504
28684
  if (!section.display)
28505
28685
  return null;
28506
28686
  if (typeof section.display == "object") {
28507
- const validateAgainst = form
28508
- .watch(section.display.field)
28509
- ?.toString();
28510
- if (!section.display.method(validateAgainst, section.display.value))
28511
- return null;
28687
+ if (Array.isArray(section.display)) {
28688
+ if (!section.display
28689
+ .map((item) => validateDisplay(item.field, item.method, item.value))
28690
+ .every((item) => item == true))
28691
+ return null;
28692
+ }
28693
+ else {
28694
+ if (!validateDisplay(section.display.field, section.display.method, section.display.value))
28695
+ return null;
28696
+ }
28512
28697
  }
28513
28698
  displayed_sections += 1;
28514
28699
  return (jsxRuntime.jsx(Section, { data: data, form: form, bgColor: displayed_sections % 2 == 1 ? "white" : "#F7F7F7", pageType: props.pageType, ...section, first: displayed_sections == 0 }, index));
@@ -28518,8 +28703,7 @@ function DetailPage(props) {
28518
28703
  if (props.api.mutate.postAction &&
28519
28704
  isSuccess &&
28520
28705
  "post_action" in mutationResponse &&
28521
- mutationResponse["post_action"]["type"] ===
28522
- props.api.mutate.postAction.type) {
28706
+ mutationResponse["post_action"]["type"] === props.api.mutate.postAction.type) {
28523
28707
  switch (props.api.mutate.postAction.after) {
28524
28708
  // case 'create':
28525
28709
  // if (props.pageType === 'create') return addPropsToNode(props.api.mutate.postAction.node, mutationResponse);
@@ -28884,6 +29068,7 @@ exports.ControlledToggleButtons = ControlledToggleButtons;
28884
29068
  exports.CoverPage = CoverPage;
28885
29069
  exports.CreateButtonBase = CreateButtonBase;
28886
29070
  exports.CreateButtonWithMenuOptions = CreateButtonWithMenuOptions;
29071
+ exports.CrudDropdown = CrudDropdown;
28887
29072
  exports.DeleteButton = DeleteButton;
28888
29073
  exports.DeleteConfirmationDialog = DeleteConfirmationDialog;
28889
29074
  exports.DetailPage = DetailPage;