ublo-lib 1.20.5 → 1.20.7
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/es/common/components/custom-contact-form/custom-contact-form.d.ts +24 -0
- package/es/common/components/custom-contact-form/custom-contact-form.d.ts.map +1 -0
- package/es/common/components/custom-contact-form/custom-contact-form.js +75 -143
- package/es/common/components/custom-contact-form/field.js +1 -1
- package/es/common/components/plausible/services/send-goal.d.ts +1 -1
- package/es/common/components/plausible/services/send-goal.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
kind?: string;
|
|
4
|
+
title?: string;
|
|
5
|
+
fields: any;
|
|
6
|
+
presets?: {
|
|
7
|
+
values?: Record<string, any>;
|
|
8
|
+
setter?: React.Dispatch<React.SetStateAction<Record<string, any> | undefined>>;
|
|
9
|
+
allowReset?: boolean;
|
|
10
|
+
disableFields?: boolean;
|
|
11
|
+
};
|
|
12
|
+
className?: string;
|
|
13
|
+
innerClassName?: string;
|
|
14
|
+
subject?: {
|
|
15
|
+
prefix?: string;
|
|
16
|
+
suffix?: string;
|
|
17
|
+
};
|
|
18
|
+
onSubmit?: (data: any) => void;
|
|
19
|
+
customSend?: (data: any) => Promise<any>;
|
|
20
|
+
};
|
|
21
|
+
declare const _default: React.MemoExoticComponent<typeof CustomContactFormWithSnackbar>;
|
|
22
|
+
export default _default;
|
|
23
|
+
declare function CustomContactFormWithSnackbar(props: Props): import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
//# sourceMappingURL=custom-contact-form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-contact-form.d.ts","sourceRoot":"","sources":["../../../../src/common/components/custom-contact-form/custom-contact-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAa/B,KAAK,KAAK,GAAG;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,GAAG,CAAC;IACZ,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC7B,MAAM,CAAC,EAAE,KAAK,CAAC,QAAQ,CACrB,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC,CACtD,CAAC;QACF,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAC/B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CAC1C,CAAC;;AASF,wBAAyD;AAEzD,iBAAS,6BAA6B,CAAC,KAAK,EAAE,KAAK,2CAMlD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
2
|
import * as React from "react";
|
|
2
3
|
import classNames from "classnames";
|
|
3
4
|
import { useUbloContext } from "ublo/with-ublo";
|
|
@@ -10,151 +11,82 @@ import * as DTIcons from "dt-design-system/es/icons";
|
|
|
10
11
|
import * as Plausible from "../plausible";
|
|
11
12
|
import { getInitialFormState, getSettings, send } from "./utils";
|
|
12
13
|
import css from "./custom-contact-form.module.css";
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
14
|
export default React.memo(CustomContactFormWithSnackbar);
|
|
16
15
|
function CustomContactFormWithSnackbar(props) {
|
|
17
|
-
|
|
18
|
-
children: _jsx(CustomContactForm, {
|
|
19
|
-
...props
|
|
20
|
-
})
|
|
21
|
-
});
|
|
16
|
+
return (_jsx(SnackbarProvider, { children: _jsx(CustomContactForm, { ...props }) }));
|
|
22
17
|
}
|
|
23
|
-
function CustomContactForm({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const isFormValid = Object.keys(data).every(key => data[key].valid);
|
|
47
|
-
const sendForm = async () => {
|
|
48
|
-
setSending(true);
|
|
49
|
-
const sendFunction = customSend || send;
|
|
50
|
-
const {
|
|
51
|
-
message,
|
|
52
|
-
error
|
|
53
|
-
} = await sendFunction({
|
|
54
|
-
site,
|
|
55
|
-
data,
|
|
56
|
-
fields,
|
|
57
|
-
subjectPrefix: subject?.prefix,
|
|
58
|
-
subjectSuffix: subject?.suffix,
|
|
59
|
-
kind
|
|
60
|
-
});
|
|
61
|
-
if (error) {
|
|
62
|
-
snackbar.show({
|
|
63
|
-
type: "error",
|
|
64
|
-
message: error
|
|
65
|
-
});
|
|
66
|
-
} else {
|
|
67
|
-
snackbar.show({
|
|
68
|
-
type: "success",
|
|
69
|
-
message: Messages.get(lang, "sent")
|
|
70
|
-
});
|
|
71
|
-
Plausible.sendGoal("Contact-us (other requests)");
|
|
72
|
-
setData(currentData => getInitialFormState(fields, undefined, currentData.subject?.value));
|
|
73
|
-
resetForm();
|
|
74
|
-
}
|
|
75
|
-
setSending(false);
|
|
76
|
-
onSubmit?.({
|
|
77
|
-
data,
|
|
78
|
-
message,
|
|
79
|
-
error
|
|
80
|
-
});
|
|
81
|
-
};
|
|
82
|
-
const resetForm = () => {
|
|
83
|
-
presets?.setter?.(undefined);
|
|
84
|
-
setData(currentData => getInitialFormState(fields, undefined, currentData.subject?.value));
|
|
85
|
-
};
|
|
86
|
-
const blurForm = () => {
|
|
87
|
-
document.activeElement.blur();
|
|
88
|
-
};
|
|
89
|
-
React.useEffect(() => {
|
|
90
|
-
if (!ready && !settings) {
|
|
91
|
-
const init = async () => {
|
|
92
|
-
if (typeof customSend === "function") {
|
|
93
|
-
setReady(true);
|
|
94
|
-
setSettings({});
|
|
95
|
-
return;
|
|
18
|
+
function CustomContactForm({ kind, title, fields, presets, className, innerClassName, subject, onSubmit, customSend, }) {
|
|
19
|
+
const [data, setData] = React.useState(getInitialFormState(fields, presets?.values));
|
|
20
|
+
const [sending, setSending] = React.useState(false);
|
|
21
|
+
const [ready, setReady] = React.useState(false);
|
|
22
|
+
const [settings, setSettings] = React.useState();
|
|
23
|
+
const { lang, config } = useUbloContext();
|
|
24
|
+
const { site } = config;
|
|
25
|
+
const snackbar = useSnackbar();
|
|
26
|
+
const isFormValid = Object.keys(data).every((key) => data[key].valid);
|
|
27
|
+
const sendForm = async () => {
|
|
28
|
+
setSending(true);
|
|
29
|
+
const sendFunction = customSend || send;
|
|
30
|
+
const { message, error } = await sendFunction({
|
|
31
|
+
site,
|
|
32
|
+
data,
|
|
33
|
+
fields,
|
|
34
|
+
subjectPrefix: subject?.prefix,
|
|
35
|
+
subjectSuffix: subject?.suffix,
|
|
36
|
+
kind,
|
|
37
|
+
});
|
|
38
|
+
if (error) {
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
snackbar.show({ type: "error", message: error });
|
|
96
41
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
42
|
+
else {
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
snackbar.show({ type: "success", message: Messages.get(lang, "sent") });
|
|
45
|
+
Plausible.sendGoal("Contact-us (other requests)");
|
|
46
|
+
setData((currentData) => getInitialFormState(fields, undefined, currentData.subject?.value));
|
|
47
|
+
resetForm();
|
|
48
|
+
}
|
|
49
|
+
setSending(false);
|
|
50
|
+
onSubmit?.({ data, message, error });
|
|
51
|
+
};
|
|
52
|
+
const resetForm = () => {
|
|
53
|
+
presets?.setter?.(undefined);
|
|
54
|
+
setData((currentData) => getInitialFormState(fields, undefined, currentData.subject?.value));
|
|
55
|
+
};
|
|
56
|
+
const blurForm = () => {
|
|
57
|
+
const activeElement = document.activeElement;
|
|
58
|
+
if (activeElement) {
|
|
59
|
+
activeElement.blur();
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
if (!ready && !settings) {
|
|
64
|
+
const init = async () => {
|
|
65
|
+
if (typeof customSend === "function") {
|
|
66
|
+
setReady(true);
|
|
67
|
+
setSettings(undefined);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const formSettings = await getSettings(site);
|
|
71
|
+
setSettings(formSettings);
|
|
72
|
+
setReady(true);
|
|
73
|
+
};
|
|
74
|
+
init();
|
|
75
|
+
}
|
|
76
|
+
}, [customSend, ready, settings, site]);
|
|
77
|
+
React.useEffect(() => {
|
|
78
|
+
setData((currentData) => getInitialFormState(fields, presets?.values, currentData.subject?.value));
|
|
79
|
+
}, [fields, presets?.values]);
|
|
80
|
+
const classes = classNames(css.root, className);
|
|
81
|
+
const innerClasses = classNames(css.inner, {
|
|
82
|
+
[innerClassName]: innerClassName,
|
|
117
83
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}), _jsx("div", {
|
|
126
|
-
|
|
127
|
-
children: Object.keys(fields).map(key => _jsx(Field, {
|
|
128
|
-
kind: kind,
|
|
129
|
-
name: key,
|
|
130
|
-
field: fields[key],
|
|
131
|
-
data: data,
|
|
132
|
-
setData: setData,
|
|
133
|
-
settings: settings,
|
|
134
|
-
presets: presets
|
|
135
|
-
}, key))
|
|
136
|
-
}), _jsxs("div", {
|
|
137
|
-
className: css.bottom,
|
|
138
|
-
children: [presets?.allowReset && _jsx(Button, {
|
|
139
|
-
className: css.resetButton,
|
|
140
|
-
disabled: sending,
|
|
141
|
-
onClick: resetForm,
|
|
142
|
-
children: Messages.get(lang, "reset")
|
|
143
|
-
}), _jsxs(Button, {
|
|
144
|
-
className: css.submitButton,
|
|
145
|
-
disabled: !isFormValid || sending,
|
|
146
|
-
onClick: sendForm,
|
|
147
|
-
onPointerEnter: blurForm,
|
|
148
|
-
children: [Messages.get(lang, "send"), _jsx(DTIcons.Mail, {})]
|
|
149
|
-
})]
|
|
150
|
-
}), showSendingOverlay && _jsxs("div", {
|
|
151
|
-
className: css.sendingOverlay,
|
|
152
|
-
children: [_jsx(Icons.Spinner, {
|
|
153
|
-
className: css.sendingIcon
|
|
154
|
-
}), _jsx("span", {
|
|
155
|
-
className: css.sendingMessage,
|
|
156
|
-
children: Messages.get(lang, "sending")
|
|
157
|
-
})]
|
|
158
|
-
})]
|
|
159
|
-
}, formKey);
|
|
160
|
-
}
|
|
84
|
+
const showSendingOverlay = !!settings?.attachmentAllowed && sending;
|
|
85
|
+
if (!ready)
|
|
86
|
+
return null;
|
|
87
|
+
if (ready && !settings) {
|
|
88
|
+
return (_jsx("div", { className: css.root, children: Messages.get(lang, "NO_SETTINGS_FOUND") }));
|
|
89
|
+
}
|
|
90
|
+
const formKey = presets ? JSON.stringify(presets.values) : undefined;
|
|
91
|
+
return (_jsxs("div", { className: classes, children: [title && _jsx("div", { className: css.title, children: title }), _jsx("div", { className: innerClasses, children: Object.keys(fields).map((key) => (_jsx(Field, { kind: kind, name: key, field: fields[key], data: data, setData: setData, settings: settings, presets: presets }, key))) }), _jsxs("div", { className: css.bottom, children: [presets?.allowReset && (_jsx(Button, { className: css.resetButton, disabled: sending, onClick: resetForm, children: Messages.get(lang, "reset") })), _jsxs(Button, { className: css.submitButton, disabled: !isFormValid || sending, onClick: sendForm, onPointerEnter: blurForm, children: [Messages.get(lang, "send"), _jsx(DTIcons.Mail, {})] })] }), showSendingOverlay && (_jsxs("div", { className: css.sendingOverlay, children: [_jsx(Icons.Spinner, { className: css.sendingIcon }), _jsx("span", { className: css.sendingMessage, children: Messages.get(lang, "sending") })] }))] }, formKey));
|
|
92
|
+
}
|
|
@@ -36,7 +36,7 @@ export default function Field({
|
|
|
36
36
|
const [activated, setActivated] = React.useState(false);
|
|
37
37
|
const [valid, setValid] = React.useState(!required || false);
|
|
38
38
|
const presetValues = presets?.values;
|
|
39
|
-
const disablePresetedFields = presetValues && presets?.disableFields && Object.keys(presets.values).includes(name);
|
|
39
|
+
const disablePresetedFields = presetValues && presets?.disableFields !== false && Object.keys(presets.values).includes(name);
|
|
40
40
|
const isTitle = type === "title";
|
|
41
41
|
const classes = classNames({
|
|
42
42
|
[css.fieldFullWidth]: isTitle || fullWidth,
|
|
@@ -2,6 +2,6 @@ type Revenue = {
|
|
|
2
2
|
currency: string;
|
|
3
3
|
amount: number;
|
|
4
4
|
};
|
|
5
|
-
export default function sendGoal(goal: string, props
|
|
5
|
+
export default function sendGoal(goal: string, props?: Record<string, any>, revenue?: Revenue): void;
|
|
6
6
|
export {};
|
|
7
7
|
//# sourceMappingURL=send-goal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-goal.d.ts","sourceRoot":"","sources":["../../../../../src/common/components/plausible/services/send-goal.ts"],"names":[],"mappings":"AAEA,KAAK,OAAO,GAAG;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"send-goal.d.ts","sourceRoot":"","sources":["../../../../../src/common/components/plausible/services/send-goal.ts"],"names":[],"mappings":"AAEA,KAAK,OAAO,GAAG;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC3B,OAAO,CAAC,EAAE,OAAO,QAIlB"}
|