@licklist/design 0.69.4 → 0.69.5
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/events/edit-event-modal/component/EditEventForm/EditEventForm.d.ts +2 -1
- package/dist/events/edit-event-modal/component/EditEventForm/EditEventForm.d.ts.map +1 -1
- package/dist/events/edit-event-modal/component/EditEventForm/EditEventForm.js +3 -2
- package/dist/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.d.ts +2 -1
- package/dist/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.d.ts.map +1 -1
- package/dist/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.js +31 -28
- package/dist/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.d.ts +2 -1
- package/dist/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.d.ts.map +1 -1
- package/dist/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.js +14 -3
- package/dist/index.js +1 -0
- package/dist/modals/confirmation/ConfirmModal.d.ts +3 -1
- package/dist/modals/confirmation/ConfirmModal.d.ts.map +1 -1
- package/dist/modals/confirmation/ConfirmModal.js +172 -8
- package/dist/product-set/card/ProductSetCard.d.ts +6 -2
- package/dist/product-set/card/ProductSetCard.d.ts.map +1 -1
- package/dist/product-set/card/ProductSetCard.js +20 -11
- package/dist/product-set/form/ProductSetForm.d.ts.map +1 -1
- package/dist/product-set/form/ProductSetForm.js +8 -0
- package/dist/product-set/form/ProductSetNameControl.d.ts +6 -0
- package/dist/product-set/form/ProductSetNameControl.d.ts.map +1 -0
- package/dist/product-set/form/ProductSetNameControl.js +35 -0
- package/dist/product-set/form/index.d.ts +1 -0
- package/dist/product-set/form/index.d.ts.map +1 -1
- package/dist/product-set/utils/index.d.ts +7 -0
- package/dist/product-set/utils/index.d.ts.map +1 -1
- package/dist/product-set/utils/index.js +10 -1
- package/dist/typeahead/Typeahead.d.ts +5 -1
- package/dist/typeahead/Typeahead.d.ts.map +1 -1
- package/dist/typeahead/Typeahead.js +9 -2
- package/package.json +4 -4
- package/src/events/edit-event-modal/component/EditEventForm/EditEventForm.tsx +3 -0
- package/src/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.tsx +86 -85
- package/src/events/edit-event-modal/component/SelectEventProductSet/component/EditEventProductSet.tsx +11 -1
- package/src/modals/confirmation/ConfirmModal.tsx +19 -3
- package/src/product-set/card/ProductSetCard.tsx +32 -6
- package/src/product-set/form/ProductSetForm.tsx +10 -0
- package/src/product-set/form/ProductSetNameControl.tsx +27 -0
- package/src/product-set/form/index.ts +1 -0
- package/src/product-set/utils/index.ts +11 -0
- package/src/typeahead/Typeahead.tsx +15 -1
- package/yarn.lock +6 -14
|
@@ -5,6 +5,7 @@ import { useForm, FormProvider } from 'react-hook-form';
|
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
import FormErrorService from '@licklist/plugins/dist/services/Form/FormErrorService';
|
|
7
7
|
import { isEqual } from 'lodash';
|
|
8
|
+
import { transformErrorToMessage } from '@licklist/plugins';
|
|
8
9
|
import { Dialog } from '../../modals/dialog/Dialog.js';
|
|
9
10
|
import { useDialogContext } from '../../modals/dialog/DialogContext.js';
|
|
10
11
|
import { ProductSetControl } from '../control/ProductSetControl.js';
|
|
@@ -142,6 +143,13 @@ function ProductSetForm(_param) {
|
|
|
142
143
|
if (!serverErrors) {
|
|
143
144
|
return;
|
|
144
145
|
}
|
|
146
|
+
if (!Array.isArray(serverErrors)) {
|
|
147
|
+
setErrorMessage(transformErrorToMessage(serverErrors));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (Array.isArray(serverErrors) && serverErrors[0]) {
|
|
151
|
+
setErrorMessage(serverErrors[0]);
|
|
152
|
+
}
|
|
145
153
|
FormErrorService.handleServerErrors(serverErrors, setError);
|
|
146
154
|
}, [
|
|
147
155
|
serverErrors,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProductSetNameControl.d.ts","sourceRoot":"","sources":["../../../src/product-set/form/ProductSetNameControl.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,gCAI/B;IACD,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,4CAeA,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Form } from 'react-bootstrap';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
|
|
5
|
+
var ProductSetNameControl = function(param) {
|
|
6
|
+
var value = param.value, onChange = param.onChange, error = param.error;
|
|
7
|
+
var t = useTranslation([
|
|
8
|
+
'Design'
|
|
9
|
+
]).t;
|
|
10
|
+
return /*#__PURE__*/ jsxs(Form.Group, {
|
|
11
|
+
children: [
|
|
12
|
+
/*#__PURE__*/ jsxs(Form.Label, {
|
|
13
|
+
children: [
|
|
14
|
+
t('Design:ProductSetName'),
|
|
15
|
+
"*"
|
|
16
|
+
]
|
|
17
|
+
}),
|
|
18
|
+
/*#__PURE__*/ jsx(Form.Control, {
|
|
19
|
+
value: value,
|
|
20
|
+
maxLength: 255,
|
|
21
|
+
onChange: function(e) {
|
|
22
|
+
return onChange(e.target.value);
|
|
23
|
+
},
|
|
24
|
+
placeholder: t('Design:placeholderProductSetName'),
|
|
25
|
+
isInvalid: Boolean(error)
|
|
26
|
+
}),
|
|
27
|
+
/*#__PURE__*/ jsx(Form.Control.Feedback, {
|
|
28
|
+
type: "invalid",
|
|
29
|
+
children: error
|
|
30
|
+
})
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { ProductSetNameControl };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/product-set/form/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/product-set/form/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA"}
|
|
@@ -2,6 +2,7 @@ import { EmailTemplate } from '@licklist/core/dist/DataMapper/Notification/Email
|
|
|
2
2
|
import { SmsTemplate } from '@licklist/core/dist/DataMapper/Notification/SmsTemplateDataMapper';
|
|
3
3
|
import { TFunction } from 'react-i18next';
|
|
4
4
|
import { UseFormSetError } from 'react-hook-form';
|
|
5
|
+
import { ProductSet } from '@licklist/core/dist/DataMapper/Product/ProductSetDataMapper';
|
|
5
6
|
import { TemplateItem } from '../control/ProductSetControl';
|
|
6
7
|
import { ProductSetFormValues } from '../form/ProductSetForm';
|
|
7
8
|
interface CheckAvailableTimesErrors {
|
|
@@ -9,11 +10,17 @@ interface CheckAvailableTimesErrors {
|
|
|
9
10
|
setError: UseFormSetError<ProductSetFormValues>;
|
|
10
11
|
t: TFunction;
|
|
11
12
|
}
|
|
13
|
+
export interface MenuTypeheadItem {
|
|
14
|
+
id: number;
|
|
15
|
+
label: string;
|
|
16
|
+
value: number;
|
|
17
|
+
}
|
|
12
18
|
export declare const moveArrayElements: <T>(array: T[], prevIndex: number, nextIndex: number) => T[];
|
|
13
19
|
export declare const sortArrayByIndex: <T>(array: T[]) => (T & {
|
|
14
20
|
sort: number;
|
|
15
21
|
})[];
|
|
16
22
|
export declare const getFilteredTemplates: (templates?: EmailTemplate[] | SmsTemplate[], formTemplates?: TemplateItem[]) => TemplateItem[] | undefined;
|
|
17
23
|
export declare const checkAvailableTimesErrors: ({ values, setError, t, }: CheckAvailableTimesErrors) => boolean;
|
|
24
|
+
export declare const getTypeHeadItemsFromMenus: (menus?: (ProductSet | ProductSetFormValues)[]) => MenuTypeheadItem[];
|
|
18
25
|
export {};
|
|
19
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/product-set/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AACnG,OAAO,EAAE,WAAW,EAAE,MAAM,mEAAmE,CAAA;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAE7D,UAAU,yBAAyB;IACjC,MAAM,EAAE,oBAAoB,CAAA;IAC5B,QAAQ,EAAE,eAAe,CAAC,oBAAoB,CAAC,CAAA;IAC/C,CAAC,EAAE,SAAS,CAAA;CACb;AAED,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAC1B,CAAC,EAAE,aACC,MAAM,aACN,MAAM,QAQlB,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,CAAC,EAAE;;IACmB,CAAA;AAEjE,eAAO,MAAM,oBAAoB,eACnB,aAAa,EAAE,GAAG,WAAW,EAAE,kBAC3B,YAAY,EAAE,KAC7B,YAAY,EAAE,GAAG,SAmBnB,CAAA;AAED,eAAO,MAAM,yBAAyB,6BAInC,yBAAyB,YA0B3B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/product-set/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AACnG,OAAO,EAAE,WAAW,EAAE,MAAM,mEAAmE,CAAA;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,6DAA6D,CAAA;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAE7D,UAAU,yBAAyB;IACjC,MAAM,EAAE,oBAAoB,CAAA;IAC5B,QAAQ,EAAE,eAAe,CAAC,oBAAoB,CAAC,CAAA;IAC/C,CAAC,EAAE,SAAS,CAAA;CACb;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd;AACD,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAC1B,CAAC,EAAE,aACC,MAAM,aACN,MAAM,QAQlB,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,CAAC,EAAE;;IACmB,CAAA;AAEjE,eAAO,MAAM,oBAAoB,eACnB,aAAa,EAAE,GAAG,WAAW,EAAE,kBAC3B,YAAY,EAAE,KAC7B,YAAY,EAAE,GAAG,SAmBnB,CAAA;AAED,eAAO,MAAM,yBAAyB,6BAInC,yBAAyB,YA0B3B,CAAA;AAED,eAAO,MAAM,yBAAyB,WAC5B,CAAC,UAAU,GAAG,oBAAoB,CAAC,EAAE,KAC5C,gBAAgB,EACwD,CAAA"}
|
|
@@ -136,5 +136,14 @@ var checkAvailableTimesErrors = function(param) {
|
|
|
136
136
|
});
|
|
137
137
|
return hasError;
|
|
138
138
|
};
|
|
139
|
+
var getTypeHeadItemsFromMenus = function(menus) {
|
|
140
|
+
return menus === null || menus === void 0 ? void 0 : menus.map(function(menu) {
|
|
141
|
+
return {
|
|
142
|
+
id: menu.id,
|
|
143
|
+
value: menu.id,
|
|
144
|
+
label: menu.name
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
};
|
|
139
148
|
|
|
140
|
-
export { checkAvailableTimesErrors, getFilteredTemplates, moveArrayElements, sortArrayByIndex };
|
|
149
|
+
export { checkAvailableTimesErrors, getFilteredTemplates, getTypeHeadItemsFromMenus, moveArrayElements, sortArrayByIndex };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CSSObjectWithLabel } from 'react-select';
|
|
1
2
|
export type TypeaheadOptions = {
|
|
2
3
|
id: number | string;
|
|
3
4
|
value: any;
|
|
@@ -8,11 +9,14 @@ export interface TypeaheadProps {
|
|
|
8
9
|
placeholder: string;
|
|
9
10
|
isRequired?: boolean;
|
|
10
11
|
name: string;
|
|
12
|
+
value?: TypeaheadOptions;
|
|
11
13
|
isMultipleChoise?: boolean;
|
|
12
14
|
noOptionsMessage: string;
|
|
13
15
|
isInvalid?: boolean;
|
|
14
16
|
isCouponForm?: boolean;
|
|
17
|
+
containerStyles?: CSSObjectWithLabel;
|
|
18
|
+
onChangeValue?: (value: TypeaheadOptions) => void;
|
|
15
19
|
}
|
|
16
|
-
declare function Typeahead({ options, placeholder, isRequired, isMultipleChoise, name, isCouponForm, noOptionsMessage, isInvalid, }: TypeaheadProps): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
declare function Typeahead({ options, placeholder, isRequired, isMultipleChoise, name, value, onChangeValue, containerStyles, isCouponForm, noOptionsMessage, isInvalid, }: TypeaheadProps): import("react/jsx-runtime").JSX.Element;
|
|
17
21
|
export { Typeahead };
|
|
18
22
|
//# sourceMappingURL=Typeahead.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Typeahead.d.ts","sourceRoot":"","sources":["../../src/typeahead/Typeahead.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Typeahead.d.ts","sourceRoot":"","sources":["../../src/typeahead/Typeahead.tsx"],"names":[],"mappings":"AAAA,OAAe,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAGzD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,KAAK,EAAE,GAAG,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,gBAAgB,EAAE,CAAA;IAC3B,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,gBAAgB,CAAA;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,gBAAgB,EAAE,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,eAAe,CAAC,EAAE,kBAAkB,CAAA;IACpC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAA;CAClD;AAED,iBAAS,SAAS,CAAC,EACjB,OAAO,EACP,WAAW,EACX,UAAkB,EAClB,gBAAgB,EAChB,IAAS,EACT,KAAK,EACL,aAAa,EACb,eAAe,EACf,YAAoB,EACpB,gBAAqB,EACrB,SAAS,GACV,EAAE,cAAc,2CAoDhB;AAED,OAAO,EAAE,SAAS,EAAE,CAAA"}
|
|
@@ -31,7 +31,7 @@ function _object_spread(target) {
|
|
|
31
31
|
return target;
|
|
32
32
|
}
|
|
33
33
|
function Typeahead(param) {
|
|
34
|
-
var options = param.options, placeholder = param.placeholder, _param_isRequired = param.isRequired, isRequired = _param_isRequired === void 0 ? false : _param_isRequired, isMultipleChoise = param.isMultipleChoise, _param_name = param.name, name = _param_name === void 0 ? '' : _param_name, _param_isCouponForm = param.isCouponForm, isCouponForm = _param_isCouponForm === void 0 ? false : _param_isCouponForm, _param_noOptionsMessage = param.noOptionsMessage, noOptionsMessage = _param_noOptionsMessage === void 0 ? '' : _param_noOptionsMessage, isInvalid = param.isInvalid;
|
|
34
|
+
var options = param.options, placeholder = param.placeholder, _param_isRequired = param.isRequired, isRequired = _param_isRequired === void 0 ? false : _param_isRequired, isMultipleChoise = param.isMultipleChoise, _param_name = param.name, name = _param_name === void 0 ? '' : _param_name, value = param.value, onChangeValue = param.onChangeValue, containerStyles = param.containerStyles, _param_isCouponForm = param.isCouponForm, isCouponForm = _param_isCouponForm === void 0 ? false : _param_isCouponForm, _param_noOptionsMessage = param.noOptionsMessage, noOptionsMessage = _param_noOptionsMessage === void 0 ? '' : _param_noOptionsMessage, isInvalid = param.isInvalid;
|
|
35
35
|
var control = useFormContext().control;
|
|
36
36
|
var getStyle = function() {
|
|
37
37
|
var couponFormStyle = isCouponForm ? {
|
|
@@ -53,14 +53,21 @@ function Typeahead(param) {
|
|
|
53
53
|
var field = param.field;
|
|
54
54
|
return /*#__PURE__*/ jsx(Select, {
|
|
55
55
|
placeholder: placeholder,
|
|
56
|
-
value: field.value,
|
|
56
|
+
value: value !== null && value !== void 0 ? value : field.value,
|
|
57
57
|
isMulti: isMultipleChoise,
|
|
58
58
|
styles: {
|
|
59
|
+
container: function(base) {
|
|
60
|
+
return _object_spread({}, base, containerStyles);
|
|
61
|
+
},
|
|
59
62
|
control: function(base) {
|
|
60
63
|
return _object_spread({}, base, getStyle());
|
|
61
64
|
}
|
|
62
65
|
},
|
|
63
66
|
onChange: function(value) {
|
|
67
|
+
if (onChangeValue) {
|
|
68
|
+
onChangeValue(value);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
64
71
|
field.onChange(value);
|
|
65
72
|
},
|
|
66
73
|
options: options,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@licklist/design",
|
|
3
|
-
"version": "0.69.
|
|
3
|
+
"version": "0.69.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+ssh://git@bitbucket.org/artelogicsoft/licklist_design.git"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@licklist/core": "0.30.3",
|
|
46
46
|
"@licklist/eslint-config": "0.5.6",
|
|
47
|
-
"@licklist/plugins": "0.33.
|
|
47
|
+
"@licklist/plugins": "0.33.4",
|
|
48
48
|
"lodash": "4.17.21",
|
|
49
49
|
"luxon": "3.5.0",
|
|
50
50
|
"react": "17.0.2",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@fortawesome/free-solid-svg-icons": "5.15.2",
|
|
64
64
|
"@licklist/core": "0.30.3",
|
|
65
65
|
"@licklist/eslint-config": "0.5.6",
|
|
66
|
-
"@licklist/plugins": "0.33.
|
|
66
|
+
"@licklist/plugins": "0.33.4",
|
|
67
67
|
"@mantine/core": "6.0.22",
|
|
68
68
|
"@mantine/hooks": "6.0.22",
|
|
69
69
|
"@mdx-js/react": "1.6.22",
|
|
@@ -206,4 +206,4 @@
|
|
|
206
206
|
"node": "20.9.0",
|
|
207
207
|
"yarn": "4.4.0"
|
|
208
208
|
}
|
|
209
|
-
}
|
|
209
|
+
}
|
|
@@ -64,6 +64,7 @@ export interface EditEventFormProps extends HasPermissionProp {
|
|
|
64
64
|
isExternalPaymentLinkEnabled?: boolean
|
|
65
65
|
timeZone: string
|
|
66
66
|
eventProductSet?: ProductSet
|
|
67
|
+
overrideNameError?: string
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
const eventImageTypes = {
|
|
@@ -85,6 +86,7 @@ export const EditEventForm = ({
|
|
|
85
86
|
isExternalPaymentLinkEnabled,
|
|
86
87
|
timeZone,
|
|
87
88
|
eventProductSet,
|
|
89
|
+
overrideNameError,
|
|
88
90
|
}: EditEventFormProps) => {
|
|
89
91
|
const { t } = useTranslation(['Design', 'Validation'])
|
|
90
92
|
|
|
@@ -406,6 +408,7 @@ export const EditEventForm = ({
|
|
|
406
408
|
showEditProductSet={showEditProductSet}
|
|
407
409
|
timeZone={timeZone}
|
|
408
410
|
eventProductSet={eventProductSet}
|
|
411
|
+
overrideNameError={overrideNameError}
|
|
409
412
|
/>
|
|
410
413
|
|
|
411
414
|
{hasPermission && !showEditProductSet && (
|
package/src/events/edit-event-modal/component/SelectEventProductSet/SelectEventProductSet.tsx
CHANGED
|
@@ -5,9 +5,11 @@ import { useId } from '@react-aria/utils'
|
|
|
5
5
|
import { Controller, useFormContext } from 'react-hook-form'
|
|
6
6
|
import { HasPermissionProp } from '@licklist/plugins/dist/types/permission/Permission'
|
|
7
7
|
import { ProductSet } from '@licklist/core/dist/DataMapper/Product/ProductSetDataMapper'
|
|
8
|
+
import { getTypeHeadItemsFromMenus } from '../../../../product-set/utils'
|
|
8
9
|
import { ConfirmModal } from '../../../../modals/confirmation/ConfirmModal'
|
|
9
10
|
import { EditEventFormValues } from '../EditEventForm/EditEventForm'
|
|
10
11
|
import { EditEventProductSet } from './component/EditEventProductSet'
|
|
12
|
+
import { Typeahead } from '../../../../typeahead'
|
|
11
13
|
|
|
12
14
|
interface SelectEventProductSetProps extends HasPermissionProp {
|
|
13
15
|
productSets?: ProductSet[]
|
|
@@ -17,6 +19,7 @@ interface SelectEventProductSetProps extends HasPermissionProp {
|
|
|
17
19
|
setEditProductSetId: (value: string) => void
|
|
18
20
|
timeZone: string
|
|
19
21
|
eventProductSet?: ProductSet
|
|
22
|
+
overrideNameError?: string
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
export const SelectEventProductSet = ({
|
|
@@ -27,6 +30,7 @@ export const SelectEventProductSet = ({
|
|
|
27
30
|
setShowEditProductSet,
|
|
28
31
|
timeZone,
|
|
29
32
|
eventProductSet,
|
|
33
|
+
overrideNameError,
|
|
30
34
|
}: SelectEventProductSetProps) => {
|
|
31
35
|
const productSets = eventProductSet
|
|
32
36
|
? [..._productSets, eventProductSet]
|
|
@@ -48,6 +52,21 @@ export const SelectEventProductSet = ({
|
|
|
48
52
|
const productSetId = watch('productSetId')
|
|
49
53
|
const editedProductSet = watch('editedProductSet')
|
|
50
54
|
|
|
55
|
+
const typeheadValues = getTypeHeadItemsFromMenus(
|
|
56
|
+
editedProductSet
|
|
57
|
+
? productSets.map((productSet) => {
|
|
58
|
+
if (productSet.id === editedProductSet.id) {
|
|
59
|
+
return editedProductSet
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return productSet
|
|
63
|
+
})
|
|
64
|
+
: productSets,
|
|
65
|
+
)
|
|
66
|
+
const selectedProductSetTypeheadValue = productSetId
|
|
67
|
+
? typeheadValues?.find((typeheadValue) => typeheadValue.id === productSetId)
|
|
68
|
+
: undefined
|
|
69
|
+
|
|
51
70
|
const onEditProductSet = useCallback(
|
|
52
71
|
() => {
|
|
53
72
|
setEditProductSetId(String(productSetId))
|
|
@@ -101,6 +120,7 @@ export const SelectEventProductSet = ({
|
|
|
101
120
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
121
|
const onSubmit = (value: EditEventFormValues['editedProductSet']) => {
|
|
103
122
|
setShowEditProductSet(false)
|
|
123
|
+
setValue('productSetId', value.id)
|
|
104
124
|
setValue('editedProductSet', value)
|
|
105
125
|
}
|
|
106
126
|
|
|
@@ -116,93 +136,73 @@ export const SelectEventProductSet = ({
|
|
|
116
136
|
<Controller
|
|
117
137
|
control={control}
|
|
118
138
|
name='productSetId'
|
|
119
|
-
render={(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
)}
|
|
179
|
-
{showEditProductSet && (
|
|
180
|
-
<Button
|
|
181
|
-
variant=''
|
|
182
|
-
className='btn product-set-button'
|
|
183
|
-
onClick={revertEditProductSet}
|
|
184
|
-
>
|
|
185
|
-
{t('cancelAndRevert')}
|
|
186
|
-
</Button>
|
|
187
|
-
)}
|
|
188
|
-
{!showEditProductSet && editedProductSet && (
|
|
189
|
-
<Button
|
|
190
|
-
variant=''
|
|
191
|
-
className='btn product-set-button ml-4 text-danger'
|
|
192
|
-
onClick={revertEditProductSet}
|
|
193
|
-
>
|
|
194
|
-
{t('undoChanges')}
|
|
195
|
-
</Button>
|
|
196
|
-
)}
|
|
197
|
-
</div>
|
|
139
|
+
render={() => (
|
|
140
|
+
<>
|
|
141
|
+
<div className='d-flex align-items-center flex-row w-100'>
|
|
142
|
+
<ConfirmModal>
|
|
143
|
+
{(confirm) => (
|
|
144
|
+
<Typeahead
|
|
145
|
+
name='productSetId'
|
|
146
|
+
value={selectedProductSetTypeheadValue}
|
|
147
|
+
containerStyles={{ width: '100%' }}
|
|
148
|
+
onChangeValue={(typeheadValue) => {
|
|
149
|
+
onChangeProductSet(Number(typeheadValue.id), confirm)
|
|
150
|
+
}}
|
|
151
|
+
isInvalid={!!overrideNameError}
|
|
152
|
+
options={typeheadValues}
|
|
153
|
+
placeholder={t('Design:choose')}
|
|
154
|
+
noOptionsMessage={t('Design:noAvailableProductSets')}
|
|
155
|
+
/>
|
|
156
|
+
)}
|
|
157
|
+
</ConfirmModal>
|
|
158
|
+
|
|
159
|
+
<div className='buttons-container'>
|
|
160
|
+
{!showEditProductSet && !editedProductSet && (
|
|
161
|
+
<Button
|
|
162
|
+
variant=''
|
|
163
|
+
className='btn product-set-button mr-4'
|
|
164
|
+
onClick={handleCreateProductSet}
|
|
165
|
+
>
|
|
166
|
+
{t('addNewProductSet')}
|
|
167
|
+
</Button>
|
|
168
|
+
)}
|
|
169
|
+
{showOverrideProductSet && (
|
|
170
|
+
<Button
|
|
171
|
+
variant=''
|
|
172
|
+
className='btn product-set-button'
|
|
173
|
+
onClick={onEditProductSet}
|
|
174
|
+
>
|
|
175
|
+
{isOverrideProductSet
|
|
176
|
+
? t('editOverrides')
|
|
177
|
+
: t('editProductSet')}
|
|
178
|
+
</Button>
|
|
179
|
+
)}
|
|
180
|
+
{showEditProductSet && (
|
|
181
|
+
<Button
|
|
182
|
+
variant=''
|
|
183
|
+
className='btn product-set-button'
|
|
184
|
+
onClick={revertEditProductSet}
|
|
185
|
+
>
|
|
186
|
+
{t('cancelAndRevert')}
|
|
187
|
+
</Button>
|
|
188
|
+
)}
|
|
189
|
+
{!showEditProductSet && editedProductSet && (
|
|
190
|
+
<Button
|
|
191
|
+
variant=''
|
|
192
|
+
className='btn product-set-button ml-4 text-danger'
|
|
193
|
+
onClick={revertEditProductSet}
|
|
194
|
+
>
|
|
195
|
+
{t('undoChanges')}
|
|
196
|
+
</Button>
|
|
197
|
+
)}
|
|
198
198
|
</div>
|
|
199
|
+
</div>
|
|
199
200
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}}
|
|
201
|
+
<div className='manual-form-error'>
|
|
202
|
+
{errors?.productSetId?.message || overrideNameError}
|
|
203
|
+
</div>
|
|
204
|
+
</>
|
|
205
|
+
)}
|
|
206
206
|
/>
|
|
207
207
|
</Form.Group>
|
|
208
208
|
</div>
|
|
@@ -213,6 +213,7 @@ export const SelectEventProductSet = ({
|
|
|
213
213
|
productSetId === editedProductSet?.id && editedProductSet
|
|
214
214
|
}
|
|
215
215
|
timeZone={timeZone}
|
|
216
|
+
overrideNameError={overrideNameError}
|
|
216
217
|
/>
|
|
217
218
|
)}
|
|
218
219
|
</>
|
|
@@ -23,12 +23,14 @@ interface EditEventProductSetProps {
|
|
|
23
23
|
onSubmit: (value: EditEventFormValues['editedProductSet']) => void
|
|
24
24
|
defaultValues?: EditEventFormValues['editedProductSet']
|
|
25
25
|
timeZone: string
|
|
26
|
+
overrideNameError?: string
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export const EditEventProductSet = ({
|
|
29
30
|
onSubmit,
|
|
30
31
|
defaultValues,
|
|
31
32
|
timeZone,
|
|
33
|
+
overrideNameError,
|
|
32
34
|
}: EditEventProductSetProps) => {
|
|
33
35
|
const { companyId } = useParams<{
|
|
34
36
|
companyId: string
|
|
@@ -64,7 +66,15 @@ export const EditEventProductSet = ({
|
|
|
64
66
|
mode: 'onChange',
|
|
65
67
|
})
|
|
66
68
|
|
|
67
|
-
const { reset, handleSubmit, watch } = form
|
|
69
|
+
const { reset, handleSubmit, watch, setError } = form
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (!overrideNameError) {
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
setError('name', { message: overrideNameError })
|
|
76
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
|
+
}, [overrideNameError])
|
|
68
78
|
|
|
69
79
|
const formValues = watch()
|
|
70
80
|
|
|
@@ -20,6 +20,9 @@ export type ConfirmModalTypes =
|
|
|
20
20
|
export interface ConfirmModalProps {
|
|
21
21
|
type?: ConfirmModalTypes
|
|
22
22
|
children?: (confirm: (action: ConfirmAction) => void) => ReactNode
|
|
23
|
+
// confirm function memoize the callback function. It's an alternative function
|
|
24
|
+
confirmationHandler?: () => Promise<boolean | undefined>
|
|
25
|
+
disabledButtons?: boolean
|
|
23
26
|
title?: string
|
|
24
27
|
content?: string | ReactNode
|
|
25
28
|
onClose?: () => void
|
|
@@ -37,7 +40,9 @@ export function ConfirmModal({
|
|
|
37
40
|
type = 'default',
|
|
38
41
|
children,
|
|
39
42
|
onClose,
|
|
43
|
+
confirmationHandler,
|
|
40
44
|
title,
|
|
45
|
+
disabledButtons,
|
|
41
46
|
content,
|
|
42
47
|
hideButtons = false,
|
|
43
48
|
}: ConfirmModalProps) {
|
|
@@ -52,10 +57,16 @@ export function ConfirmModal({
|
|
|
52
57
|
setIsOpen(() => true)
|
|
53
58
|
}
|
|
54
59
|
|
|
55
|
-
const handleConfirmation = (e) => {
|
|
60
|
+
const handleConfirmation = async (e) => {
|
|
56
61
|
e.stopPropagation()
|
|
57
|
-
if (!actionRef.current) return
|
|
58
|
-
|
|
62
|
+
if (!actionRef.current && !confirmationHandler) return
|
|
63
|
+
if (confirmationHandler) {
|
|
64
|
+
const res = await confirmationHandler()
|
|
65
|
+
if (res) {
|
|
66
|
+
setIsOpen(() => false)
|
|
67
|
+
}
|
|
68
|
+
return
|
|
69
|
+
}
|
|
59
70
|
actionRef.current()
|
|
60
71
|
setIsOpen(() => false)
|
|
61
72
|
}
|
|
@@ -88,6 +99,7 @@ export function ConfirmModal({
|
|
|
88
99
|
<Button
|
|
89
100
|
variant='danger'
|
|
90
101
|
className='btn-sm rounded'
|
|
102
|
+
disabled={disabledButtons}
|
|
91
103
|
onClick={handleClose}
|
|
92
104
|
data-id={CONFIRM_MODAL_ACTION_DECLINE}
|
|
93
105
|
>
|
|
@@ -105,12 +117,14 @@ export function ConfirmModal({
|
|
|
105
117
|
variant='outline'
|
|
106
118
|
className='cancel-button'
|
|
107
119
|
onClick={handleClose}
|
|
120
|
+
disabled={disabledButtons}
|
|
108
121
|
data-id={CONFIRM_MODAL_ACTION_DECLINE}
|
|
109
122
|
>
|
|
110
123
|
{t('cancel')}
|
|
111
124
|
</Button>
|
|
112
125
|
<Button
|
|
113
126
|
variant='danger'
|
|
127
|
+
disabled={disabledButtons}
|
|
114
128
|
onClick={handleConfirmation}
|
|
115
129
|
data-id={CONFIRM_MODAL_ACTION_CONFIRM}
|
|
116
130
|
>
|
|
@@ -121,6 +135,7 @@ export function ConfirmModal({
|
|
|
121
135
|
<>
|
|
122
136
|
<Button
|
|
123
137
|
variant='danger'
|
|
138
|
+
disabled={disabledButtons}
|
|
124
139
|
onClick={handleClose}
|
|
125
140
|
data-id={CONFIRM_MODAL_ACTION_DECLINE}
|
|
126
141
|
>
|
|
@@ -128,6 +143,7 @@ export function ConfirmModal({
|
|
|
128
143
|
</Button>
|
|
129
144
|
<Button
|
|
130
145
|
variant='success'
|
|
146
|
+
disabled={disabledButtons}
|
|
131
147
|
onClick={handleConfirmation}
|
|
132
148
|
data-id={CONFIRM_MODAL_ACTION_CONFIRM}
|
|
133
149
|
>
|