@licklist/design 0.62.3-dev.2 → 0.63.0-dev.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/dist/product-set/control/DateAndRecurrenceInput.d.ts +0 -4
- package/dist/product-set/control/DateAndRecurrenceInput.d.ts.map +1 -1
- package/dist/product-set/control/DateAndRecurrenceInput.js +1 -1
- package/dist/product-set/control/ProductSetControl.d.ts +3 -2
- package/dist/product-set/control/ProductSetControl.d.ts.map +1 -1
- package/dist/product-set/control/utils.d.ts +5 -0
- package/dist/product-set/control/utils.d.ts.map +1 -0
- package/dist/product-set/control/utils.js +1 -0
- package/dist/zone/form/components/AvailableTimesControl.d.ts +0 -2
- package/dist/zone/form/components/AvailableTimesControl.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/product-set/control/DateAndRecurrenceInput.tsx +45 -12
- package/src/product-set/control/ProductSetControl.stories.tsx +1 -1
- package/src/product-set/control/ProductSetControl.tsx +4 -7
- package/src/product-set/control/utils.ts +25 -0
- package/src/product-set/form/ProductSetForm.stories.tsx +1 -2
- package/src/zone/form/components/AvailableTimesControl.tsx +0 -2
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Modifier } from "@popperjs/core";
|
|
3
3
|
import { WorkHour } from "@licklist/core/dist/DataMapper/Provider/WorkHourDataMapper";
|
|
4
|
-
import { ProductSetRecurrence } from "@licklist/core/dist/DataMapper/Product/ProductSetRecurrenceDataMapper";
|
|
5
|
-
export interface DateAndRecurrenceInputValues {
|
|
6
|
-
menuRecurrences?: Partial<ProductSetRecurrence>[];
|
|
7
|
-
}
|
|
8
4
|
interface DateAndRecurrenceInputProps {
|
|
9
5
|
isEventEditProductSet?: boolean;
|
|
10
6
|
workHours: WorkHour[] | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateAndRecurrenceInput.d.ts","sourceRoot":"","sources":["../../../src/product-set/control/DateAndRecurrenceInput.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAO1C,OAAO,EAAE,QAAQ,EAAE,MAAM,4DAA4D,CAAC;
|
|
1
|
+
{"version":3,"file":"DateAndRecurrenceInput.d.ts","sourceRoot":"","sources":["../../../src/product-set/control/DateAndRecurrenceInput.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAO1C,OAAO,EAAE,QAAQ,EAAE,MAAM,4DAA4D,CAAC;AA0BtF,UAAU,2BAA2B;IACnC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;IAClC,4BAA4B,EAAE,OAAO,CAAC;IACtC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,sBAAsB,mFAKhC,2BAA2B,gBAmT7B,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAC5C,WAAW,EACX,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAsBxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("tslib"),t=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("tslib"),t=require("react"),i=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,n=require("react-i18next"),a=require("react-bootstrap"),o=require("../../static/Icon.js"),u=require("react-hook-form"),l=require("@react-aria/utils"),s=require("react-use"),d=require("luxon");require("../../static/index.js");var c=require("@dnd-kit/core"),m=require("@dnd-kit/modifiers"),v=require("@dnd-kit/sortable"),f=require("../../modals/confirmation/ConfirmModal.js"),g=require("@licklist/core/dist/Config/Date"),p=require("../../recurring-date-picker-input/RecurringDatePickerInput.js"),T=require("./ProductSetRecurrenceControl.js"),b=require("../../zone/form/components/AvailableTimesControl.js"),E=require("./utils.js"),x={name:"sameWidth",enabled:!0,phase:"beforeWrite",requires:["computeStyles"],fn:function(e){var r=e.state,t={width:"".concat(r.rects.reference.width+4,"px"),marginLeft:"-2px",maxWidth:"unset"};Object.assign(r.styles.popper,t)},effect:function(e){var r=e.state,t=r.elements.reference.getBoundingClientRect().width,i={width:"".concat(t,"px"),maxWidth:"unset"};Object.assign(r.elements.popper.style,i)}};exports.DateAndRecurrenceInput=function(e){var _,R,D,h,M,q=e.isEventEditProductSet,S=e.providerHasBookingManagement,I=e.workHours,C=e.isLoading,F=u.useFormContext(),k=F.control,w=F.register,y=F.formState.errors,A=F.getValues,O=F.setValue,j=F.clearErrors,N=u.useWatch({control:k,name:"steps"}),P=r.__read(t.useState([]),2),V=P[0],L=P[1],W=t.useRef(),B=u.useFieldArray({name:"menuRecurrences",control:k,keyName:"_id"}),H=B.fields,z=B.append,G=B.update,K=B.move,J=r.__read(t.useState(!1),2),Q=J[0],U=J[1],X=r.__read(t.useState({index:null,values:null}),2),Y=X[0],Z=X[1],$=function(){return Z({index:null,values:null})},ee=t.useRef();s.useClickAway(ee,(function(e){var r,t,i;f.CONFIRM_MODAL_ACTIONS.includes(null===(i=null===(t=null===(r=e.target)||void 0===r?void 0:r.attributes)||void 0===t?void 0:t.getNamedItem("data-id"))||void 0===i?void 0:i.value)||(U(!1),$())}));var re=l.useId(),te=n.useTranslation("Design").t,ie=function(){$(),U((function(e){return!e}))};return t.useEffect((function(){H.length&&j("menuRecurrences")}),[H,j]),i.createElement(a.Form.Group,null,i.createElement(a.Form.Label,null,te(q?"whenOverridesAvailable":"productSetAvailable")),i.createElement(a.OverlayTrigger,{show:Q,overlay:i.createElement(a.Popover,{id:re,className:"rounded"},i.createElement(a.Popover.Content,{className:"shadow-lg rounded",ref:ee},i.createElement(p.RecurringDatePickerInput,{defaultValues:Y.values,onChange:function(e){return r.__awaiter(void 0,void 0,void 0,(function(){var t,i,n,a,o,u,l,s,c,m,v,f,p,T,b;return r.__generator(this,(function(r){switch(r.label){case 0:return[4,null===(v=W.current)||void 0===v?void 0:v.trigger()];case 1:return t=r.sent(),i=W.current.getValues().availableTimes,(null==e?void 0:e.startTime)&&(null==e?void 0:e.endTime)&&t&&(n=d.DateTime.fromISO(e.startTime),a=d.DateTime.fromISO(e.endTime),!i.every((function(e){var r=d.DateTime.fromFormat(e,g.TIME_FORMAT);return r.diff(n,"minutes").minutes>=0&&r.diff(a,"minutes").minutes<=0})))?(W.current.setError("availableTimes",{message:te("Validation:fieldTimeBetween",{attribute:te("Design:startTimesSmall"),min:n.toFormat(g.TIME_FORMAT),max:a.toFormat(g.TIME_FORMAT)})}),[2]):(o=E.getProductWithSmallestDuration(N))&&(u=(null==e?void 0:e.endTime)?d.DateTime.fromFormat(null==e?void 0:e.endTime,g.TIME_FORMAT):d.DateTime.fromFormat("23:59",g.TIME_FORMAT).plus({minutes:1}),l=E.getLatestAvailableDateTime(i),s=u.minus({minutes:o.duration}),l>s)?(W.current.setError("availableTimes",{message:te("Validation:fieldTimeBefore",{attribute:te("Design:timeLowercase"),time:s.toFormat(g.TIME_FORMAT)})}),[2]):(c=(null===(p=null===(f=null==W?void 0:W.current)||void 0===f?void 0:f.getValues())||void 0===p?void 0:p.availableTimes)||null,m={rrule:e.rrule,startDate:e.startDate,endDate:e.endDate,startTime:e.startTime,endTime:e.endTime,availableTimes:c},(null===(T=Y.values)||void 0===T?void 0:T.id)&&(m.id=null===(b=Y.values)||void 0===b?void 0:b.id),null!==Y.index?G(Y.index,m):z(m),U((function(){return!1})),$(),[2])}}))}))},onDelete:function(){var e=Y.index;U(!1),$(),setTimeout((function(){var r=A().menuRecurrences;O("menuRecurrences",(void 0===r?[]:r).filter((function(r,t){return t!==e})))}),100)},workHours:I},S&&i.createElement(b.AvailableTimesControl,{workHours:I,isLoading:C,defaultValues:V,ref:W,errorMessage:null===(D=null===(R=null===(_=null==y?void 0:y.menuRecurrences)||void 0===_?void 0:_["".concat(null==Y?void 0:Y.index)])||void 0===R?void 0:R.availableTimes)||void 0===D?void 0:D.message,clearErrorMessage:function(){return j("menuRecurrences.".concat(null==Y?void 0:Y.index,".availableTimes"))}})))),trigger:"click",placement:"bottom",popperConfig:{modifiers:[x]}},i.createElement("div",{className:"product-set-recurrences"},i.createElement(c.DndContext,{onDragEnd:function(e){var r=e.over,t=e.active;if(r.id!==t.id){var i=H.findIndex((function(e){return String(e._id)===t.id})),n=H.findIndex((function(e){return String(e._id)===r.id}));K(i,n)}},modifiers:[m.restrictToVerticalAxis]},i.createElement(v.SortableContext,{items:null!==(h=null==H?void 0:H.map((function(e){return String(e._id)})))&&void 0!==h?h:[],strategy:v.verticalListSortingStrategy},H.map((function(e,r){var t,n,a;return i.createElement(T.ProductSetRecurrenceControl,{key:e._id,menuRecurrence:e,onEdit:function(){return function(e,r){$(),setTimeout((function(){Z({index:r,values:e}),L(e.availableTimes||[]),U((function(){return!0}))}),100)}(e,r)},errorMessage:null===(a=null===(n=null===(t=null==y?void 0:y.menuRecurrences)||void 0===t?void 0:t["".concat(r)])||void 0===n?void 0:n.availableTimes)||void 0===a?void 0:a.message})})))),(!q||(null==H?void 0:H.length)<1)&&i.createElement("div",{className:"product-set-recurrence-icon-wrapper",role:"button",tabIndex:0,onClick:ie,onKeyDown:ie},i.createElement(o.default,{type:"plus-circle",height:"1rem",className:"product-set-recurrence-icon-add mr-2"}),te("addDates")),i.createElement(a.Form.Control,r.__assign({type:"hidden"},w("menuRecurrences",{required:{value:!0,message:te("Validation:fieldMinNumber",{attribute:te("dates"),min:1})}}))),i.createElement("div",{className:"manual-form-error"},null===(M=y.menuRecurrences)||void 0===M?void 0:M.message))))},exports.sameWidthPopperModifier=x;
|
|
@@ -4,15 +4,15 @@ import { FieldSet } from "@licklist/core/dist/DataMapper/Order/FieldSetDataMappe
|
|
|
4
4
|
import { EmailTemplate } from "@licklist/core/dist/DataMapper/Notification/EmailTemplateDataMapper";
|
|
5
5
|
import { SmsTemplate } from "@licklist/core/dist/DataMapper/Notification/SmsTemplateDataMapper";
|
|
6
6
|
import { WorkHour } from "@licklist/core/dist/DataMapper/Provider/WorkHourDataMapper";
|
|
7
|
+
import { ProductSetRecurrence } from "@licklist/core/dist/DataMapper/Product/ProductSetRecurrenceDataMapper";
|
|
7
8
|
import { SelectItem } from "../../types/generic/SelectItem";
|
|
8
|
-
import { DateAndRecurrenceInputValues } from "./DateAndRecurrenceInput";
|
|
9
9
|
import { Step } from "../types";
|
|
10
10
|
export interface TemplateItem {
|
|
11
11
|
id: string;
|
|
12
12
|
value: EmailTemplate | SmsTemplate;
|
|
13
13
|
label: string;
|
|
14
14
|
}
|
|
15
|
-
export interface ProductSetControlValues
|
|
15
|
+
export interface ProductSetControlValues {
|
|
16
16
|
name: string;
|
|
17
17
|
type: ProductSetType;
|
|
18
18
|
termsAndConditions: string;
|
|
@@ -24,6 +24,7 @@ export interface ProductSetControlValues extends DateAndRecurrenceInputValues {
|
|
|
24
24
|
steps: Step[];
|
|
25
25
|
emailTemplates?: TemplateItem[];
|
|
26
26
|
smsTemplates?: TemplateItem[];
|
|
27
|
+
menuRecurrences?: Partial<ProductSetRecurrence>[];
|
|
27
28
|
}
|
|
28
29
|
export interface ProductSetControlShared {
|
|
29
30
|
fee?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProductSetControl.d.ts","sourceRoot":"","sources":["../../../src/product-set/control/ProductSetControl.tsx"],"names":[],"mappings":";AAKA,OAAO,EAOL,mBAAmB,EACnB,cAAc,EAEd,gBAAgB,EACjB,MAAM,6DAA6D,CAAC;AAErE,OAAO,EAAE,QAAQ,EAAE,MAAM,yDAAyD,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAC;AACpG,OAAO,EAAE,WAAW,EAAE,MAAM,mEAAmE,CAAC;AAGhG,OAAO,EAAE,QAAQ,EAAE,MAAM,4DAA4D,CAAC;
|
|
1
|
+
{"version":3,"file":"ProductSetControl.d.ts","sourceRoot":"","sources":["../../../src/product-set/control/ProductSetControl.tsx"],"names":[],"mappings":";AAKA,OAAO,EAOL,mBAAmB,EACnB,cAAc,EAEd,gBAAgB,EACjB,MAAM,6DAA6D,CAAC;AAErE,OAAO,EAAE,QAAQ,EAAE,MAAM,yDAAyD,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAC;AACpG,OAAO,EAAE,WAAW,EAAE,MAAM,mEAAmE,CAAC;AAGhG,OAAO,EAAE,QAAQ,EAAE,MAAM,4DAA4D,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,uEAAuE,CAAC;AAE7G,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAG5D,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAgBhC,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,aAAa,GAAG,WAAW,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,cAAc,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,mBAAmB,CAAC;IACrC,aAAa,CAAC,EAAE,UAAU,EAAE,CAAC;IAC7B,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,cAAc,CAAC,EAAE,YAAY,EAAE,CAAC;IAChC,YAAY,CAAC,EAAE,YAAY,EAAE,CAAC;IAC9B,eAAe,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,EAAE,CAAC;CACnD;AAED,MAAM,WAAW,uBAAuB;IACtC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;IACjC,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,YAAY,EAAE,CAAC;IAChC,YAAY,CAAC,EAAE,YAAY,EAAE,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;IAClC,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,wBAAgB,iBAAiB,CAAC,EAChC,WAAW,EACX,SAAS,EACT,GAAU,EACV,SAAc,EACd,cAAmB,EACnB,YAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,SAAS,EACT,4BAAoC,EACpC,WAAmB,GACpB,EAAE,sBAAsB,eAgTxB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DateTime } from "luxon";
|
|
2
|
+
import { Product, Step } from "../types";
|
|
3
|
+
export declare const getProductWithSmallestDuration: (steps: Step[]) => Product;
|
|
4
|
+
export declare const getLatestAvailableDateTime: (array: string[]) => DateTime;
|
|
5
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/product-set/control/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAczC,eAAO,MAAM,8BAA8B,UAAW,IAAI,EAAE,KAAG,OACM,CAAC;AAEtE,eAAO,MAAM,0BAA0B,UAAW,MAAM,EAAE,KAAG,QAGxB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@licklist/core/dist/Config"),e=require("luxon"),r=require("@licklist/plugins/dist/utils/dateTime"),i=require("@licklist/plugins/dist/utils/extractObjectWithLowestKey");exports.getLatestAvailableDateTime=function(i){return i.map((function(r){return e.DateTime.fromFormat(r,t.TIME_FORMAT)})).sort(r.dateTimesSortFn("desc"))[0]},exports.getProductWithSmallestDuration=function(t){return i.extractObjectWithLowestKey(function(t){return t.reduce((function(t,e){return t.concat(e.productCategories.reduce((function(t,e){return t.concat(e.products)}),[]))}),[])}(t),"duration")};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AvailableTimesControl.d.ts","sourceRoot":"","sources":["../../../../src/zone/form/components/AvailableTimesControl.tsx"],"names":[],"mappings":"AAAA,OAAO,KAKN,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,eAAe,EAAW,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,4DAA4D,CAAC;AAGtF,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,SAAS,EAAE,MAAM;QAAE,cAAc,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAC9C,QAAQ,EAAE,eAAe,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,KAAK,0BAA0B,GAAG;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,
|
|
1
|
+
{"version":3,"file":"AvailableTimesControl.d.ts","sourceRoot":"","sources":["../../../../src/zone/form/components/AvailableTimesControl.tsx"],"names":[],"mappings":"AAAA,OAAO,KAKN,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,eAAe,EAAW,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,4DAA4D,CAAC;AAGtF,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,SAAS,EAAE,MAAM;QAAE,cAAc,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAC9C,QAAQ,EAAE,eAAe,CAAC,kBAAkB,CAAC,CAAC;CAC/C,CAAC;AAEF,KAAK,0BAA0B,GAAG;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAEF,KAAK,kBAAkB,GAAG;IAAE,cAAc,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEvD,eAAO,MAAM,qBAAqB,6GA8FjC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@licklist/design",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.63.0-dev.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+ssh://git@bitbucket.org/artelogicsoft/licklist_design.git"
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"@fortawesome/free-brands-svg-icons": "5.15.2",
|
|
51
51
|
"@fortawesome/free-solid-svg-icons": "5.15.2",
|
|
52
52
|
"@fortawesome/react-fontawesome": "0.1.9",
|
|
53
|
-
"@licklist/core": ">=0.25.
|
|
53
|
+
"@licklist/core": ">=0.25.1-dev.0 < 0.25.1",
|
|
54
54
|
"@licklist/eslint-config": "0.4.5",
|
|
55
|
-
"@licklist/plugins": ">=0.28.0-dev.
|
|
55
|
+
"@licklist/plugins": ">=0.28.0-dev.2 < 0.28.0",
|
|
56
56
|
"@mdx-js/react": "1.6.22",
|
|
57
57
|
"@popperjs/core": "2.11.8",
|
|
58
58
|
"@react-aria/utils": "3.9.0",
|
|
@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from "react";
|
|
|
2
2
|
import { Modifier } from "@popperjs/core";
|
|
3
3
|
import { useId } from "@react-aria/utils";
|
|
4
4
|
import { Form, OverlayTrigger, Popover } from "react-bootstrap";
|
|
5
|
-
import { useFieldArray, useFormContext } from "react-hook-form";
|
|
5
|
+
import { useFieldArray, useFormContext, useWatch } from "react-hook-form";
|
|
6
6
|
import { useTranslation } from "react-i18next";
|
|
7
7
|
import { useClickAway } from "react-use";
|
|
8
8
|
import { DateTime } from "luxon";
|
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
SortableContext,
|
|
15
15
|
verticalListSortingStrategy,
|
|
16
16
|
} from "@dnd-kit/sortable";
|
|
17
|
-
|
|
18
17
|
import { restrictToVerticalAxis } from "@dnd-kit/modifiers";
|
|
19
18
|
import { CONFIRM_MODAL_ACTIONS } from "../../modals/confirmation/ConfirmModal";
|
|
20
19
|
import { Icon } from "../../static";
|
|
@@ -27,12 +26,11 @@ import {
|
|
|
27
26
|
AvailableTimesControl,
|
|
28
27
|
AvailableTimesControlRef,
|
|
29
28
|
} from "../../zone/form/components/AvailableTimesControl";
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
29
|
+
import { ProductSetControlValues } from "..";
|
|
30
|
+
import {
|
|
31
|
+
getProductWithSmallestDuration,
|
|
32
|
+
getLatestAvailableDateTime,
|
|
33
|
+
} from "./utils";
|
|
36
34
|
|
|
37
35
|
interface DateAndRecurrenceInputProps {
|
|
38
36
|
isEventEditProductSet?: boolean;
|
|
@@ -54,7 +52,9 @@ export const DateAndRecurrenceInput = ({
|
|
|
54
52
|
getValues,
|
|
55
53
|
setValue,
|
|
56
54
|
clearErrors,
|
|
57
|
-
} = useFormContext<
|
|
55
|
+
} = useFormContext<ProductSetControlValues>();
|
|
56
|
+
|
|
57
|
+
const steps = useWatch({ control, name: "steps" });
|
|
58
58
|
|
|
59
59
|
const [availableTimes, setAvailableTimes] = useState<string[]>([]);
|
|
60
60
|
const availableTimesFormRef = useRef<AvailableTimesControlRef>();
|
|
@@ -101,11 +101,13 @@ export const DateAndRecurrenceInput = ({
|
|
|
101
101
|
const isAvailableTimesFormValid =
|
|
102
102
|
await availableTimesFormRef.current?.trigger();
|
|
103
103
|
|
|
104
|
+
const { availableTimes } = availableTimesFormRef.current.getValues();
|
|
105
|
+
|
|
104
106
|
if (next?.startTime && next?.endTime && isAvailableTimesFormValid) {
|
|
105
107
|
const startTime = DateTime.fromISO(next.startTime);
|
|
106
108
|
const endTime = DateTime.fromISO(next.endTime);
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
+
|
|
110
|
+
const areAvailableTimesValid = availableTimes.every((time) => {
|
|
109
111
|
const currentAvailableTime = DateTime.fromFormat(time, TIME_FORMAT);
|
|
110
112
|
|
|
111
113
|
return (
|
|
@@ -113,7 +115,8 @@ export const DateAndRecurrenceInput = ({
|
|
|
113
115
|
currentAvailableTime.diff(endTime, "minutes").minutes <= 0
|
|
114
116
|
);
|
|
115
117
|
});
|
|
116
|
-
|
|
118
|
+
|
|
119
|
+
if (!areAvailableTimesValid) {
|
|
117
120
|
availableTimesFormRef.current.setError("availableTimes", {
|
|
118
121
|
message: t("Validation:fieldTimeBetween", {
|
|
119
122
|
attribute: t("Design:startTimesSmall"),
|
|
@@ -126,6 +129,36 @@ export const DateAndRecurrenceInput = ({
|
|
|
126
129
|
}
|
|
127
130
|
}
|
|
128
131
|
|
|
132
|
+
// this check is required to prevent user from adding available time
|
|
133
|
+
// less than the lowest duration product, e.g. if lowest duration product
|
|
134
|
+
// is 1 hour and user tries to add time 15 minutes before end time,
|
|
135
|
+
// such time can never be booked
|
|
136
|
+
const lowestDurationProduct = getProductWithSmallestDuration(steps);
|
|
137
|
+
|
|
138
|
+
if (lowestDurationProduct) {
|
|
139
|
+
const endTime = next?.endTime
|
|
140
|
+
? DateTime.fromFormat(next?.endTime, TIME_FORMAT)
|
|
141
|
+
: // this is to allow user to add 23:00 if end is at 23:59
|
|
142
|
+
DateTime.fromFormat("23:59", TIME_FORMAT).plus({ minutes: 1 });
|
|
143
|
+
|
|
144
|
+
const latestAvailableTime = getLatestAvailableDateTime(availableTimes);
|
|
145
|
+
|
|
146
|
+
const latestAllowedTime = endTime.minus({
|
|
147
|
+
minutes: lowestDurationProduct.duration,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
if (latestAvailableTime > latestAllowedTime) {
|
|
151
|
+
availableTimesFormRef.current.setError("availableTimes", {
|
|
152
|
+
message: t("Validation:fieldTimeBefore", {
|
|
153
|
+
attribute: t("Design:timeLowercase"),
|
|
154
|
+
time: latestAllowedTime.toFormat(TIME_FORMAT),
|
|
155
|
+
}),
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
129
162
|
const availableTime =
|
|
130
163
|
availableTimesFormRef?.current?.getValues()?.availableTimes || null;
|
|
131
164
|
|
|
@@ -2,12 +2,12 @@ import { Meta, Story } from "@storybook/react";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import Form from "react-bootstrap/Form";
|
|
4
4
|
import { FormProvider, useForm } from "react-hook-form";
|
|
5
|
+
import { OPERATIONAL_COST_CUSTOMER } from "@licklist/core/dist/DataMapper/Product/ProductSetDataMapper";
|
|
5
6
|
import {
|
|
6
7
|
ProductSetControl,
|
|
7
8
|
ProductSetControlProps,
|
|
8
9
|
ProductSetControlValues,
|
|
9
10
|
} from "./ProductSetControl";
|
|
10
|
-
import { OPERATIONAL_COST_CUSTOMER } from "@licklist/core/dist/DataMapper/Product/ProductSetDataMapper";
|
|
11
11
|
|
|
12
12
|
export default {
|
|
13
13
|
title: "Product Set/Control",
|
|
@@ -22,14 +22,10 @@ import { SmsTemplate } from "@licklist/core/dist/DataMapper/Notification/SmsTemp
|
|
|
22
22
|
import HookFormService from "@licklist/plugins/dist/services/Form/HookFormService";
|
|
23
23
|
import { ruleForUrlWithProtocol } from "@licklist/plugins/dist/validation/Rules/urlRule";
|
|
24
24
|
import { WorkHour } from "@licklist/core/dist/DataMapper/Provider/WorkHourDataMapper";
|
|
25
|
+
import { ProductSetRecurrence } from "@licklist/core/dist/DataMapper/Product/ProductSetRecurrenceDataMapper";
|
|
25
26
|
import { WarningMessage } from "../../static";
|
|
26
27
|
import { SelectItem } from "../../types/generic/SelectItem";
|
|
27
|
-
import {
|
|
28
|
-
DateAndRecurrenceInput,
|
|
29
|
-
// TODO: Show Date Component, when reccurent date bugs are fixed
|
|
30
|
-
// DateAndRecurrenceInput,
|
|
31
|
-
DateAndRecurrenceInputValues,
|
|
32
|
-
} from "./DateAndRecurrenceInput";
|
|
28
|
+
import { DateAndRecurrenceInput } from "./DateAndRecurrenceInput";
|
|
33
29
|
import TutorialGifCard from "./TutorialGifCard";
|
|
34
30
|
import { Step } from "../types";
|
|
35
31
|
import { StepsControl } from "../form/StepsControl";
|
|
@@ -53,7 +49,7 @@ export interface TemplateItem {
|
|
|
53
49
|
label: string;
|
|
54
50
|
}
|
|
55
51
|
|
|
56
|
-
export interface ProductSetControlValues
|
|
52
|
+
export interface ProductSetControlValues {
|
|
57
53
|
name: string;
|
|
58
54
|
type: ProductSetType;
|
|
59
55
|
termsAndConditions: string;
|
|
@@ -65,6 +61,7 @@ export interface ProductSetControlValues extends DateAndRecurrenceInputValues {
|
|
|
65
61
|
steps: Step[];
|
|
66
62
|
emailTemplates?: TemplateItem[];
|
|
67
63
|
smsTemplates?: TemplateItem[];
|
|
64
|
+
menuRecurrences?: Partial<ProductSetRecurrence>[];
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
export interface ProductSetControlShared {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TIME_FORMAT } from "@licklist/core/dist/Config";
|
|
2
|
+
import { dateTimesSortFn } from "@licklist/plugins/dist/utils/dateTime";
|
|
3
|
+
import { extractObjectWithLowestKey } from "@licklist/plugins/dist/utils/extractObjectWithLowestKey";
|
|
4
|
+
import { DateTime } from "luxon";
|
|
5
|
+
import { Product, Step } from "../types";
|
|
6
|
+
|
|
7
|
+
const getProductsFromSteps = (steps: Step[]): Product[] =>
|
|
8
|
+
steps.reduce(
|
|
9
|
+
(acc, step) =>
|
|
10
|
+
acc.concat(
|
|
11
|
+
step.productCategories.reduce(
|
|
12
|
+
(acc, productCategory) => acc.concat(productCategory.products),
|
|
13
|
+
[]
|
|
14
|
+
)
|
|
15
|
+
),
|
|
16
|
+
[]
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const getProductWithSmallestDuration = (steps: Step[]): Product =>
|
|
20
|
+
extractObjectWithLowestKey(getProductsFromSteps(steps), "duration");
|
|
21
|
+
|
|
22
|
+
export const getLatestAvailableDateTime = (array: string[]): DateTime =>
|
|
23
|
+
array
|
|
24
|
+
.map((time) => DateTime.fromFormat(time, TIME_FORMAT))
|
|
25
|
+
.sort(dateTimesSortFn("desc"))[0];
|
|
@@ -63,9 +63,9 @@ Default.args = {
|
|
|
63
63
|
sort: 100,
|
|
64
64
|
type: "standard",
|
|
65
65
|
updatedAt: "2023-05-08T15:55:28.000+03:00",
|
|
66
|
+
defaultDuration: 30,
|
|
66
67
|
zoneRecurrences: [
|
|
67
68
|
{
|
|
68
|
-
availableTimes: ["10:05", "10:25", "10:45"],
|
|
69
69
|
endDate: "2022-02-22",
|
|
70
70
|
endTime: "22:00:00",
|
|
71
71
|
id: 1,
|
|
@@ -90,7 +90,6 @@ Default.args = {
|
|
|
90
90
|
updatedAt: "2023-05-08T15:55:28.000+03:00",
|
|
91
91
|
zoneRecurrences: [
|
|
92
92
|
{
|
|
93
|
-
availableTimes: ["10:05", "10:25", "10:45"],
|
|
94
93
|
endDate: "2022-02-22",
|
|
95
94
|
endTime: "22:00:00",
|
|
96
95
|
id: 1,
|