cozy-ui 128.2.0 → 128.3.0
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/CHANGELOG.md +8 -0
- package/package.json +5 -1
- package/react/Contacts/AddModal/ContactAddressDialog/helpers.js +22 -0
- package/react/Contacts/AddModal/ContactAddressDialog/helpers.spec.js +64 -0
- package/react/Contacts/AddModal/ContactAddressDialog/index.jsx +84 -0
- package/react/Contacts/AddModal/ContactAddressDialog/locales/en.json +25 -0
- package/react/Contacts/AddModal/ContactAddressDialog/locales/fr.json +25 -0
- package/react/Contacts/AddModal/ContactAddressDialog/locales/index.jsx +7 -0
- package/react/Contacts/AddModal/ContactForm/FieldInput.jsx +117 -0
- package/react/Contacts/AddModal/ContactForm/FieldInputArray.jsx +80 -0
- package/react/Contacts/AddModal/ContactForm/FieldInputLayout.jsx +65 -0
- package/react/Contacts/AddModal/ContactForm/FieldInputWrapper.jsx +41 -0
- package/react/Contacts/AddModal/ContactForm/HasValueCondition.jsx +31 -0
- package/react/Contacts/AddModal/ContactForm/HasValueCondition.spec.jsx +79 -0
- package/react/Contacts/AddModal/ContactForm/RelatedContactList.jsx +37 -0
- package/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.jsx +78 -0
- package/react/Contacts/AddModal/ContactForm/TextFieldSelect.jsx +39 -0
- package/react/Contacts/AddModal/ContactForm/__snapshots__/HasValueCondition.spec.jsx.snap +33 -0
- package/react/Contacts/AddModal/ContactForm/contactToFormValues.js +99 -0
- package/react/Contacts/AddModal/ContactForm/contactToFormValues.spec.js +128 -0
- package/react/Contacts/AddModal/ContactForm/fieldsConfig.jsx +341 -0
- package/react/Contacts/AddModal/ContactForm/formValuesToContact.js +100 -0
- package/react/Contacts/AddModal/ContactForm/formValuesToContact.spec.js +494 -0
- package/react/Contacts/AddModal/ContactForm/helpers.js +324 -0
- package/react/Contacts/AddModal/ContactForm/helpers.spec.js +152 -0
- package/react/Contacts/AddModal/ContactForm/index.jsx +104 -0
- package/react/Contacts/AddModal/ContactForm/index.spec.jsx +289 -0
- package/react/Contacts/AddModal/ContactForm/locales/en.json +73 -0
- package/react/Contacts/AddModal/ContactForm/locales/fr.json +73 -0
- package/react/Contacts/AddModal/ContactForm/locales/index.jsx +7 -0
- package/react/Contacts/AddModal/ContactForm/styles.styl +2 -0
- package/react/Contacts/AddModal/CustomLabelDialog/index.jsx +108 -0
- package/react/Contacts/AddModal/CustomLabelDialog/locales/en.json +15 -0
- package/react/Contacts/AddModal/CustomLabelDialog/locales/fr.json +15 -0
- package/react/Contacts/AddModal/CustomLabelDialog/locales/index.jsx +7 -0
- package/react/Contacts/AddModal/Readme.md +46 -0
- package/react/Contacts/AddModal/index.jsx +78 -0
- package/react/Contacts/AddModal/locales/en.json +13 -0
- package/react/Contacts/AddModal/locales/fr.json +13 -0
- package/react/Contacts/AddModal/locales/index.jsx +7 -0
- package/react/Contacts/AddModal/mocks.js +249 -0
- package/react/Contacts/AddModal/types.js +57 -0
- package/react/Contacts/Header/Readme.md +0 -2
- package/react/providers/DemoProvider.jsx +3 -2
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.d.ts +4 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.js +20 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/helpers.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/index.d.ts +39 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/index.js +87 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/ContactAddressDialog/locales/index.js +54 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.d.ts +35 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInput.js +126 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputArray.d.ts +14 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputArray.js +82 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.d.ts +20 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputLayout.js +70 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper.d.ts +16 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper.js +31 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.d.ts +18 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.js +32 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/RelatedContactList.d.ts +15 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/RelatedContactList.js +39 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.d.ts +9 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect.js +81 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect.d.ts +5 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect.js +42 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.d.ts +2 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.js +88 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/contactToFormValues.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.d.ts +4 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/fieldsConfig.js +278 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.js +94 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/formValuesToContact.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/helpers.d.ts +28 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/helpers.js +335 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/helpers.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/index.d.ts +11 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/index.js +114 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/index.spec.d.ts +1 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/ContactForm/locales/index.js +150 -0
- package/transpiled/react/Contacts/AddModal/CustomLabelDialog/index.d.ts +22 -0
- package/transpiled/react/Contacts/AddModal/CustomLabelDialog/index.js +113 -0
- package/transpiled/react/Contacts/AddModal/CustomLabelDialog/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/CustomLabelDialog/locales/index.js +34 -0
- package/transpiled/react/Contacts/AddModal/index.d.ts +7 -0
- package/transpiled/react/Contacts/AddModal/index.js +109 -0
- package/transpiled/react/Contacts/AddModal/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/AddModal/locales/index.js +30 -0
- package/transpiled/react/Contacts/AddModal/mocks.d.ts +270 -0
- package/transpiled/react/Contacts/AddModal/mocks.js +214 -0
- package/transpiled/react/Contacts/AddModal/types.d.ts +54 -0
- package/transpiled/react/Contacts/AddModal/types.js +49 -0
- package/transpiled/react/providers/DemoProvider.d.ts +2 -1
- package/transpiled/react/providers/DemoProvider.js +7 -3
- package/transpiled/react/stylesheet.css +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export default FieldInput;
|
|
2
|
+
declare function FieldInput({ name, labelProps, attributes: { subFields, ...restAttributes }, contacts, error, helperText, label, required }: {
|
|
3
|
+
name: any;
|
|
4
|
+
labelProps: any;
|
|
5
|
+
attributes: {
|
|
6
|
+
[x: string]: any;
|
|
7
|
+
subFields: any;
|
|
8
|
+
};
|
|
9
|
+
contacts: any;
|
|
10
|
+
error: any;
|
|
11
|
+
helperText: any;
|
|
12
|
+
label: any;
|
|
13
|
+
required: any;
|
|
14
|
+
}): JSX.Element;
|
|
15
|
+
declare namespace FieldInput {
|
|
16
|
+
namespace propTypes {
|
|
17
|
+
export const name: PropTypes.Validator<string>;
|
|
18
|
+
export { labelPropTypes as labelProps };
|
|
19
|
+
export { fieldInputAttributesTypes as attributes };
|
|
20
|
+
export const contacts: PropTypes.Requireable<PropTypes.InferProps<{
|
|
21
|
+
data: PropTypes.Requireable<(object | null)[]>;
|
|
22
|
+
}>>;
|
|
23
|
+
export const id: PropTypes.Requireable<string>;
|
|
24
|
+
export const label: PropTypes.Requireable<string>;
|
|
25
|
+
export const required: PropTypes.Requireable<boolean>;
|
|
26
|
+
}
|
|
27
|
+
namespace defaultProps {
|
|
28
|
+
export const labelProps: null;
|
|
29
|
+
const required_1: boolean;
|
|
30
|
+
export { required_1 as required };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
import PropTypes from "prop-types";
|
|
34
|
+
import { labelPropTypes } from "../types";
|
|
35
|
+
import { fieldInputAttributesTypes } from "../types";
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["subFields"];
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
import uniqueId from 'lodash/uniqueId';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import React, { useState } from 'react';
|
|
8
|
+
import { Field } from 'react-final-form';
|
|
9
|
+
import FieldInputWrapper from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/FieldInputWrapper";
|
|
10
|
+
import HasValueCondition from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/HasValueCondition";
|
|
11
|
+
import { RelatedContactList } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/RelatedContactList";
|
|
12
|
+
import { locales } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/locales";
|
|
13
|
+
var styles = {
|
|
14
|
+
"contact-form-field__wrapper": "styles__contact-form-field__wrapper___39a5x"
|
|
15
|
+
};
|
|
16
|
+
import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
|
17
|
+
import ContactAddressDialog from "cozy-ui/transpiled/react/Contacts/AddModal/ContactAddressDialog";
|
|
18
|
+
import { fieldInputAttributesTypes, labelPropTypes } from "cozy-ui/transpiled/react/Contacts/AddModal/types";
|
|
19
|
+
|
|
20
|
+
var FieldInput = function FieldInput(_ref) {
|
|
21
|
+
var name = _ref.name,
|
|
22
|
+
labelProps = _ref.labelProps,
|
|
23
|
+
_ref$attributes = _ref.attributes,
|
|
24
|
+
subFields = _ref$attributes.subFields,
|
|
25
|
+
restAttributes = _objectWithoutProperties(_ref$attributes, _excluded),
|
|
26
|
+
contacts = _ref.contacts,
|
|
27
|
+
error = _ref.error,
|
|
28
|
+
helperText = _ref.helperText,
|
|
29
|
+
label = _ref.label,
|
|
30
|
+
required = _ref.required;
|
|
31
|
+
|
|
32
|
+
var _useState = useState(uniqueId('field_')),
|
|
33
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
34
|
+
id = _useState2[0]; // state only use to generate id once and not at each render
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
var _useState3 = useState(false),
|
|
38
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
39
|
+
hasBeenFocused = _useState4[0],
|
|
40
|
+
setHasBeenFocused = _useState4[1];
|
|
41
|
+
|
|
42
|
+
var _useState5 = useState(false),
|
|
43
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
44
|
+
isAddressDialogOpen = _useState6[0],
|
|
45
|
+
setIsAddressDialogOpen = _useState6[1];
|
|
46
|
+
|
|
47
|
+
var _useState7 = useState(false),
|
|
48
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
49
|
+
isRelatedContactDialogOpen = _useState8[0],
|
|
50
|
+
setIsRelatedContactDialogOpen = _useState8[1];
|
|
51
|
+
|
|
52
|
+
useExtendI18n(locales);
|
|
53
|
+
|
|
54
|
+
var _useI18n = useI18n(),
|
|
55
|
+
t = _useI18n.t;
|
|
56
|
+
|
|
57
|
+
var handleClick = function handleClick() {
|
|
58
|
+
if (name.includes('address')) {
|
|
59
|
+
setIsAddressDialogOpen(true);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (name.includes('relatedContact')) {
|
|
63
|
+
setIsRelatedContactDialogOpen(true);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
var onFocus = function onFocus() {
|
|
68
|
+
setHasBeenFocused(true);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
72
|
+
className: cx(styles['contact-form-field__wrapper'], 'u-flex', 'u-flex-column-s')
|
|
73
|
+
}, /*#__PURE__*/React.createElement(Field, {
|
|
74
|
+
required: required,
|
|
75
|
+
error: error,
|
|
76
|
+
helperText: helperText,
|
|
77
|
+
label: label,
|
|
78
|
+
id: id,
|
|
79
|
+
attributes: restAttributes,
|
|
80
|
+
name: name,
|
|
81
|
+
component: FieldInputWrapper,
|
|
82
|
+
onFocus: onFocus,
|
|
83
|
+
onClick: handleClick
|
|
84
|
+
}), isAddressDialogOpen && /*#__PURE__*/React.createElement(ContactAddressDialog, {
|
|
85
|
+
onClose: function onClose() {
|
|
86
|
+
return setIsAddressDialogOpen(false);
|
|
87
|
+
},
|
|
88
|
+
name: name,
|
|
89
|
+
subFields: subFields
|
|
90
|
+
}), isRelatedContactDialogOpen && /*#__PURE__*/React.createElement(RelatedContactList, {
|
|
91
|
+
onClose: function onClose() {
|
|
92
|
+
return setIsRelatedContactDialogOpen(false);
|
|
93
|
+
},
|
|
94
|
+
name: name,
|
|
95
|
+
contacts: contacts
|
|
96
|
+
}), labelProps && /*#__PURE__*/React.createElement(HasValueCondition, {
|
|
97
|
+
name: name,
|
|
98
|
+
otherCondition: hasBeenFocused
|
|
99
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
100
|
+
className: "u-mt-half-s u-ml-half u-ml-0-s u-flex-shrink-0 u-w-auto u-miw-4"
|
|
101
|
+
}, /*#__PURE__*/React.createElement(Field, {
|
|
102
|
+
attributes: labelProps,
|
|
103
|
+
name: "".concat(name, "Label"),
|
|
104
|
+
label: t('Contacts.AddModal.ContactForm.fields.label'),
|
|
105
|
+
component: FieldInputWrapper,
|
|
106
|
+
onFocus: onFocus
|
|
107
|
+
}))));
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
FieldInput.propTypes = {
|
|
111
|
+
name: PropTypes.string.isRequired,
|
|
112
|
+
labelProps: labelPropTypes,
|
|
113
|
+
attributes: fieldInputAttributesTypes,
|
|
114
|
+
contacts: PropTypes.shape({
|
|
115
|
+
data: PropTypes.arrayOf(PropTypes.object)
|
|
116
|
+
}),
|
|
117
|
+
// Destructuring props
|
|
118
|
+
id: PropTypes.string,
|
|
119
|
+
label: PropTypes.string,
|
|
120
|
+
required: PropTypes.bool
|
|
121
|
+
};
|
|
122
|
+
FieldInput.defaultProps = {
|
|
123
|
+
labelProps: null,
|
|
124
|
+
required: false
|
|
125
|
+
};
|
|
126
|
+
export default FieldInput;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default FieldInputArray;
|
|
2
|
+
declare function FieldInputArray({ attributes: { name, label, ...restAttributes }, contacts, formProps: { valid, submitFailed, errors } }: {
|
|
3
|
+
attributes: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
name: any;
|
|
6
|
+
label: any;
|
|
7
|
+
};
|
|
8
|
+
contacts: any;
|
|
9
|
+
formProps: {
|
|
10
|
+
valid: any;
|
|
11
|
+
submitFailed: any;
|
|
12
|
+
errors: any;
|
|
13
|
+
};
|
|
14
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
var _excluded = ["name", "label"];
|
|
3
|
+
import cx from 'classnames';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { FieldArray } from 'react-final-form-arrays';
|
|
6
|
+
import FieldInput from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/FieldInput";
|
|
7
|
+
import { fieldsRequired, addField, removeField } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/helpers";
|
|
8
|
+
import { locales } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/locales";
|
|
9
|
+
import Button from "cozy-ui/transpiled/react/Buttons";
|
|
10
|
+
import Icon from "cozy-ui/transpiled/react/Icon";
|
|
11
|
+
import IconButton from "cozy-ui/transpiled/react/IconButton";
|
|
12
|
+
import CrossCircleIcon from "cozy-ui/transpiled/react/Icons/CrossCircle";
|
|
13
|
+
import PlusIcon from "cozy-ui/transpiled/react/Icons/Plus";
|
|
14
|
+
import ListItemIcon from "cozy-ui/transpiled/react/ListItemIcon";
|
|
15
|
+
import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
|
16
|
+
|
|
17
|
+
var FieldInputArray = function FieldInputArray(_ref) {
|
|
18
|
+
var _ref$attributes = _ref.attributes,
|
|
19
|
+
name = _ref$attributes.name,
|
|
20
|
+
label = _ref$attributes.label,
|
|
21
|
+
restAttributes = _objectWithoutProperties(_ref$attributes, _excluded),
|
|
22
|
+
contacts = _ref.contacts,
|
|
23
|
+
_ref$formProps = _ref.formProps,
|
|
24
|
+
valid = _ref$formProps.valid,
|
|
25
|
+
submitFailed = _ref$formProps.submitFailed,
|
|
26
|
+
errors = _ref$formProps.errors;
|
|
27
|
+
|
|
28
|
+
useExtendI18n(locales);
|
|
29
|
+
|
|
30
|
+
var _useI18n = useI18n(),
|
|
31
|
+
t = _useI18n.t;
|
|
32
|
+
|
|
33
|
+
return /*#__PURE__*/React.createElement(FieldArray, {
|
|
34
|
+
name: name
|
|
35
|
+
}, function (_ref2) {
|
|
36
|
+
var fields = _ref2.fields;
|
|
37
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, fields.map(function (nameWithIndex, index) {
|
|
38
|
+
var _fields$value$index, _fields$value$index2;
|
|
39
|
+
|
|
40
|
+
var key = ((_fields$value$index = fields.value[index]) === null || _fields$value$index === void 0 ? void 0 : _fields$value$index.fieldId) || nameWithIndex;
|
|
41
|
+
var showRemove = (_fields$value$index2 = fields.value[index]) === null || _fields$value$index2 === void 0 ? void 0 : _fields$value$index2[name];
|
|
42
|
+
var inputName = "".concat(nameWithIndex, ".").concat(name);
|
|
43
|
+
var isError = fieldsRequired.includes(inputName) && !valid && submitFailed;
|
|
44
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
45
|
+
key: key,
|
|
46
|
+
className: cx('u-flex u-flex-items-center', {
|
|
47
|
+
'u-mt-1': index !== 0
|
|
48
|
+
})
|
|
49
|
+
}, /*#__PURE__*/React.createElement(FieldInput, {
|
|
50
|
+
attributes: restAttributes,
|
|
51
|
+
contacts: contacts,
|
|
52
|
+
error: isError,
|
|
53
|
+
helperText: isError ? errors[inputName] : null,
|
|
54
|
+
name: inputName,
|
|
55
|
+
label: t("Contacts.AddModal.ContactForm.fields.".concat(name)),
|
|
56
|
+
labelProps: label
|
|
57
|
+
}), showRemove && /*#__PURE__*/React.createElement(ListItemIcon, {
|
|
58
|
+
className: "u-ml-half"
|
|
59
|
+
}, /*#__PURE__*/React.createElement(IconButton, {
|
|
60
|
+
"aria-label": "delete",
|
|
61
|
+
color: "error",
|
|
62
|
+
size: "medium",
|
|
63
|
+
onClick: function onClick() {
|
|
64
|
+
return removeField(fields, index);
|
|
65
|
+
}
|
|
66
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
67
|
+
icon: CrossCircleIcon
|
|
68
|
+
}))));
|
|
69
|
+
}), /*#__PURE__*/React.createElement(Button, {
|
|
70
|
+
variant: "text",
|
|
71
|
+
startIcon: /*#__PURE__*/React.createElement(Icon, {
|
|
72
|
+
icon: PlusIcon
|
|
73
|
+
}),
|
|
74
|
+
onClick: function onClick() {
|
|
75
|
+
return addField(fields);
|
|
76
|
+
},
|
|
77
|
+
label: t("Contacts.AddModal.ContactForm.addLabel.".concat(name))
|
|
78
|
+
}));
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default FieldInputArray;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export default FieldInputLayout;
|
|
2
|
+
declare function FieldInputLayout({ attributes: { isArray, icon, ...attributes }, contacts, formProps }: {
|
|
3
|
+
attributes: {
|
|
4
|
+
[x: string]: any;
|
|
5
|
+
isArray: any;
|
|
6
|
+
icon: any;
|
|
7
|
+
};
|
|
8
|
+
contacts: any;
|
|
9
|
+
formProps: any;
|
|
10
|
+
}): JSX.Element;
|
|
11
|
+
declare namespace FieldInputLayout {
|
|
12
|
+
namespace propTypes {
|
|
13
|
+
const attributes: PropTypes.Requireable<object>;
|
|
14
|
+
const contacts: PropTypes.Requireable<PropTypes.InferProps<{
|
|
15
|
+
data: PropTypes.Requireable<(object | null)[]>;
|
|
16
|
+
}>>;
|
|
17
|
+
const formProps: PropTypes.Requireable<object>;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
import PropTypes from "prop-types";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
var _excluded = ["isArray", "icon"],
|
|
3
|
+
_excluded2 = ["name", "label"];
|
|
4
|
+
import cx from 'classnames';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import FieldInput from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/FieldInput";
|
|
8
|
+
import FieldInputArray from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/FieldInputArray";
|
|
9
|
+
import { fieldsRequired } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/helpers";
|
|
10
|
+
import { locales } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/locales";
|
|
11
|
+
import Icon from "cozy-ui/transpiled/react/Icon";
|
|
12
|
+
import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
|
13
|
+
|
|
14
|
+
var FieldInputLayout = function FieldInputLayout(_ref) {
|
|
15
|
+
var _ref$attributes = _ref.attributes,
|
|
16
|
+
isArray = _ref$attributes.isArray,
|
|
17
|
+
icon = _ref$attributes.icon,
|
|
18
|
+
attributes = _objectWithoutProperties(_ref$attributes, _excluded),
|
|
19
|
+
contacts = _ref.contacts,
|
|
20
|
+
formProps = _ref.formProps;
|
|
21
|
+
|
|
22
|
+
useExtendI18n(locales);
|
|
23
|
+
|
|
24
|
+
var _useI18n = useI18n(),
|
|
25
|
+
t = _useI18n.t;
|
|
26
|
+
|
|
27
|
+
var valid = formProps.valid,
|
|
28
|
+
submitFailed = formProps.submitFailed,
|
|
29
|
+
errors = formProps.errors;
|
|
30
|
+
|
|
31
|
+
var name = attributes.name,
|
|
32
|
+
label = attributes.label,
|
|
33
|
+
restAttributes = _objectWithoutProperties(attributes, _excluded2);
|
|
34
|
+
|
|
35
|
+
var isError = fieldsRequired.includes(name) && !valid && submitFailed;
|
|
36
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
37
|
+
className: cx('u-flex u-mt-1', {
|
|
38
|
+
'u-flex-items-center': !isArray,
|
|
39
|
+
'u-flex-items-baseline': isArray
|
|
40
|
+
})
|
|
41
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
42
|
+
className: "u-w-2-half"
|
|
43
|
+
}, icon && /*#__PURE__*/React.createElement(Icon, {
|
|
44
|
+
icon: icon,
|
|
45
|
+
color: "var(--iconTextColor)"
|
|
46
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
47
|
+
className: "u-w-100"
|
|
48
|
+
}, isArray ? /*#__PURE__*/React.createElement(FieldInputArray, {
|
|
49
|
+
attributes: attributes,
|
|
50
|
+
contacts: contacts,
|
|
51
|
+
formProps: formProps
|
|
52
|
+
}) : /*#__PURE__*/React.createElement(FieldInput, {
|
|
53
|
+
attributes: restAttributes,
|
|
54
|
+
contacts: contacts,
|
|
55
|
+
error: isError,
|
|
56
|
+
helperText: isError ? errors[name] : null,
|
|
57
|
+
name: name,
|
|
58
|
+
label: t("Contacts.AddModal.ContactForm.fields.".concat(name)),
|
|
59
|
+
labelProps: label
|
|
60
|
+
})));
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
FieldInputLayout.propTypes = {
|
|
64
|
+
attributes: PropTypes.object,
|
|
65
|
+
contacts: PropTypes.shape({
|
|
66
|
+
data: PropTypes.arrayOf(PropTypes.object)
|
|
67
|
+
}),
|
|
68
|
+
formProps: PropTypes.object
|
|
69
|
+
};
|
|
70
|
+
export default FieldInputLayout;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default FieldInputWrapper;
|
|
2
|
+
declare function FieldInputWrapper({ input, attributes, variant, fullWidth, ...props }: {
|
|
3
|
+
[x: string]: any;
|
|
4
|
+
input: any;
|
|
5
|
+
attributes: any;
|
|
6
|
+
variant: any;
|
|
7
|
+
fullWidth: any;
|
|
8
|
+
}): JSX.Element;
|
|
9
|
+
declare namespace FieldInputWrapper {
|
|
10
|
+
export { FieldInputWrapperPropTypes as propTypes };
|
|
11
|
+
export namespace defaultProps {
|
|
12
|
+
const variant: string;
|
|
13
|
+
const fullWidth: boolean;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
import { FieldInputWrapperPropTypes } from "../types";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["input", "attributes", "variant", "fullWidth"];
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import TextFieldCustomLabelSelect from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/TextFieldCustomLabelSelect";
|
|
6
|
+
import TextFieldSelect from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect";
|
|
7
|
+
import TextField from "cozy-ui/transpiled/react/TextField";
|
|
8
|
+
import { FieldInputWrapperPropTypes } from "cozy-ui/transpiled/react/Contacts/AddModal/types"; // component used to flatten props to ensure compatibility
|
|
9
|
+
// between Field from react-final-form and TextField from Mui
|
|
10
|
+
|
|
11
|
+
var FieldInputWrapper = function FieldInputWrapper(_ref) {
|
|
12
|
+
var input = _ref.input,
|
|
13
|
+
attributes = _ref.attributes,
|
|
14
|
+
variant = _ref.variant,
|
|
15
|
+
fullWidth = _ref.fullWidth,
|
|
16
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
17
|
+
|
|
18
|
+
var Component = attributes.customLabelOptions ? TextFieldCustomLabelSelect : attributes !== null && attributes !== void 0 && attributes.select ? TextFieldSelect : TextField;
|
|
19
|
+
return /*#__PURE__*/React.createElement(Component, _extends({}, attributes, input, props, {
|
|
20
|
+
variant: variant,
|
|
21
|
+
fullWidth: fullWidth,
|
|
22
|
+
minRows: "2"
|
|
23
|
+
}));
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
FieldInputWrapper.propTypes = FieldInputWrapperPropTypes;
|
|
27
|
+
FieldInputWrapper.defaultProps = {
|
|
28
|
+
variant: 'outlined',
|
|
29
|
+
fullWidth: true
|
|
30
|
+
};
|
|
31
|
+
export default FieldInputWrapper;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default HasValueCondition;
|
|
2
|
+
declare function HasValueCondition({ children, otherCondition, name }: {
|
|
3
|
+
children: any;
|
|
4
|
+
otherCondition: any;
|
|
5
|
+
name: any;
|
|
6
|
+
}): JSX.Element;
|
|
7
|
+
declare namespace HasValueCondition {
|
|
8
|
+
namespace defaultProps {
|
|
9
|
+
const otherCondition: undefined;
|
|
10
|
+
}
|
|
11
|
+
namespace propTypes {
|
|
12
|
+
export const children: PropTypes.Validator<PropTypes.ReactElementLike>;
|
|
13
|
+
export const name: PropTypes.Validator<string>;
|
|
14
|
+
const otherCondition_1: PropTypes.Requireable<boolean>;
|
|
15
|
+
export { otherCondition_1 as otherCondition };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
import PropTypes from "prop-types";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Wrapper for react-final-form field that renders it children only if the field
|
|
3
|
+
with the given name has a truthy value or if the other condition is fulfilled
|
|
4
|
+
*/
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { Field } from 'react-final-form';
|
|
8
|
+
|
|
9
|
+
var HasValueCondition = function HasValueCondition(_ref) {
|
|
10
|
+
var children = _ref.children,
|
|
11
|
+
otherCondition = _ref.otherCondition,
|
|
12
|
+
name = _ref.name;
|
|
13
|
+
return /*#__PURE__*/React.createElement(Field, {
|
|
14
|
+
name: name,
|
|
15
|
+
subscription: {
|
|
16
|
+
value: true
|
|
17
|
+
}
|
|
18
|
+
}, function (_ref2) {
|
|
19
|
+
var value = _ref2.input.value;
|
|
20
|
+
return otherCondition !== undefined && otherCondition || value ? children : null;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
HasValueCondition.defaultProps = {
|
|
25
|
+
otherCondition: undefined
|
|
26
|
+
};
|
|
27
|
+
HasValueCondition.propTypes = {
|
|
28
|
+
children: PropTypes.element.isRequired,
|
|
29
|
+
name: PropTypes.string.isRequired,
|
|
30
|
+
otherCondition: PropTypes.bool
|
|
31
|
+
};
|
|
32
|
+
export default HasValueCondition;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function RelatedContactList({ name, onClose, contacts }: {
|
|
2
|
+
name: any;
|
|
3
|
+
onClose: any;
|
|
4
|
+
contacts: any;
|
|
5
|
+
}): JSX.Element;
|
|
6
|
+
export namespace RelatedContactList {
|
|
7
|
+
namespace propTypes {
|
|
8
|
+
const name: PropTypes.Validator<string>;
|
|
9
|
+
const onClose: PropTypes.Validator<(...args: any[]) => any>;
|
|
10
|
+
const contacts: PropTypes.Validator<PropTypes.InferProps<{
|
|
11
|
+
data: PropTypes.Requireable<(object | null)[]>;
|
|
12
|
+
}>>;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
import PropTypes from "prop-types";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useForm } from 'react-final-form';
|
|
4
|
+
import { makeDisplayName } from 'cozy-client/dist/models/contact';
|
|
5
|
+
import ContactsListModal from "cozy-ui/transpiled/react/ContactsListModal";
|
|
6
|
+
export var RelatedContactList = function RelatedContactList(_ref) {
|
|
7
|
+
var name = _ref.name,
|
|
8
|
+
onClose = _ref.onClose,
|
|
9
|
+
contacts = _ref.contacts;
|
|
10
|
+
|
|
11
|
+
var _useForm = useForm(),
|
|
12
|
+
change = _useForm.change;
|
|
13
|
+
/**
|
|
14
|
+
* @param {import('cozy-client/types/types').IOCozyContact} contact
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var onClickContactsListModal = function onClickContactsListModal(contact) {
|
|
19
|
+
// Use `makeDisplayName` because if the contact is newly created, it has no `displayName` attribute. (Creation of a contact when selecting a linked contact)
|
|
20
|
+
change(name, makeDisplayName(contact));
|
|
21
|
+
change("".concat(name, "Id"), contact._id);
|
|
22
|
+
onClose();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return /*#__PURE__*/React.createElement(ContactsListModal, {
|
|
26
|
+
dismissAction: onClose,
|
|
27
|
+
onItemClick: function onItemClick(contact) {
|
|
28
|
+
return onClickContactsListModal(contact);
|
|
29
|
+
},
|
|
30
|
+
contacts: contacts
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
RelatedContactList.propTypes = {
|
|
34
|
+
name: PropTypes.string.isRequired,
|
|
35
|
+
onClose: PropTypes.func.isRequired,
|
|
36
|
+
contacts: PropTypes.shape({
|
|
37
|
+
data: PropTypes.arrayOf(PropTypes.object)
|
|
38
|
+
}).isRequired
|
|
39
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default TextFieldCustomLabelSelect;
|
|
2
|
+
declare function TextFieldCustomLabelSelect({ name, value, options, customLabelOptions, onChange, ...props }: {
|
|
3
|
+
[x: string]: any;
|
|
4
|
+
name: any;
|
|
5
|
+
value: any;
|
|
6
|
+
options: any;
|
|
7
|
+
customLabelOptions: any;
|
|
8
|
+
onChange: any;
|
|
9
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["name", "value", "options", "customLabelOptions", "onChange"];
|
|
5
|
+
import React, { useState } from 'react';
|
|
6
|
+
import TextFieldSelect from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/TextFieldSelect";
|
|
7
|
+
import { makeCustomLabel, makeInitialCustomValue } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/helpers";
|
|
8
|
+
import { locales } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/locales";
|
|
9
|
+
import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
|
10
|
+
import CustomLabelDialog from "cozy-ui/transpiled/react/Contacts/AddModal/CustomLabelDialog";
|
|
11
|
+
import { FieldInputWrapperPropTypes } from "cozy-ui/transpiled/react/Contacts/AddModal/types";
|
|
12
|
+
|
|
13
|
+
var TextFieldCustomLabelSelect = function TextFieldCustomLabelSelect(_ref) {
|
|
14
|
+
var name = _ref.name,
|
|
15
|
+
value = _ref.value,
|
|
16
|
+
options = _ref.options,
|
|
17
|
+
customLabelOptions = _ref.customLabelOptions,
|
|
18
|
+
_onChange = _ref.onChange,
|
|
19
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
20
|
+
|
|
21
|
+
useExtendI18n(locales);
|
|
22
|
+
|
|
23
|
+
var _useI18n = useI18n(),
|
|
24
|
+
t = _useI18n.t;
|
|
25
|
+
|
|
26
|
+
var _useState = useState(false),
|
|
27
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
28
|
+
openModal = _useState2[0],
|
|
29
|
+
setOpenModal = _useState2[1];
|
|
30
|
+
|
|
31
|
+
var _useState3 = useState(function () {
|
|
32
|
+
return makeInitialCustomValue(name, value);
|
|
33
|
+
}),
|
|
34
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
35
|
+
customValue = _useState4[0],
|
|
36
|
+
setCustomValue = _useState4[1];
|
|
37
|
+
|
|
38
|
+
var customOption = customValue ? [{
|
|
39
|
+
value: customValue,
|
|
40
|
+
label: makeCustomLabel(customValue, t),
|
|
41
|
+
translated: true,
|
|
42
|
+
onClick: function onClick() {
|
|
43
|
+
// trigger modal only if customValue is already selected
|
|
44
|
+
if (value === customValue) {
|
|
45
|
+
return setOpenModal(true);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}] : [{
|
|
49
|
+
value: 'skip',
|
|
50
|
+
label: 'Contacts.AddModal.ContactForm.label.custom',
|
|
51
|
+
onClick: function onClick() {
|
|
52
|
+
return setOpenModal(true);
|
|
53
|
+
}
|
|
54
|
+
}];
|
|
55
|
+
|
|
56
|
+
var _options = options.concat(customOption);
|
|
57
|
+
|
|
58
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TextFieldSelect, _extends({}, props, {
|
|
59
|
+
name: name,
|
|
60
|
+
value: value,
|
|
61
|
+
options: _options,
|
|
62
|
+
onChange: function onChange(ev) {
|
|
63
|
+
if (ev.target.value === 'skip') {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
_onChange(ev);
|
|
68
|
+
}
|
|
69
|
+
})), openModal && /*#__PURE__*/React.createElement(CustomLabelDialog, {
|
|
70
|
+
customValue: customValue,
|
|
71
|
+
customLabelOptions: customLabelOptions,
|
|
72
|
+
setCustomValue: setCustomValue,
|
|
73
|
+
onSubmit: _onChange,
|
|
74
|
+
onClose: function onClose() {
|
|
75
|
+
return setOpenModal(false);
|
|
76
|
+
}
|
|
77
|
+
}));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
TextFieldCustomLabelSelect.prototype = FieldInputWrapperPropTypes;
|
|
81
|
+
export default TextFieldCustomLabelSelect;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["options"];
|
|
5
|
+
|
|
6
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
+
|
|
8
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
9
|
+
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { locales } from "cozy-ui/transpiled/react/Contacts/AddModal/ContactForm/locales";
|
|
12
|
+
import MenuItem from "cozy-ui/transpiled/react/MenuItem";
|
|
13
|
+
import TextField from "cozy-ui/transpiled/react/TextField";
|
|
14
|
+
import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
|
15
|
+
import { FieldInputWrapperPropTypes } from "cozy-ui/transpiled/react/Contacts/AddModal/types";
|
|
16
|
+
|
|
17
|
+
var TextFieldSelect = function TextFieldSelect(_ref) {
|
|
18
|
+
var options = _ref.options,
|
|
19
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
20
|
+
|
|
21
|
+
useExtendI18n(locales);
|
|
22
|
+
|
|
23
|
+
var _useI18n = useI18n(),
|
|
24
|
+
t = _useI18n.t;
|
|
25
|
+
|
|
26
|
+
var _options = _toConsumableArray(options.map(function (option) {
|
|
27
|
+
return _objectSpread(_objectSpread({}, option), {}, {
|
|
28
|
+
label: option.translated ? option.label : t(option.label)
|
|
29
|
+
});
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
return /*#__PURE__*/React.createElement(TextField, props, _options.map(function (option, index) {
|
|
33
|
+
return /*#__PURE__*/React.createElement(MenuItem, {
|
|
34
|
+
key: "".concat(props.name, "-").concat(index),
|
|
35
|
+
value: option.value,
|
|
36
|
+
onClick: option.onClick
|
|
37
|
+
}, option.label);
|
|
38
|
+
}));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
TextFieldSelect.prototype = FieldInputWrapperPropTypes;
|
|
42
|
+
export default TextFieldSelect;
|