@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,
|
|
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 |
|
|
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
|
|
50
|
+
const out: Record<string, number | null> = {};
|
|
51
51
|
for (const [key, val] of Object.entries(params)) {
|
|
52
|
-
|
|
53
|
-
clean[key] = val;
|
|
54
|
-
}
|
|
52
|
+
out[key] = typeof val === 'number' ? val : null;
|
|
55
53
|
}
|
|
56
|
-
return JSON.stringify(
|
|
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
|
|
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)
|
|
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]:
|
|
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,
|
|
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
|
|
117
|
+
const out = {};
|
|
118
118
|
for (const [key, val] of Object.entries(params)) {
|
|
119
|
-
|
|
120
|
-
clean[key] = val;
|
|
121
|
-
}
|
|
119
|
+
out[key] = typeof val === "number" ? val : null;
|
|
122
120
|
}
|
|
123
|
-
return JSON.stringify(
|
|
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
|
|
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)
|
|
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]:
|
|
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
|
|
119
|
+
const out = {};
|
|
120
120
|
for (const [key, val] of Object.entries(params)) {
|
|
121
|
-
|
|
122
|
-
clean[key] = val;
|
|
123
|
-
}
|
|
121
|
+
out[key] = typeof val === "number" ? val : null;
|
|
124
122
|
}
|
|
125
|
-
return JSON.stringify(
|
|
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
|
|
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)
|
|
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]:
|
|
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: [
|
package/dist/admin/index.js
CHANGED
package/dist/admin/index.mjs
CHANGED