@inspirer-dev/crm-dashboard 1.0.82 → 1.0.84

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.
@@ -1,4 +1,4 @@
1
- import React, { forwardRef, useEffect, useMemo, useState } from 'react';
1
+ import React, { forwardRef, useMemo, useRef, useState } from 'react';
2
2
  import {
3
3
  Box,
4
4
  Button,
@@ -17,7 +17,7 @@ import { Plus, Trash } from '@strapi/icons';
17
17
  import { useTheme } from 'styled-components';
18
18
  import { TRIGGER_PARAMS, STAGE_TYPE_LABELS, type TriggerParamDef } from './constants';
19
19
 
20
- type TriggerParamsValue = Record<string, number | undefined>;
20
+ type TriggerParamsValue = Record<string, number | null>;
21
21
 
22
22
  interface TriggerParamsFieldProps {
23
23
  name: string;
@@ -47,13 +47,11 @@ const parseValue = (value: string | TriggerParamsValue | null | undefined): Trig
47
47
  };
48
48
 
49
49
  const serialize = (params: TriggerParamsValue): string => {
50
- const clean: Record<string, number> = {};
50
+ const out: Record<string, number | null> = {};
51
51
  for (const [key, val] of Object.entries(params)) {
52
- if (val !== undefined && val !== null) {
53
- clean[key] = val;
54
- }
52
+ out[key] = typeof val === 'number' ? val : null;
55
53
  }
56
- return JSON.stringify(clean);
54
+ return JSON.stringify(out);
57
55
  };
58
56
 
59
57
  interface StrapiTheme {
@@ -77,28 +75,23 @@ const useThemeColors = () => {
77
75
 
78
76
  const TriggerParamsField = forwardRef<HTMLDivElement, TriggerParamsFieldProps>(
79
77
  ({ name, value, onChange, intlLabel, disabled, error, required, hint }, ref) => {
80
- const [params, setParams] = useState<TriggerParamsValue>(() => parseValue(value));
78
+ const initialRef = useRef(value);
79
+ const [params, setParams] = useState<TriggerParamsValue>(() => parseValue(initialRef.current));
81
80
  const colors = useThemeColors();
82
81
 
83
- useEffect(() => {
84
- setParams(parseValue(value));
85
- }, [value]);
86
-
87
82
  const update = (next: TriggerParamsValue) => {
88
83
  setParams(next);
89
84
  onChange({ target: { name, value: serialize(next) } });
90
85
  };
91
86
 
92
- const activeKeys = Object.keys(params).filter(
93
- (k) => params[k] !== undefined && params[k] !== null
94
- );
87
+ const activeKeys = Object.keys(params);
95
88
 
96
89
  const availableParams = TRIGGER_PARAMS.filter((p) => !activeKeys.includes(p.key));
97
90
 
98
91
  const addParam = (key: string) => {
99
92
  const def = TRIGGER_PARAMS.find((p) => p.key === key);
100
93
  if (!def) return;
101
- update({ ...params, [key]: undefined });
94
+ update({ ...params, [key]: null });
102
95
  };
103
96
 
104
97
  const removeParam = (key: string) => {
@@ -108,7 +101,7 @@ const TriggerParamsField = forwardRef<HTMLDivElement, TriggerParamsFieldProps>(
108
101
  };
109
102
 
110
103
  const setParamValue = (key: string, val: number | undefined) => {
111
- update({ ...params, [key]: val });
104
+ update({ ...params, [key]: val ?? null });
112
105
  };
113
106
 
114
107
  const getParamDef = (key: string): TriggerParamDef | undefined =>
@@ -1,5 +1,5 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useState, useEffect, useMemo } from "react";
2
+ import { forwardRef, useRef, useState, useMemo } from "react";
3
3
  import { Field, Flex, Box, Typography, Card, CardContent, NumberInput, Tooltip, IconButton, SingleSelect, SingleSelectOption, Button } from "@strapi/design-system";
4
4
  import { Trash, Plus } from "@strapi/icons";
5
5
  import { useTheme } from "styled-components";
@@ -114,13 +114,11 @@ const parseValue = (value) => {
114
114
  return {};
115
115
  };
116
116
  const serialize = (params) => {
117
- const clean = {};
117
+ const out = {};
118
118
  for (const [key, val] of Object.entries(params)) {
119
- if (val !== void 0 && val !== null) {
120
- clean[key] = val;
121
- }
119
+ out[key] = typeof val === "number" ? val : null;
122
120
  }
123
- return JSON.stringify(clean);
121
+ return JSON.stringify(out);
124
122
  };
125
123
  const useThemeColors = () => {
126
124
  const theme = useTheme();
@@ -137,23 +135,19 @@ const useThemeColors = () => {
137
135
  };
138
136
  const TriggerParamsField = forwardRef(
139
137
  ({ name, value, onChange, intlLabel, disabled, error, required, hint }, ref) => {
140
- const [params, setParams] = useState(() => parseValue(value));
138
+ const initialRef = useRef(value);
139
+ const [params, setParams] = useState(() => parseValue(initialRef.current));
141
140
  const colors = useThemeColors();
142
- useEffect(() => {
143
- setParams(parseValue(value));
144
- }, [value]);
145
141
  const update = (next) => {
146
142
  setParams(next);
147
143
  onChange({ target: { name, value: serialize(next) } });
148
144
  };
149
- const activeKeys = Object.keys(params).filter(
150
- (k) => params[k] !== void 0 && params[k] !== null
151
- );
145
+ const activeKeys = Object.keys(params);
152
146
  const availableParams = TRIGGER_PARAMS.filter((p) => !activeKeys.includes(p.key));
153
147
  const addParam = (key) => {
154
148
  const def = TRIGGER_PARAMS.find((p) => p.key === key);
155
149
  if (!def) return;
156
- update({ ...params, [key]: void 0 });
150
+ update({ ...params, [key]: null });
157
151
  };
158
152
  const removeParam = (key) => {
159
153
  const next = { ...params };
@@ -161,7 +155,7 @@ const TriggerParamsField = forwardRef(
161
155
  update(next);
162
156
  };
163
157
  const setParamValue = (key, val) => {
164
- update({ ...params, [key]: val });
158
+ update({ ...params, [key]: val ?? null });
165
159
  };
166
160
  const getParamDef = (key) => TRIGGER_PARAMS.find((p) => p.key === key);
167
161
  return /* @__PURE__ */ jsx(Field.Root, { name, error, required, hint, ref, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", gap: 3, children: [
@@ -116,13 +116,11 @@ const parseValue = (value) => {
116
116
  return {};
117
117
  };
118
118
  const serialize = (params) => {
119
- const clean = {};
119
+ const out = {};
120
120
  for (const [key, val] of Object.entries(params)) {
121
- if (val !== void 0 && val !== null) {
122
- clean[key] = val;
123
- }
121
+ out[key] = typeof val === "number" ? val : null;
124
122
  }
125
- return JSON.stringify(clean);
123
+ return JSON.stringify(out);
126
124
  };
127
125
  const useThemeColors = () => {
128
126
  const theme = styledComponents.useTheme();
@@ -139,23 +137,19 @@ const useThemeColors = () => {
139
137
  };
140
138
  const TriggerParamsField = React.forwardRef(
141
139
  ({ name, value, onChange, intlLabel, disabled, error, required, hint }, ref) => {
142
- const [params, setParams] = React.useState(() => parseValue(value));
140
+ const initialRef = React.useRef(value);
141
+ const [params, setParams] = React.useState(() => parseValue(initialRef.current));
143
142
  const colors = useThemeColors();
144
- React.useEffect(() => {
145
- setParams(parseValue(value));
146
- }, [value]);
147
143
  const update = (next) => {
148
144
  setParams(next);
149
145
  onChange({ target: { name, value: serialize(next) } });
150
146
  };
151
- const activeKeys = Object.keys(params).filter(
152
- (k) => params[k] !== void 0 && params[k] !== null
153
- );
147
+ const activeKeys = Object.keys(params);
154
148
  const availableParams = TRIGGER_PARAMS.filter((p) => !activeKeys.includes(p.key));
155
149
  const addParam = (key) => {
156
150
  const def = TRIGGER_PARAMS.find((p) => p.key === key);
157
151
  if (!def) return;
158
- update({ ...params, [key]: void 0 });
152
+ update({ ...params, [key]: null });
159
153
  };
160
154
  const removeParam = (key) => {
161
155
  const next = { ...params };
@@ -163,7 +157,7 @@ const TriggerParamsField = React.forwardRef(
163
157
  update(next);
164
158
  };
165
159
  const setParamValue = (key, val) => {
166
- update({ ...params, [key]: val });
160
+ update({ ...params, [key]: val ?? null });
167
161
  };
168
162
  const getParamDef = (key) => TRIGGER_PARAMS.find((p) => p.key === key);
169
163
  return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Root, { name, error, required, hint, ref, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 3, children: [
@@ -155,7 +155,7 @@ const index = {
155
155
  components: {
156
156
  Input: async () => Promise.resolve().then(() => require(
157
157
  /* webpackChunkName: "crm-trigger-params" */
158
- "../_chunks/index-CuMY0eo5.js"
158
+ "../_chunks/index-Cmo9If32.js"
159
159
  ))
160
160
  },
161
161
  options: {
@@ -154,7 +154,7 @@ const index = {
154
154
  components: {
155
155
  Input: async () => import(
156
156
  /* webpackChunkName: "crm-trigger-params" */
157
- "../_chunks/index-NvFKi6er.mjs"
157
+ "../_chunks/index-Bot_XlI2.mjs"
158
158
  )
159
159
  },
160
160
  options: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inspirer-dev/crm-dashboard",
3
- "version": "1.0.82",
3
+ "version": "1.0.84",
4
4
  "description": "CRM Dashboard and Tools",
5
5
  "strapi": {
6
6
  "name": "crm-dashboard",