@licklist/design 0.63.1-dev.3 → 0.63.1-dev.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/product-set/control/DateAndRecurrenceInput.d.ts +4 -0
- 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 +2 -3
- package/dist/product-set/control/ProductSetControl.d.ts.map +1 -1
- package/dist/styles/iframe-page/PageBody.scss +0 -1
- package/dist/zone/form/components/AvailableTimesControl.d.ts +2 -0
- package/dist/zone/form/components/AvailableTimesControl.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/product-set/control/DateAndRecurrenceInput.tsx +12 -45
- package/src/product-set/control/ProductSetControl.stories.tsx +1 -1
- package/src/product-set/control/ProductSetControl.tsx +7 -4
- package/src/product-set/form/ProductSetForm.stories.tsx +2 -1
- package/src/styles/iframe-page/PageBody.scss +0 -1
- package/src/zone/form/components/AvailableTimesControl.tsx +2 -0
- package/dist/product-set/control/utils.d.ts +0 -5
- package/dist/product-set/control/utils.d.ts.map +0 -1
- package/dist/product-set/control/utils.js +0 -1
- package/src/product-set/control/utils.ts +0 -25
|
@@ -1,6 +1,10 @@
|
|
|
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
|
+
}
|
|
4
8
|
interface DateAndRecurrenceInputProps {
|
|
5
9
|
isEventEditProductSet?: boolean;
|
|
6
10
|
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;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,uEAAuE,CAAC;AAuB7G,MAAM,WAAW,4BAA4B;IAC3C,eAAe,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,EAAE,CAAC;CACnD;AAED,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,gBAgR7B,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"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,i=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"),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,n={width:"".concat(t,"px"),maxWidth:"unset"};Object.assign(r.elements.popper.style,n)}};exports.DateAndRecurrenceInput=function(e){var E,_,R,h,q,D=e.isEventEditProductSet,S=e.providerHasBookingManagement,C=e.workHours,k=e.isLoading,y=u.useFormContext(),w=y.control,I=y.register,M=y.formState.errors,A=y.getValues,O=y.setValue,F=y.clearErrors,N=r.__read(t.useState([]),2),j=N[0],P=N[1],V=t.useRef(),L=u.useFieldArray({name:"menuRecurrences",control:w,keyName:"_id"}),W=L.fields,H=L.append,B=L.update,z=L.move,G=r.__read(t.useState(!1),2),K=G[0],J=G[1],Q=r.__read(t.useState({index:null,values:null}),2),U=Q[0],X=Q[1],Y=function(){return X({index:null,values:null})},Z=t.useRef();s.useClickAway(Z,(function(e){var r,t,n;f.CONFIRM_MODAL_ACTIONS.includes(null===(n=null===(t=null===(r=e.target)||void 0===r?void 0:r.attributes)||void 0===t?void 0:t.getNamedItem("data-id"))||void 0===n?void 0:n.value)||(J(!1),Y())}));var $=l.useId(),ee=i.useTranslation("Design").t,re=function(){Y(),J((function(e){return!e}))};return t.useEffect((function(){W.length&&F("menuRecurrences")}),[W,F]),n.createElement(a.Form.Group,null,n.createElement(a.Form.Label,null,ee(D?"whenOverridesAvailable":"productSetAvailable")),n.createElement(a.OverlayTrigger,{show:K,overlay:n.createElement(a.Popover,{id:$,className:"rounded"},n.createElement(a.Popover.Content,{className:"shadow-lg rounded",ref:Z},n.createElement(p.RecurringDatePickerInput,{defaultValues:U.values,onChange:function(e){return r.__awaiter(void 0,void 0,void 0,(function(){var t,n,i,a,o,u,l,s,c,m,v;return r.__generator(this,(function(r){switch(r.label){case 0:return[4,null===(l=V.current)||void 0===l?void 0:l.trigger()];case 1:return t=r.sent(),(null==e?void 0:e.startTime)&&(null==e?void 0:e.endTime)&&t&&(n=d.DateTime.fromISO(e.startTime),i=d.DateTime.fromISO(e.endTime),a=V.current.getValues().availableTimes,!a.every((function(e){var r=d.DateTime.fromFormat(e,g.TIME_FORMAT);return r.diff(n,"minutes").minutes>=0&&r.diff(i,"minutes").minutes<=0})))?(V.current.setError("availableTimes",{message:ee("Validation:fieldTimeBetween",{attribute:ee("Design:startTimesSmall"),min:n.toFormat(g.TIME_FORMAT),max:i.toFormat(g.TIME_FORMAT)})}),[2]):(o=(null===(c=null===(s=null==V?void 0:V.current)||void 0===s?void 0:s.getValues())||void 0===c?void 0:c.availableTimes)||null,u={rrule:e.rrule,startDate:e.startDate,endDate:e.endDate,startTime:e.startTime,endTime:e.endTime,availableTimes:o},(null===(m=U.values)||void 0===m?void 0:m.id)&&(u.id=null===(v=U.values)||void 0===v?void 0:v.id),null!==U.index?B(U.index,u):H(u),J((function(){return!1})),Y(),[2])}}))}))},onDelete:function(){var e=U.index;J(!1),Y(),setTimeout((function(){var r=A().menuRecurrences;O("menuRecurrences",(void 0===r?[]:r).filter((function(r,t){return t!==e})))}),100)},workHours:C},S&&n.createElement(b.AvailableTimesControl,{workHours:C,isLoading:k,defaultValues:j,ref:V,errorMessage:null===(R=null===(_=null===(E=null==M?void 0:M.menuRecurrences)||void 0===E?void 0:E["".concat(null==U?void 0:U.index)])||void 0===_?void 0:_.availableTimes)||void 0===R?void 0:R.message,clearErrorMessage:function(){return F("menuRecurrences.".concat(null==U?void 0:U.index,".availableTimes"))}})))),trigger:"click",placement:"bottom",popperConfig:{modifiers:[x]}},n.createElement("div",{className:"product-set-recurrences"},n.createElement(c.DndContext,{onDragEnd:function(e){var r=e.over,t=e.active;if(r.id!==t.id){var n=W.findIndex((function(e){return String(e._id)===t.id})),i=W.findIndex((function(e){return String(e._id)===r.id}));z(n,i)}},modifiers:[m.restrictToVerticalAxis]},n.createElement(v.SortableContext,{items:null!==(h=null==W?void 0:W.map((function(e){return String(e._id)})))&&void 0!==h?h:[],strategy:v.verticalListSortingStrategy},W.map((function(e,r){var t,i,a;return n.createElement(T.ProductSetRecurrenceControl,{key:e._id,menuRecurrence:e,onEdit:function(){return function(e,r){Y(),setTimeout((function(){X({index:r,values:e}),P(e.availableTimes||[]),J((function(){return!0}))}),100)}(e,r)},errorMessage:null===(a=null===(i=null===(t=null==M?void 0:M.menuRecurrences)||void 0===t?void 0:t["".concat(r)])||void 0===i?void 0:i.availableTimes)||void 0===a?void 0:a.message})})))),(!D||(null==W?void 0:W.length)<1)&&n.createElement("div",{className:"product-set-recurrence-icon-wrapper",role:"button",tabIndex:0,onClick:re,onKeyDown:re},n.createElement(o.default,{type:"plus-circle",height:"1rem",className:"product-set-recurrence-icon-add mr-2"}),ee("addDates")),n.createElement(a.Form.Control,r.__assign({type:"hidden"},I("menuRecurrences",{required:{value:!0,message:ee("Validation:fieldMinNumber",{attribute:ee("dates"),min:1})}}))),n.createElement("div",{className:"manual-form-error"},null===(q=M.menuRecurrences)||void 0===q?void 0:q.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";
|
|
8
7
|
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 extends DateAndRecurrenceInputValues {
|
|
16
16
|
name: string;
|
|
17
17
|
type: ProductSetType;
|
|
18
18
|
termsAndConditions: string;
|
|
@@ -24,7 +24,6 @@ export interface ProductSetControlValues {
|
|
|
24
24
|
steps: Step[];
|
|
25
25
|
emailTemplates?: TemplateItem[];
|
|
26
26
|
smsTemplates?: TemplateItem[];
|
|
27
|
-
menuRecurrences?: Partial<ProductSetRecurrence>[];
|
|
28
27
|
}
|
|
29
28
|
export interface ProductSetControlShared {
|
|
30
29
|
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;AAEtF,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAIL,4BAA4B,EAC7B,MAAM,0BAA0B,CAAC;AAElC,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,uBAAwB,SAAQ,4BAA4B;IAC3E,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;CAC/B;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;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;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,EACnB,oBAA4B,GAC7B,EAAE,sBAAsB,eAqTxB"}
|
|
@@ -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,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"}
|
|
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,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,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
|
@@ -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
|
|
5
|
+
import { useFieldArray, useFormContext } 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,6 +14,7 @@ import {
|
|
|
14
14
|
SortableContext,
|
|
15
15
|
verticalListSortingStrategy,
|
|
16
16
|
} from "@dnd-kit/sortable";
|
|
17
|
+
|
|
17
18
|
import { restrictToVerticalAxis } from "@dnd-kit/modifiers";
|
|
18
19
|
import { CONFIRM_MODAL_ACTIONS } from "../../modals/confirmation/ConfirmModal";
|
|
19
20
|
import { Icon } from "../../static";
|
|
@@ -26,11 +27,12 @@ import {
|
|
|
26
27
|
AvailableTimesControl,
|
|
27
28
|
AvailableTimesControlRef,
|
|
28
29
|
} from "../../zone/form/components/AvailableTimesControl";
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
|
|
31
|
+
// eslint-disable-next-line max-len
|
|
32
|
+
|
|
33
|
+
export interface DateAndRecurrenceInputValues {
|
|
34
|
+
menuRecurrences?: Partial<ProductSetRecurrence>[];
|
|
35
|
+
}
|
|
34
36
|
|
|
35
37
|
interface DateAndRecurrenceInputProps {
|
|
36
38
|
isEventEditProductSet?: boolean;
|
|
@@ -52,9 +54,7 @@ export const DateAndRecurrenceInput = ({
|
|
|
52
54
|
getValues,
|
|
53
55
|
setValue,
|
|
54
56
|
clearErrors,
|
|
55
|
-
} = useFormContext<
|
|
56
|
-
|
|
57
|
-
const steps = useWatch({ control, name: "steps" });
|
|
57
|
+
} = useFormContext<DateAndRecurrenceInputValues>();
|
|
58
58
|
|
|
59
59
|
const [availableTimes, setAvailableTimes] = useState<string[]>([]);
|
|
60
60
|
const availableTimesFormRef = useRef<AvailableTimesControlRef>();
|
|
@@ -101,13 +101,11 @@ export const DateAndRecurrenceInput = ({
|
|
|
101
101
|
const isAvailableTimesFormValid =
|
|
102
102
|
await availableTimesFormRef.current?.trigger();
|
|
103
103
|
|
|
104
|
-
const { availableTimes } = availableTimesFormRef.current.getValues();
|
|
105
|
-
|
|
106
104
|
if (next?.startTime && next?.endTime && isAvailableTimesFormValid) {
|
|
107
105
|
const startTime = DateTime.fromISO(next.startTime);
|
|
108
106
|
const endTime = DateTime.fromISO(next.endTime);
|
|
109
|
-
|
|
110
|
-
const
|
|
107
|
+
const { availableTimes } = availableTimesFormRef.current.getValues();
|
|
108
|
+
const validAvalilableTimes = availableTimes.every((time) => {
|
|
111
109
|
const currentAvailableTime = DateTime.fromFormat(time, TIME_FORMAT);
|
|
112
110
|
|
|
113
111
|
return (
|
|
@@ -115,8 +113,7 @@ export const DateAndRecurrenceInput = ({
|
|
|
115
113
|
currentAvailableTime.diff(endTime, "minutes").minutes <= 0
|
|
116
114
|
);
|
|
117
115
|
});
|
|
118
|
-
|
|
119
|
-
if (!areAvailableTimesValid) {
|
|
116
|
+
if (!validAvalilableTimes) {
|
|
120
117
|
availableTimesFormRef.current.setError("availableTimes", {
|
|
121
118
|
message: t("Validation:fieldTimeBetween", {
|
|
122
119
|
attribute: t("Design:startTimesSmall"),
|
|
@@ -129,36 +126,6 @@ export const DateAndRecurrenceInput = ({
|
|
|
129
126
|
}
|
|
130
127
|
}
|
|
131
128
|
|
|
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
|
-
|
|
162
129
|
const availableTime =
|
|
163
130
|
availableTimesFormRef?.current?.getValues()?.availableTimes || null;
|
|
164
131
|
|
|
@@ -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";
|
|
6
5
|
import {
|
|
7
6
|
ProductSetControl,
|
|
8
7
|
ProductSetControlProps,
|
|
9
8
|
ProductSetControlValues,
|
|
10
9
|
} 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,10 +22,14 @@ 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";
|
|
26
25
|
import { WarningMessage } from "../../static";
|
|
27
26
|
import { SelectItem } from "../../types/generic/SelectItem";
|
|
28
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
DateAndRecurrenceInput,
|
|
29
|
+
// TODO: Show Date Component, when reccurent date bugs are fixed
|
|
30
|
+
// DateAndRecurrenceInput,
|
|
31
|
+
DateAndRecurrenceInputValues,
|
|
32
|
+
} from "./DateAndRecurrenceInput";
|
|
29
33
|
import TutorialGifCard from "./TutorialGifCard";
|
|
30
34
|
import { Step } from "../types";
|
|
31
35
|
import { StepsControl } from "../form/StepsControl";
|
|
@@ -49,7 +53,7 @@ export interface TemplateItem {
|
|
|
49
53
|
label: string;
|
|
50
54
|
}
|
|
51
55
|
|
|
52
|
-
export interface ProductSetControlValues {
|
|
56
|
+
export interface ProductSetControlValues extends DateAndRecurrenceInputValues {
|
|
53
57
|
name: string;
|
|
54
58
|
type: ProductSetType;
|
|
55
59
|
termsAndConditions: string;
|
|
@@ -61,7 +65,6 @@ export interface ProductSetControlValues {
|
|
|
61
65
|
steps: Step[];
|
|
62
66
|
emailTemplates?: TemplateItem[];
|
|
63
67
|
smsTemplates?: TemplateItem[];
|
|
64
|
-
menuRecurrences?: Partial<ProductSetRecurrence>[];
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
export interface ProductSetControlShared {
|
|
@@ -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,
|
|
67
66
|
zoneRecurrences: [
|
|
68
67
|
{
|
|
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,6 +90,7 @@ 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"],
|
|
93
94
|
endDate: "2022-02-22",
|
|
94
95
|
endTime: "22:00:00",
|
|
95
96
|
id: 1,
|
|
@@ -1,5 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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,25 +0,0 @@
|
|
|
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];
|