@acvl/frontend-components 0.0.33 → 0.0.34

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")));
@@ -25777,7 +25777,7 @@ const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, dat
25777
25777
  break;
25778
25778
  }
25779
25779
  };
25780
- const formParser = ({ type, submitData, data, useLabel, props }) => {
25780
+ const formParser = ({ type, submitData, data, useLabel, props, }) => {
25781
25781
  const t = type || "json";
25782
25782
  const response = t === "json" ? {} : new FormData();
25783
25783
  Object.entries(submitData).forEach(([key, value]) => {
@@ -28104,43 +28104,49 @@ const Field = (props) => {
28104
28104
  };
28105
28105
 
28106
28106
  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" }) }) })) }));
28107
+ 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
28108
  };
28109
28109
  const FieldArrayField = (props) => {
28110
28110
  const detail = React.useMemo(() => props.pageType === "detail", [props.pageType]);
28111
- const { fields, append, update, remove } = reactHookForm.useFieldArray({
28111
+ const { fields, append, remove, update } = reactHookForm.useFieldArray({
28112
28112
  control: props.form.control,
28113
28113
  name: props.name,
28114
28114
  keyName: "_id",
28115
28115
  });
28116
- const [rowModesModel, setRowModesModel] = React.useState({});
28116
+ // console.log(props.form?.watch(props.name));
28117
+ // console.log(fields);
28117
28118
  const getIndex = React.useCallback((id) => lodash.findIndex(fields, function (field) {
28118
28119
  return field._id == id;
28119
28120
  }), [fields]);
28121
+ const [drawer, setDrawer] = React.useState({
28122
+ index: 0,
28123
+ open: false,
28124
+ });
28120
28125
  const handleCreate = () => {
28121
28126
  append(props.defaultValues);
28127
+ setDrawer({ index: fields.length, open: true });
28128
+ };
28129
+ const handleRowClick = (params) => {
28130
+ const index = getIndex(params.id);
28131
+ setDrawer({ index, open: true });
28132
+ };
28133
+ const handleCloseDrawer = () => {
28134
+ setDrawer((prev) => ({ ...prev, open: false }));
28135
+ };
28136
+ const handleCancel = () => {
28137
+ update(drawer.index, fields[drawer.index]);
28138
+ handleCloseDrawer();
28139
+ };
28140
+ const handleSave = () => {
28141
+ update(drawer.index, props.form.watch(`${props.name}.${drawer.index}`));
28142
+ handleCloseDrawer();
28122
28143
  };
28123
28144
  const handleDelete = (id) => {
28124
28145
  remove(getIndex(id));
28125
28146
  };
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
28147
  const dataGridProps = mergeSettings({
28137
28148
  columns: !detail
28138
28149
  ? [
28139
- ...editColumn({
28140
- displayEdit: true,
28141
- rowModesModel,
28142
- setRowModesModel,
28143
- }),
28144
28150
  {
28145
28151
  field: "delete",
28146
28152
  type: "actions",
@@ -28156,8 +28162,7 @@ const FieldArrayField = (props) => {
28156
28162
  slots: { toolbar: EditToolbar },
28157
28163
  slotProps: {
28158
28164
  toolbar: {
28159
- handleCreate: handleCreate,
28160
- handleDelete: handleDelete,
28165
+ handleClick: handleCreate,
28161
28166
  pageType: props.pageType,
28162
28167
  },
28163
28168
  baseCheckbox: {
@@ -28167,23 +28172,21 @@ const FieldArrayField = (props) => {
28167
28172
  getRowId: (row) => row._id,
28168
28173
  getRowClassName: (params) => params.indexRelativeToCurrentPage % 2 === 0 ? "even" : "odd",
28169
28174
  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
- }
28184
- },
28175
+ onRowClick: props.pageType == "edit" ? handleRowClick : undefined,
28185
28176
  }, 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 }) })] }) }));
28177
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(MainDrawer, { open: drawer.open, drawerToggle: handleCancel, title: "Trailer", slots: {
28178
+ button: (jsxRuntime.jsx(SaveCancelButton, { slotProps: {
28179
+ saveBtn: { onClick: handleSave, type: "button" },
28180
+ cancelBtn: { onClick: handleCancel },
28181
+ } })),
28182
+ }, ...props.slotProps?.drawer, children: jsxRuntime.jsx(material.Grid, { container: true, size: 12, children: props.fields.map((field, index) => {
28183
+ 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({
28184
+ name: `${props.name}.${drawer.index}.${field.name}`,
28185
+ control: props.form.control,
28186
+ fieldProps: field.fieldProps,
28187
+ extraProps: field.extraProps,
28188
+ }) })] }, `grid-${index}`));
28189
+ }) }) }), 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
28190
  };
28188
28191
 
28189
28192
  const Section = (props) => {
@@ -28416,7 +28419,7 @@ function DetailPage(props) {
28416
28419
  }
28417
28420
  }
28418
28421
  }, [data, dispatch, form, props.slots?.title]);
28419
- const [mutation, { isLoading: mutationIsLoading, isSuccess, data: mutationResponse }] = props.api.mutate.mutation();
28422
+ const [mutation, { isLoading: mutationIsLoading, isSuccess, data: mutationResponse },] = props.api.mutate.mutation();
28420
28423
  const handleCancel = () => {
28421
28424
  form.reset();
28422
28425
  navigate(-1);
@@ -28426,7 +28429,8 @@ function DetailPage(props) {
28426
28429
  // ==============================|| VALIDATION ||============================== //
28427
28430
  useValidateFieldData(props, form);
28428
28431
  // ==============================|| QUICK RETURN ||============================== //
28429
- if ((!canEdit && props.pageType == "edit") || (fetchError && fetchError.originalStatus == 403))
28432
+ if ((!canEdit && props.pageType == "edit") ||
28433
+ (fetchError && fetchError.originalStatus == 403))
28430
28434
  return jsxRuntime.jsx(NotAllowed, {});
28431
28435
  if (fetchError && fetchError.originalStatus == 404)
28432
28436
  return jsxRuntime.jsx(NotFound, {});
@@ -28440,7 +28444,9 @@ function DetailPage(props) {
28440
28444
  props: props.slotProps?.parser,
28441
28445
  };
28442
28446
  const dataToSend = formParser(params);
28443
- mutation(props.edit.useFormData ? dataToSend : { ...dataToSend, ...props.api.mutate.args })
28447
+ mutation(props.edit.useFormData
28448
+ ? dataToSend
28449
+ : { ...dataToSend, ...props.api.mutate.args })
28444
28450
  .unwrap()
28445
28451
  .then(() => {
28446
28452
  if (!props.slotProps?.button?.save?.disableNavBack)
@@ -28472,7 +28478,9 @@ function DetailPage(props) {
28472
28478
  if (!section.display)
28473
28479
  return null;
28474
28480
  if (typeof section.display == "object") {
28475
- const validateAgainst = form.watch(section.display.field)?.toString();
28481
+ const validateAgainst = form
28482
+ .watch(section.display.field)
28483
+ ?.toString();
28476
28484
  if (!section.display.method(validateAgainst, section.display.value))
28477
28485
  return null;
28478
28486
  }
@@ -28484,7 +28492,8 @@ function DetailPage(props) {
28484
28492
  if (props.api.mutate.postAction &&
28485
28493
  isSuccess &&
28486
28494
  "post_action" in mutationResponse &&
28487
- mutationResponse["post_action"]["type"] === props.api.mutate.postAction.type) {
28495
+ mutationResponse["post_action"]["type"] ===
28496
+ props.api.mutate.postAction.type) {
28488
28497
  switch (props.api.mutate.postAction.after) {
28489
28498
  // case 'create':
28490
28499
  // if (props.pageType === 'create') return addPropsToNode(props.api.mutate.postAction.node, mutationResponse);