@licklist/design 0.71.18-dev.4 → 0.71.18-dev.6

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.
Files changed (25) hide show
  1. package/dist/iframe/ProductWithModifierModal/ModifierSetModal/ProductWithModifierSetForm.js +3 -3
  2. package/dist/iframe/ProductWithModifierModal/ModifierSetModal/controll/ModifierSetControll.d.ts +1 -3
  3. package/dist/iframe/ProductWithModifierModal/ModifierSetModal/controll/ModifierSetControll.d.ts.map +1 -1
  4. package/dist/iframe/ProductWithModifierModal/ModifierSetModal/controll/ModifierSetControll.js +171 -219
  5. package/dist/iframe/ProductWithModifierModal/ModifierSetModal/controll/ProductControll.d.ts +1 -3
  6. package/dist/iframe/ProductWithModifierModal/ModifierSetModal/controll/ProductControll.d.ts.map +1 -1
  7. package/dist/iframe/ProductWithModifierModal/ModifierSetModal/controll/ProductControll.js +77 -35
  8. package/dist/iframe/ProductWithModifierModal/utils.d.ts +5 -0
  9. package/dist/iframe/ProductWithModifierModal/utils.d.ts.map +1 -0
  10. package/dist/iframe/ProductWithModifierModal/utils.js +19 -0
  11. package/dist/product-set/form/ProductsControl.d.ts.map +1 -1
  12. package/dist/product-set/form/ProductsControl.js +10 -3
  13. package/dist/styles/product-set/EditProductSetElement.scss +1 -0
  14. package/dist/styles/product-set/ProductSetForm.scss +1 -0
  15. package/dist/styles/themes/bookedit/index.scss +5 -0
  16. package/package.json +3 -3
  17. package/src/iframe/ProductWithModifierModal/ModifierSetModal/ProductWithModifierSetForm.tsx +3 -3
  18. package/src/iframe/ProductWithModifierModal/ModifierSetModal/controll/ModifierSetControll.tsx +47 -131
  19. package/src/iframe/ProductWithModifierModal/ModifierSetModal/controll/ProductControll.tsx +76 -35
  20. package/src/iframe/ProductWithModifierModal/utils.ts +28 -0
  21. package/src/product-set/form/ProductsControl.tsx +13 -4
  22. package/src/styles/product-set/EditProductSetElement.scss +1 -0
  23. package/src/styles/product-set/ProductSetForm.scss +1 -0
  24. package/src/styles/themes/bookedit/index.scss +5 -0
  25. package/yarn.lock +60 -32
@@ -1,44 +1,86 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { useEffect } from 'react';
2
3
  import { useFormContext, Controller } from 'react-hook-form';
4
+ import { useTranslation } from 'react-i18next';
3
5
  import { ModifiersSetControl } from './ModifierSetControll.js';
6
+ import { orderProductModifiersQuantity } from '../../utils.js';
4
7
 
5
8
  var ProductControl = function(param) {
6
- var product = param.product, _param_isLoading = param.isLoading, isLoading = _param_isLoading === void 0 ? false : _param_isLoading, editOrderModifier = param.editOrderModifier, errors = param.errors;
7
- var control = useFormContext().control;
9
+ var product = param.product, _param_isLoading = param.isLoading, isLoading = _param_isLoading === void 0 ? false : _param_isLoading, editOrderModifier = param.editOrderModifier;
10
+ var t = useTranslation() // Added translation hook
11
+ .t;
12
+ var _useFormContext = useFormContext(), control = _useFormContext.control, watch = _useFormContext.watch, isValid = _useFormContext.formState.isValid, clearErrors = _useFormContext.clearErrors;
8
13
  var modifiersSet = (product === null || product === void 0 ? void 0 : product.modifiersSet) || [];
9
- return /*#__PURE__*/ jsx(Controller, {
10
- control: control,
11
- name: "product",
12
- render: function() {
13
- return /*#__PURE__*/ jsx("div", {
14
- className: "mb-8 pt-4",
15
- children: /*#__PURE__*/ jsx("div", {
16
- className: " d-flex flex-column",
17
- children: modifiersSet.map(function(modifierSet) {
18
- return /*#__PURE__*/ jsxs(Fragment, {
19
- children: [
20
- /*#__PURE__*/ jsx("div", {
21
- className: "modifier-header",
22
- children: /*#__PURE__*/ jsx("div", {
23
- className: "title",
24
- children: modifierSet.name
25
- })
26
- }),
27
- /*#__PURE__*/ jsx(ModifiersSetControl, {
28
- modifierSet: modifierSet,
29
- productId: product.id,
30
- modifiers: modifierSet.modifiers,
31
- isEditMode: !!(editOrderModifier === null || editOrderModifier === void 0 ? void 0 : editOrderModifier.modifiers),
32
- orderProductModifierSets: editOrderModifier === null || editOrderModifier === void 0 ? void 0 : editOrderModifier.modifiers,
33
- modifiersSetWithErrors: errors,
34
- isLoading: isLoading
35
- })
36
- ]
37
- });
38
- })
39
- })
40
- });
41
- }
14
+ var orderModifiersSets = watch("".concat(product.id, ".orderProductModifiers"));
15
+ useEffect(function() {
16
+ if (!isValid) return;
17
+ clearErrors();
18
+ }, [
19
+ isValid,
20
+ clearErrors
21
+ ]);
22
+ return /*#__PURE__*/ jsx("div", {
23
+ className: "mb-8 pt-4",
24
+ children: /*#__PURE__*/ jsx("div", {
25
+ className: "d-flex flex-column",
26
+ children: modifiersSet.map(function(modifierSet) {
27
+ var orderProductModifiersMaxQuantity = orderProductModifiersQuantity(orderModifiersSets, modifierSet);
28
+ return /*#__PURE__*/ jsxs("div", {
29
+ className: "modifier-set-container",
30
+ children: [
31
+ /*#__PURE__*/ jsx("div", {
32
+ className: "modifier-header",
33
+ children: /*#__PURE__*/ jsx("div", {
34
+ className: "title",
35
+ children: modifierSet.name
36
+ })
37
+ }),
38
+ /*#__PURE__*/ jsx(Controller, {
39
+ control: control,
40
+ name: "".concat(product.id, ".").concat(modifierSet.id),
41
+ rules: {
42
+ validate: function() {
43
+ var maxItems = modifierSet.maxItems, minItems = modifierSet.minItems;
44
+ if (!!minItems && orderProductModifiersMaxQuantity < minItems) {
45
+ return t('Validation:quantityMinNumberModifier', {
46
+ min: minItems
47
+ });
48
+ }
49
+ if (orderProductModifiersMaxQuantity > maxItems) {
50
+ return t('Validation:quantityMaxNumberModifier', {
51
+ max: maxItems
52
+ });
53
+ }
54
+ return true;
55
+ }
56
+ },
57
+ render: function(param) {
58
+ var error = param.fieldState.error;
59
+ return /*#__PURE__*/ jsxs(Fragment, {
60
+ children: [
61
+ /*#__PURE__*/ jsx(ModifiersSetControl, {
62
+ modifierSet: modifierSet,
63
+ productId: product.id,
64
+ modifiers: modifierSet.modifiers,
65
+ isEditMode: !!(editOrderModifier === null || editOrderModifier === void 0 ? void 0 : editOrderModifier.modifiers),
66
+ orderProductModifierSets: editOrderModifier === null || editOrderModifier === void 0 ? void 0 : editOrderModifier.modifiers,
67
+ isLoading: isLoading
68
+ }),
69
+ (error === null || error === void 0 ? void 0 : error.message) && /*#__PURE__*/ jsxs("div", {
70
+ className: "invalid-feedback d-flex pl-4",
71
+ children: [
72
+ error === null || error === void 0 ? void 0 : error.message,
73
+ "!"
74
+ ]
75
+ })
76
+ ]
77
+ });
78
+ }
79
+ })
80
+ ]
81
+ }, modifierSet.id);
82
+ })
83
+ })
42
84
  });
43
85
  };
44
86
 
@@ -0,0 +1,5 @@
1
+ import { OrderModifier } from "@licklist/core/dist/DataMapper/Order/OrderModifierDataMapper";
2
+ export type selectModifierType = 'radio' | 'checkbox' | 'selector';
3
+ export declare const filteredOrderModifierSets: (modifiersSet: OrderModifier[]) => OrderModifier[];
4
+ export declare const orderProductModifiersQuantity: (orderModifiersSets: OrderModifier[], modifierSet: any) => number;
5
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/iframe/ProductWithModifierModal/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8DAA8D,CAAA;AAG5F,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,UAAU,GAAG,UAAU,CAAA;AAElE,eAAO,MAAM,yBAAyB,iBACpB,aAAa,EAAE,KAC5B,aAAa,EAUf,CAAA;AAED,eAAO,MAAM,6BAA6B,uBACpB,aAAa,EAAE,6BAOpC,CAAA"}
@@ -0,0 +1,19 @@
1
+ import { uniqBy } from 'lodash';
2
+
3
+ var filteredOrderModifierSets = function(modifiersSet) {
4
+ if (!modifiersSet) return [];
5
+ var orderModifier = modifiersSet.flat().filter(function(modifier) {
6
+ return !!(modifier === null || modifier === void 0 ? void 0 : modifier.quantity);
7
+ });
8
+ return uniqBy(orderModifier, function(item) {
9
+ return "".concat(item.modifierId, "-").concat(item.modifierSetId);
10
+ });
11
+ };
12
+ var orderProductModifiersQuantity = function(orderModifiersSets, modifierSet) {
13
+ var filteredOrderModifier = filteredOrderModifierSets(orderModifiersSets);
14
+ return filteredOrderModifier.filter(function(item) {
15
+ return (item === null || item === void 0 ? void 0 : item.modifierSetId) === modifierSet.id;
16
+ }).length;
17
+ };
18
+
19
+ export { filteredOrderModifierSets, orderProductModifiersQuantity };
@@ -1 +1 @@
1
- {"version":3,"file":"ProductsControl.d.ts","sourceRoot":"","sources":["../../../src/product-set/form/ProductsControl.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,MAAM,kEAAkE,CAAA;AAC/F,OAAO,EAAkB,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,IAAI,CAAA;AAI9E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAQhD,UAAU,oBAAqB,SAAQ,aAAa;IAClD,YAAY,EAAE,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,cAAc,CAAC,CAAA;IACvE,SAAS,EAAE,MAAM,CAAA;IACjB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AA+BD,wBAAgB,eAAe,CAAC,EAC9B,SAAS,EACT,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,SAAS,EACT,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,oBAAoB,GACrB,EAAE,oBAAoB,2CAyOtB"}
1
+ {"version":3,"file":"ProductsControl.d.ts","sourceRoot":"","sources":["../../../src/product-set/form/ProductsControl.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,MAAM,kEAAkE,CAAA;AAC/F,OAAO,EAAkB,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,IAAI,CAAA;AAI9E,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAQhD,UAAU,oBAAqB,SAAQ,aAAa;IAClD,YAAY,EAAE,mBAAmB,CAAC,oBAAoB,CAAC,CAAC,cAAc,CAAC,CAAA;IACvE,SAAS,EAAE,MAAM,CAAA;IACjB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,YAAY,CAAA;IAC1B,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AA+BD,wBAAgB,eAAe,CAAC,EAC9B,SAAS,EACT,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,SAAS,EACT,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,oBAAoB,GACrB,EAAE,oBAAoB,2CAkPtB"}
@@ -168,6 +168,12 @@ function ProductsControl(param) {
168
168
  return "".concat(productControlFieldName, ".").concat(index, ".isUnlimited");
169
169
  }))
170
170
  });
171
+ var modifierSets = useWatch({
172
+ control: control,
173
+ name: _to_consumable_array(fields.map(function(_, index) {
174
+ return "".concat(productControlFieldName, ".").concat(index, ".modifiersSet");
175
+ }))
176
+ });
171
177
  var categoryProductErrors = errors === null || errors === void 0 ? void 0 : (_errors_steps = errors.steps) === null || _errors_steps === void 0 ? void 0 : (_errors_steps_stepIndex = _errors_steps[stepIndex]) === null || _errors_steps_stepIndex === void 0 ? void 0 : (_errors_steps_stepIndex_productCategories = _errors_steps_stepIndex.productCategories) === null || _errors_steps_stepIndex_productCategories === void 0 ? void 0 : (_errors_steps_stepIndex_productCategories_productCategoryIndex = _errors_steps_stepIndex_productCategories[productCategoryIndex]) === null || _errors_steps_stepIndex_productCategories_productCategoryIndex === void 0 ? void 0 : _errors_steps_stepIndex_productCategories_productCategoryIndex.products;
172
178
  var isFirstProductAdded = fields.length === 1;
173
179
  var mouseSensor = useSensor(MouseSensor, {
@@ -211,9 +217,10 @@ function ProductsControl(param) {
211
217
  mouseSensor
212
218
  ],
213
219
  children: fields.map(function(product, index) {
220
+ var _modifierSets_index;
214
221
  var isOverridesProductSet = isEventEditProductSet ? !!product.id : isOverrides && !!product.originalProductId;
215
- var modifierSets = (product === null || product === void 0 ? void 0 : product.modifiersSet.length) || 0;
216
222
  var isNewProductOverrides = isCreateNewOverrides && !!product.id;
223
+ var modifiersSets = ((_modifierSets_index = modifierSets[index]) === null || _modifierSets_index === void 0 ? void 0 : _modifierSets_index.length) || 0;
217
224
  return /*#__PURE__*/ jsx(Controller, {
218
225
  control: control,
219
226
  name: "".concat(productControlFieldName, ".").concat(index, ".name"),
@@ -256,9 +263,9 @@ function ProductsControl(param) {
256
263
  })
257
264
  ]
258
265
  }),
259
- !!modifierSets && /*#__PURE__*/ jsx(Badge, {
266
+ !!modifiersSets && /*#__PURE__*/ jsx(Badge, {
260
267
  className: "modifier-badge",
261
- children: "".concat(modifierSets, " ").concat(t('modifiersSets'))
268
+ children: "".concat(modifiersSets, " ").concat(t('modifiersSets'))
262
269
  })
263
270
  ]
264
271
  }),
@@ -90,6 +90,7 @@
90
90
  }
91
91
  label.btn-link {
92
92
  width: 4.5rem;
93
+ z-index: 0;
93
94
  display: flex;
94
95
  justify-content: center;
95
96
  span {
@@ -90,6 +90,7 @@
90
90
  .modifier-badge {
91
91
  background-color: #e9f5ea;
92
92
  color: #269b36;
93
+ height: 1rem;
93
94
  }
94
95
  }
95
96
 
@@ -60,6 +60,11 @@
60
60
  }
61
61
 
62
62
  .modifier-container {
63
+ background-color: color('white');
64
+ padding-bottom: 1rem;
65
+ }
66
+
67
+ .modifier-set-container {
63
68
  background-color: color('white');
64
69
  border-bottom: 2px solid #f0f0f0;
65
70
  padding-bottom: 1rem;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@licklist/design",
3
- "version": "0.71.18-dev.4",
3
+ "version": "0.71.18-dev.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+ssh://git@bitbucket.org/artelogicsoft/licklist_design.git"
@@ -42,7 +42,7 @@
42
42
  ]
43
43
  },
44
44
  "peerDependencies": {
45
- "@licklist/core": "0.31.2-dev.10",
45
+ "@licklist/core": "0.31.2-dev.11",
46
46
  "@licklist/eslint-config": "0.5.6",
47
47
  "@licklist/plugins": "0.35.1-dev.8",
48
48
  "lodash": "4.17.21",
@@ -61,7 +61,7 @@
61
61
  "@dnd-kit/utilities": "2.0.0",
62
62
  "@fortawesome/fontawesome-svg-core": "1.2.34",
63
63
  "@fortawesome/free-solid-svg-icons": "5.15.2",
64
- "@licklist/core": "0.31.2-dev.10",
64
+ "@licklist/core": "0.31.2-dev.11",
65
65
  "@licklist/eslint-config": "0.5.6",
66
66
  "@licklist/plugins": "0.35.1-dev.8",
67
67
  "@mantine/core": "6.0.22",
@@ -54,7 +54,7 @@ export const ProductWithModifierSetForm = ({
54
54
  const { t } = useTranslation(['App', 'Sale', 'Validation'])
55
55
 
56
56
  const {
57
- formState: { errors, isSubmitting },
57
+ formState: { errors, isSubmitting, isValid },
58
58
  control,
59
59
  trigger,
60
60
  watch,
@@ -78,8 +78,9 @@ export const ProductWithModifierSetForm = ({
78
78
 
79
79
  const onSubmit = (event) => {
80
80
  event.preventDefault()
81
- trigger()
81
+ trigger(`${product.id}`)
82
82
 
83
+ if (!isValid) return undefined
83
84
  const productOrder: FormOrderItem = {
84
85
  id: product.id,
85
86
  name: product.name,
@@ -123,7 +124,6 @@ export const ProductWithModifierSetForm = ({
123
124
  <div className='manual-booking-form'>
124
125
  <ProductControl
125
126
  product={product}
126
- errors={errors}
127
127
  editOrderModifier={editOrderModifier}
128
128
  />
129
129
  <div className='bg-light m-2 p-2 rounded'>
@@ -5,35 +5,27 @@ import { Modifier } from '@licklist/core/dist/DataMapper/Product/ModifierDataMap
5
5
  import { ModifierSet } from '@licklist/core/dist/DataMapper/Product/ModifierSetDataMapper'
6
6
  import { ChangeEvent, useEffect, useMemo } from 'react'
7
7
  import { useId } from '@mantine/hooks'
8
- import {
9
- Controller,
10
- FieldErrors,
11
- FieldValues,
12
- useFormContext,
13
- } from 'react-hook-form'
14
- import { xor, uniqBy } from 'lodash'
8
+ import { Controller, useFormContext } from 'react-hook-form'
9
+ import { xor } from 'lodash'
15
10
  import clsx from 'clsx'
16
11
  import { Currency } from '@licklist/core/dist/Config'
17
12
  import { useIntl } from 'react-intl'
18
13
  import { MAX_PRODUCT_NUMBER } from 'src/iframe/order-process/components/CategoryProduct/constants'
19
14
  import { NumberInputHorizontal } from 'src/sales'
15
+ import { selectModifierType } from '../../utils'
20
16
 
21
17
  interface ModifiersSetControllProps {
22
18
  modifiers?: Modifier[]
23
19
  modifierSet: ModifierSet
24
- modifiersSetWithErrors?: FieldErrors<FieldValues>
25
20
  isLoading?: boolean
26
21
  isEditMode?: boolean
27
22
  productId: number
28
23
  orderProductModifierSets?: OrderModifier[]
29
24
  }
30
25
 
31
- type selectModifierType = 'radio' | 'checkbox' | 'selector'
32
-
33
26
  export const ModifiersSetControl = ({
34
27
  modifierSet,
35
28
  modifiers,
36
- modifiersSetWithErrors,
37
29
  productId,
38
30
  isLoading = false,
39
31
  isEditMode = false,
@@ -42,35 +34,12 @@ export const ModifiersSetControl = ({
42
34
  const { control, watch, setValue, trigger } = useFormContext()
43
35
  const { t } = useTranslation('App')
44
36
 
45
- const filteredOrderModifierSets = (
46
- modifiersSet: OrderModifier[],
47
- ): OrderModifier[] => {
48
- if (!modifiersSet) return []
49
- const orderModifier = modifiersSet
50
- .flat()
51
- .filter((modifier) => !!modifier?.quantity)
52
-
53
- return uniqBy(
54
- orderModifier,
55
- (item) => `${item.modifierId}-${item.modifierSetId}`,
56
- )
57
- }
58
-
59
37
  const orderModifiersSets = watch(`${productId}.orderProductModifiers`)
38
+
60
39
  const { formatNumber } = useIntl()
61
40
  const formatToCurrency = (value: number) =>
62
41
  formatNumber(value, { style: 'currency', currency: Currency.GBP })
63
42
 
64
- const orderProductModifiersQuantity = (orderModifiersSets) => {
65
- const filteredOrderModifier = filteredOrderModifierSets(orderModifiersSets)
66
- return filteredOrderModifier
67
- .flat()
68
- .filter((item) => item && item.modifierSetId === modifierSet.id).length
69
- }
70
-
71
- const orderProductModifiersMaxQuantity =
72
- orderProductModifiersQuantity(orderModifiersSets)
73
-
74
43
  const currentOrderModifiersSets = useMemo(
75
44
  () =>
76
45
  orderProductModifierSets?.filter(
@@ -141,6 +110,8 @@ export const ModifiersSetControl = ({
141
110
  orderModifiers,
142
111
  )
143
112
  }
113
+
114
+ trigger(`${productId}.orderProductModifiers`)
144
115
  }
145
116
 
146
117
  useEffect(() => {
@@ -153,8 +124,6 @@ export const ModifiersSetControl = ({
153
124
  )
154
125
  }, [isEditMode])
155
126
 
156
- const modifiersErrors = modifiersSetWithErrors?.modifiers
157
-
158
127
  return (
159
128
  <>
160
129
  {modifierSet?.maxItems === 1 &&
@@ -162,20 +131,22 @@ export const ModifiersSetControl = ({
162
131
  !currentOrderModifiersSets?.find((modifier) => !!modifier?.quantity) ? (
163
132
  <>
164
133
  <Controller
165
- name={`${modifierSet.id}`}
166
- data-testid='modifierSet-values-select'
134
+ name={`${productId}.orderProductModifiers.${modifierSet.id}`}
167
135
  control={control}
168
136
  rules={{
169
- required: !!modifierSet.minItems
137
+ required: {
138
+ value: !!modifierSet.minItems,
139
+ message: t('Validation:fieldRequired') as string,
140
+ },
170
141
  }}
171
- render={({ field }) => {
142
+ render={({ field, fieldState }) => {
172
143
  const onChange = (e: ChangeEvent<HTMLInputElement>) => {
173
144
  onChangeModifiers(e, 'radio')
174
145
  field.onChange(e.target.id)
175
146
  }
176
147
  return (
177
148
  <>
178
- {modifiers?.map((modifier) => {
149
+ {modifiers.map((modifier) => {
179
150
  const selectedOrderModifierId = currentOrderModifiersSets
180
151
  ?.find(
181
152
  (orderModifier) =>
@@ -184,44 +155,39 @@ export const ModifiersSetControl = ({
184
155
  ?.modifierId?.toString()
185
156
 
186
157
  return (
187
- <Col key={modifier.id.toString()}>
188
- <>
189
- <div className='modifier-container d-flex justify-content-between align-items-center p-2'>
190
- <Form.Check
191
- className='custom-radio'
192
- inline
193
- id={modifier.id.toString()}
194
- defaultChecked={!!selectedOrderModifierId}
195
- defaultValue={modifier.id.toString()}
196
- checked={field.value === modifier.id.toString()}
197
- onChange={onChange}
198
- type='radio'
199
- label={modifier.name}
200
- name={modifier.name}
201
- />
202
- </div>
158
+ <Col key={modifier.id}>
159
+ <div className='modifier-container d-flex flex-column p-2'>
160
+ <Form.Check
161
+ className='custom-radio p-2'
162
+ inline
163
+ id={modifier.id.toString()}
164
+ defaultChecked={!!selectedOrderModifierId}
165
+ defaultValue={modifier.id.toString()}
166
+ checked={field.value === modifier.id.toString()}
167
+ onChange={onChange}
168
+ type='radio'
169
+ label={modifier.name}
170
+ name={modifier.name}
171
+ />
203
172
  <div className='mt-3 w-100 pl-2'>
204
173
  <p>{modifier.description}</p>
205
174
  <div className='price'>
206
175
  + {formatToCurrency(modifier.price)}
207
176
  </div>
208
177
  </div>
209
- </>
178
+ </div>
210
179
  </Col>
211
180
  )
212
181
  })}
182
+ {fieldState.error && (
183
+ <div className='invalid-feedback d-block'>
184
+ {fieldState.error.message}
185
+ </div>
186
+ )}
213
187
  </>
214
188
  )
215
189
  }}
216
190
  />
217
-
218
- {modifiersErrors?.message && (
219
- <Col>
220
- <div className='invalid-feedback field-values-error'>
221
- {modifiersSetWithErrors.message || 'test'}
222
- </div>
223
- </Col>
224
- )}
225
191
  </>
226
192
  ) : (
227
193
  <>
@@ -229,44 +195,20 @@ export const ModifiersSetControl = ({
229
195
  const selectedOrderModifier = currentOrderModifiersSets?.find(
230
196
  (orderModifier) => orderModifier.modifierId === modifier.id,
231
197
  )?.quantity
232
- const requiredModifierSet = modifierSet?.minItems > currentOrderModifiersSets.length
233
- const errorMessage = (modifiersErrors as FieldError[])?.find(
234
- (modifier) =>
235
- modifier.ref && modifier.ref.name === `modifiers[${index}]`,
236
- )?.message
237
198
 
238
199
  return (
239
200
  <>
240
201
  {modifier.maxItems === 1 ? (
241
202
  <>
242
203
  <Controller
243
- name={`modifiers[${index}]`}
204
+ name={`${productId}.${modifierSet.id}.modifiers[${index}]`}
244
205
  control={control}
245
206
  rules={{
246
- required: !!modifier.minItems || requiredModifierSet,
207
+ required: {
208
+ value: !!modifier.minItems,
209
+ message: t('Validation:fieldRequired') as string,
210
+ },
247
211
  validate: (value) => {
248
- if (!value) return true
249
- const {
250
- maxItems: maxModifierSet,
251
- minItems: minModifierSet,
252
- } = modifierSet
253
-
254
- if (
255
- orderProductModifiersMaxQuantity < minModifierSet
256
- ) {
257
- return t('Validation:quantityMinNumberModifier', {
258
- min: minModifierSet,
259
- }) as string
260
- }
261
-
262
- if (
263
- orderProductModifiersMaxQuantity > maxModifierSet
264
- ) {
265
- return t('Validation:quantityMaxNumberModifier', {
266
- max: maxModifierSet,
267
- }) as string
268
- }
269
-
270
212
  const { maxItems, minItems } = modifier
271
213
  if (value?.length > maxItems) {
272
214
  return t('Validation:quantityMaxNumberModifier', {
@@ -283,7 +225,7 @@ export const ModifiersSetControl = ({
283
225
  return true
284
226
  },
285
227
  }}
286
- render={({ field }) => {
228
+ render={({ field, fieldState: { error } }) => {
287
229
  const onChange = (e: ChangeEvent<HTMLInputElement>) => {
288
230
  onChangeModifiers(e, 'checkbox')
289
231
  field.onChange(
@@ -293,10 +235,10 @@ export const ModifiersSetControl = ({
293
235
 
294
236
  return (
295
237
  <Col
296
- className='modifier-container pl-6'
238
+ className='modifier-container pl-4'
297
239
  key={modifier.id.toString()}
298
240
  >
299
- <div className='d-flex justify-content-between align-items-center'>
241
+ <div className='d-flex justify-content-between pl-2 align-items-center'>
300
242
  <Checkbox
301
243
  value={modifier.id}
302
244
  onChange={onChange}
@@ -310,9 +252,9 @@ export const ModifiersSetControl = ({
310
252
  + {formatToCurrency(modifier.price)}
311
253
  </div>
312
254
  </div>
313
- {errorMessage && (
255
+ {error?.message && (
314
256
  <div className='invalid-feedback d-flex'>
315
- {errorMessage}
257
+ {error?.message}
316
258
  </div>
317
259
  )}
318
260
  </Col>
@@ -329,30 +271,11 @@ export const ModifiersSetControl = ({
329
271
  control={control}
330
272
  name={`${productId}.${modifierSet.id}.modifiers[${index}].quantity`}
331
273
  rules={{
332
- required: !!modifier.minItems || requiredModifierSet,
274
+ required: {
275
+ value: !!modifier.minItems,
276
+ message: t('Validation:fieldRequired') as string,
277
+ },
333
278
  validate: (value) => {
334
- // if (!value) return true
335
- const {
336
- maxItems: maxModifierSet,
337
- minItems: minModifierSet,
338
- } = modifierSet
339
- if (
340
- orderProductModifiersMaxQuantity < minModifierSet
341
- ) {
342
- return t('Validation:quantityMinNumberModifier', {
343
- min: minModifierSet,
344
- }) as string
345
- }
346
-
347
- if (
348
- orderProductModifiersMaxQuantity > maxModifierSet
349
- ) {
350
-
351
- return t('Validation:quantityMaxNumberModifier', {
352
- max: maxModifierSet,
353
- }) as string
354
- }
355
-
356
279
  const { maxItems, minItems } = modifier
357
280
  if (value > maxItems) {
358
281
  return t('Validation:quantityMaxNumberModifier', {
@@ -426,13 +349,6 @@ export const ModifiersSetControl = ({
426
349
  />
427
350
  </>
428
351
  )}
429
- {modifiersErrors?.message && (
430
- <Col>
431
- <div className='invalid-feedback field-values-error'>
432
- {modifiersSetWithErrors.message || 'test'}
433
- </div>
434
- </Col>
435
- )}
436
352
  </>
437
353
  )
438
354
  })}