@acvl/frontend-components 0.0.33 → 0.0.35

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
@@ -25693,14 +25693,14 @@ const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, dat
25693
25693
  setValue(formType, response, key, object);
25694
25694
  break;
25695
25695
  case "object":
25696
- if (object === null || isEmpty(object)) {
25696
+ if (object instanceof File) {
25697
+ setValue(formType, response, key, object);
25698
+ }
25699
+ else if (object === null || isEmpty(object)) {
25697
25700
  if (key.includes("after") || key.includes("before"))
25698
25701
  setValue(formType, response, key, "");
25699
25702
  else
25700
- setValue(formType, response, key, object);
25701
- }
25702
- else if (object instanceof File) {
25703
- setValue(formType, response, key, object);
25703
+ setValue(formType, response, key, formType == "json" ? object : "");
25704
25704
  }
25705
25705
  else if (dayjs.isDayjs(object)) {
25706
25706
  setValue(formType, response, key, object.format(get(props, `${key}.format`, "YYYY-MM-DD")));
@@ -25798,9 +25798,27 @@ const formParser = ({ type, submitData, data, useLabel, props }) => {
25798
25798
  };
25799
25799
  // ==============================|| ERRORS ||============================== //
25800
25800
  const setErrors = (form, error) => {
25801
+ const iterateDeep = (obj) => {
25802
+ if (Array.isArray(obj.reason)) {
25803
+ if (obj.reason.every((item) => typeof item === "object" && item !== null && !Array.isArray(item))) {
25804
+ obj.reason.forEach((obj2, index) => {
25805
+ Object.entries(obj2).forEach(([key3, val3]) => {
25806
+ form.setError(`${obj.name}.${index}.${key3}`, { message: val3.join(", ") });
25807
+ });
25808
+ });
25809
+ }
25810
+ else {
25811
+ form.setError(obj.name, { message: obj.reason.join(", ") });
25812
+ }
25813
+ }
25814
+ else {
25815
+ form.setError(obj.name, { message: obj.reason });
25816
+ }
25817
+ };
25801
25818
  if ("invalid_params" in error.data) {
25802
25819
  Object.values(error.data.invalid_params).forEach((entry) => {
25803
- form.setError(entry.name, { message: entry.reason.join(", ") });
25820
+ iterateDeep(entry);
25821
+ // form.setError(entry.name, { message: entry.reason.join(", ") });
25804
25822
  });
25805
25823
  }
25806
25824
  };
@@ -28104,43 +28122,48 @@ const Field = (props) => {
28104
28122
  };
28105
28123
 
28106
28124
  const EditToolbar = (props) => {
28107
- return (jsxRuntime.jsx(xDataGrid.Toolbar, { children: props.pageType != "detail" && (jsxRuntime.jsx(Tooltip, { title: "Crear", children: jsxRuntime.jsx(xDataGrid.ToolbarButton, { onClick: props.handleCreate, children: jsxRuntime.jsx(AddIcon, { fontSize: "small" }) }) })) }));
28125
+ return (jsxRuntime.jsx(xDataGrid.Toolbar, { children: props.pageType != "detail" && (jsxRuntime.jsx(Tooltip, { title: "Crear", children: jsxRuntime.jsx(xDataGrid.ToolbarButton, { onClick: props.handleClick, children: jsxRuntime.jsx(AddIcon, { fontSize: "small" }) }) })) }));
28108
28126
  };
28109
28127
  const FieldArrayField = (props) => {
28110
28128
  const detail = React.useMemo(() => props.pageType === "detail", [props.pageType]);
28111
- const { fields, append, update, remove } = reactHookForm.useFieldArray({
28112
- control: props.form.control,
28129
+ const { fields, append, remove, update } = reactHookForm.useFieldArray({
28130
+ control: props.form?.control,
28113
28131
  name: props.name,
28114
28132
  keyName: "_id",
28115
28133
  });
28116
- const [rowModesModel, setRowModesModel] = React.useState({});
28134
+ const errors = props.form.formState.errors;
28117
28135
  const getIndex = React.useCallback((id) => lodash.findIndex(fields, function (field) {
28118
28136
  return field._id == id;
28119
28137
  }), [fields]);
28138
+ const [drawer, setDrawer] = React.useState({
28139
+ index: 0,
28140
+ open: false,
28141
+ });
28120
28142
  const handleCreate = () => {
28121
28143
  append(props.defaultValues);
28144
+ setDrawer({ index: fields.length, open: true });
28145
+ };
28146
+ const handleRowClick = (params) => {
28147
+ const index = getIndex(params.id);
28148
+ setDrawer({ index, open: true });
28149
+ };
28150
+ const handleCloseDrawer = () => {
28151
+ setDrawer((prev) => ({ ...prev, open: false }));
28152
+ };
28153
+ const handleCancel = () => {
28154
+ update(drawer.index, fields[drawer.index]);
28155
+ handleCloseDrawer();
28156
+ };
28157
+ const handleSave = () => {
28158
+ update(drawer.index, props.form.watch(`${props.name}.${drawer.index}`));
28159
+ handleCloseDrawer();
28122
28160
  };
28123
28161
  const handleDelete = (id) => {
28124
28162
  remove(getIndex(id));
28125
28163
  };
28126
- const processRowUpdate = async (newRow, originalRow) => {
28127
- const original_data = formParser({ submitData: originalRow, props: props.parser });
28128
- const data = formParser({ submitData: newRow, props: props.parser });
28129
- if (lodash.isEqual(data, original_data))
28130
- return originalRow;
28131
- const index = getIndex(data._id);
28132
- update(index, data);
28133
- return newRow;
28134
- };
28135
- const handleProcessRowUpdateError = () => { };
28136
28164
  const dataGridProps = mergeSettings({
28137
28165
  columns: !detail
28138
28166
  ? [
28139
- ...editColumn({
28140
- displayEdit: true,
28141
- rowModesModel,
28142
- setRowModesModel,
28143
- }),
28144
28167
  {
28145
28168
  field: "delete",
28146
28169
  type: "actions",
@@ -28156,8 +28179,7 @@ const FieldArrayField = (props) => {
28156
28179
  slots: { toolbar: EditToolbar },
28157
28180
  slotProps: {
28158
28181
  toolbar: {
28159
- handleCreate: handleCreate,
28160
- handleDelete: handleDelete,
28182
+ handleClick: handleCreate,
28161
28183
  pageType: props.pageType,
28162
28184
  },
28163
28185
  baseCheckbox: {
@@ -28165,25 +28187,32 @@ const FieldArrayField = (props) => {
28165
28187
  },
28166
28188
  },
28167
28189
  getRowId: (row) => row._id,
28168
- getRowClassName: (params) => params.indexRelativeToCurrentPage % 2 === 0 ? "even" : "odd",
28169
- density: "compact",
28170
- onRowClick: undefined,
28171
- editMode: "row",
28172
- rowModesModel: rowModesModel,
28173
- onRowModesModelChange: setRowModesModel,
28174
- processRowUpdate: processRowUpdate,
28175
- onProcessRowUpdateError: handleProcessRowUpdateError,
28176
- onRowEditStart: ({ reason }, event) => {
28177
- if (reason === xDataGrid.GridRowEditStartReasons.cellDoubleClick && detail)
28178
- event.defaultMuiPrevented = true;
28179
- },
28180
- onRowEditStop: (params, event) => {
28181
- if (params.reason === xDataGrid.GridRowEditStopReasons.rowFocusOut) {
28182
- event.defaultMuiPrevented = true;
28183
- }
28190
+ getRowClassName: (params) => {
28191
+ const hasError = !!(errors &&
28192
+ props.name in errors &&
28193
+ errors[props.name][getIndex(params.row._id)]);
28194
+ return hasError
28195
+ ? "row-error"
28196
+ : params.indexRelativeToCurrentPage % 2 === 0
28197
+ ? "even"
28198
+ : "odd";
28184
28199
  },
28200
+ density: "compact",
28201
+ onRowClick: props.pageType != "detail" ? handleRowClick : undefined,
28185
28202
  }, props.dataGridProps);
28186
- return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: 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 }) })] }) }));
28203
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(MainDrawer, { open: drawer.open, drawerToggle: handleCancel, title: "Trailer", slots: {
28204
+ button: (jsxRuntime.jsx(SaveCancelButton, { slotProps: {
28205
+ saveBtn: { onClick: handleSave, type: "button" },
28206
+ cancelBtn: { onClick: handleCancel },
28207
+ } })),
28208
+ }, ...props.slotProps?.drawer, children: jsxRuntime.jsx(material.Grid, { container: true, size: 12, children: props.fields.map((field, index) => {
28209
+ return (jsxRuntime.jsxs(material.Grid, { rowSpacing: 1, container: true, size: "grow", direction: "column", ...field.gridProps, children: [jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(material.Typography, { variant: "body1", fontWeight: "bold", children: field.label }) }), jsxRuntime.jsx(material.Grid, { size: 12, children: field.type({
28210
+ name: `${props.name}.${drawer.index}.${field.name}`,
28211
+ control: props.form.control,
28212
+ fieldProps: field.fieldProps,
28213
+ extraProps: field.extraProps,
28214
+ }) })] }, `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 }) })] })] }));
28187
28216
  };
28188
28217
 
28189
28218
  const Section = (props) => {
@@ -28416,7 +28445,7 @@ function DetailPage(props) {
28416
28445
  }
28417
28446
  }
28418
28447
  }, [data, dispatch, form, props.slots?.title]);
28419
- const [mutation, { isLoading: mutationIsLoading, isSuccess, data: mutationResponse }] = props.api.mutate.mutation();
28448
+ const [mutation, { isLoading: mutationIsLoading, isSuccess, data: mutationResponse },] = props.api.mutate.mutation();
28420
28449
  const handleCancel = () => {
28421
28450
  form.reset();
28422
28451
  navigate(-1);
@@ -28426,7 +28455,8 @@ function DetailPage(props) {
28426
28455
  // ==============================|| VALIDATION ||============================== //
28427
28456
  useValidateFieldData(props, form);
28428
28457
  // ==============================|| QUICK RETURN ||============================== //
28429
- if ((!canEdit && props.pageType == "edit") || (fetchError && fetchError.originalStatus == 403))
28458
+ if ((!canEdit && props.pageType == "edit") ||
28459
+ (fetchError && fetchError.originalStatus == 403))
28430
28460
  return jsxRuntime.jsx(NotAllowed, {});
28431
28461
  if (fetchError && fetchError.originalStatus == 404)
28432
28462
  return jsxRuntime.jsx(NotFound, {});
@@ -28440,7 +28470,9 @@ function DetailPage(props) {
28440
28470
  props: props.slotProps?.parser,
28441
28471
  };
28442
28472
  const dataToSend = formParser(params);
28443
- mutation(props.edit.useFormData ? dataToSend : { ...dataToSend, ...props.api.mutate.args })
28473
+ mutation(props.edit.useFormData
28474
+ ? dataToSend
28475
+ : { ...dataToSend, ...props.api.mutate.args })
28444
28476
  .unwrap()
28445
28477
  .then(() => {
28446
28478
  if (!props.slotProps?.button?.save?.disableNavBack)
@@ -28472,7 +28504,9 @@ function DetailPage(props) {
28472
28504
  if (!section.display)
28473
28505
  return null;
28474
28506
  if (typeof section.display == "object") {
28475
- const validateAgainst = form.watch(section.display.field)?.toString();
28507
+ const validateAgainst = form
28508
+ .watch(section.display.field)
28509
+ ?.toString();
28476
28510
  if (!section.display.method(validateAgainst, section.display.value))
28477
28511
  return null;
28478
28512
  }
@@ -28484,7 +28518,8 @@ function DetailPage(props) {
28484
28518
  if (props.api.mutate.postAction &&
28485
28519
  isSuccess &&
28486
28520
  "post_action" in mutationResponse &&
28487
- mutationResponse["post_action"]["type"] === props.api.mutate.postAction.type) {
28521
+ mutationResponse["post_action"]["type"] ===
28522
+ props.api.mutate.postAction.type) {
28488
28523
  switch (props.api.mutate.postAction.after) {
28489
28524
  // case 'create':
28490
28525
  // if (props.pageType === 'create') return addPropsToNode(props.api.mutate.postAction.node, mutationResponse);
@@ -28721,67 +28756,70 @@ function themeTypography() {
28721
28756
  // ==============================|| PERSONALIZADO DE COMPONENTES DE MUI ||============================== //
28722
28757
  /**
28723
28758
  * Cambia el diseño default de ciertos componentes de Material UI
28724
- **/
28759
+ **/
28725
28760
  function componentStyleOverrides(theme) {
28726
28761
  return {
28727
28762
  MuiAlert: {
28728
28763
  defaultProps: {
28729
- variant: 'filled'
28764
+ variant: "filled",
28730
28765
  },
28731
28766
  },
28732
28767
  MuiListItemButton: {
28733
28768
  styleOverrides: {
28734
28769
  root: {
28735
- '&:hover': {
28770
+ "&:hover": {
28736
28771
  backgroundColor: `${theme.palette.primary.main} !important`,
28737
- '& .MuiTypography-root': {
28738
- color: 'white !important',
28772
+ "& .MuiTypography-root": {
28773
+ color: "white !important",
28739
28774
  },
28740
- '& .MuiSvgIcon-root': {
28741
- color: 'white !important'
28742
- }
28743
- }
28744
- }
28745
- }
28775
+ "& .MuiSvgIcon-root": {
28776
+ color: "white !important",
28777
+ },
28778
+ },
28779
+ },
28780
+ },
28746
28781
  },
28747
28782
  MuiDataGrid: {
28748
28783
  styleOverrides: {
28749
28784
  columnHeader: {
28750
- '& .MuiDataGrid-columnHeaderTitle': {
28751
- fontWeight: 'bold'
28785
+ "& .MuiDataGrid-columnHeaderTitle": {
28786
+ fontWeight: "bold",
28752
28787
  },
28753
- '&:focus': {
28754
- outline: 'none',
28788
+ "&:focus": {
28789
+ outline: "none",
28755
28790
  },
28756
28791
  },
28757
28792
  row: {
28793
+ [`&.row-error`]: {
28794
+ backgroundColor: colors.red[100],
28795
+ },
28758
28796
  [`&.even`]: {
28759
28797
  backgroundColor: colors.grey[50],
28760
28798
  },
28761
- '&:hover': {
28799
+ "&:hover": {
28762
28800
  backgroundColor: material.alpha(theme.palette.primary.main, 0.2),
28763
- '@media (hover: none)': {
28764
- backgroundColor: 'transparent',
28801
+ "@media (hover: none)": {
28802
+ backgroundColor: "transparent",
28765
28803
  },
28766
- }
28804
+ },
28767
28805
  },
28768
28806
  cell: {
28769
- '& .MuiOutlinedInput-notchedOutline': {
28770
- border: 'none',
28807
+ "& .MuiOutlinedInput-notchedOutline": {
28808
+ border: "none",
28771
28809
  },
28772
- '&.MuiDataGrid-cell--editing': {
28773
- backgroundColor: 'rgb(217 243 190)',
28774
- '& .MuiInputBase-root': {
28775
- height: '100%',
28810
+ "&.MuiDataGrid-cell--editing": {
28811
+ backgroundColor: "rgb(217 243 190)",
28812
+ "& .MuiInputBase-root": {
28813
+ height: "100%",
28776
28814
  },
28777
28815
  },
28778
- '& .Mui-error': {
28779
- backgroundColor: 'rgba(234,27,43,0.2)',
28780
- color: '#ef1a2b',
28781
- fontWeight: 'bold',
28816
+ "& .Mui-error": {
28817
+ backgroundColor: "rgba(234,27,43,0.2)",
28818
+ color: "#ef1a2b",
28819
+ fontWeight: "bold",
28782
28820
  },
28783
28821
  },
28784
- }
28822
+ },
28785
28823
  },
28786
28824
  };
28787
28825
  }