@ikas/storefront 4.2.3 → 4.3.0-beta.2

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.
@@ -16,6 +16,7 @@ export { LoginForm } from "./validator/form/login";
16
16
  export { AddressForm } from "./validator/form/address";
17
17
  export { IkasAddressForm } from "./validator/form/ikas-address";
18
18
  export { RegisterForm } from "./validator/form/register";
19
+ export type { RegisterFormCustomerAttribute } from "./validator/form/register";
19
20
  export { ContactForm } from "./validator/form/contact-form";
20
21
  export { ForgotPasswordForm } from "./validator/form/forgot-password";
21
22
  export { RecoverPasswordForm } from "./validator/form/recover-password";
@@ -1,10 +1,11 @@
1
- import { IkasCustomerAttributeValue } from "../../../data";
1
+ import { IkasCustomerAttribute, IkasCustomerAttributeValue } from "../../../data";
2
+ declare type RegisterFormPropsValidatorMessage<T> = {
3
+ requiredRule: ((model: T) => string) | string;
4
+ emailRule: ((model: T) => string) | string;
5
+ minRule: ((model: T) => string) | string;
6
+ };
2
7
  declare type RegisterFormProps<T> = {
3
- message: {
4
- requiredRule: ((model: T) => string) | string;
5
- emailRule: ((model: T) => string) | string;
6
- minRule: ((model: T) => string) | string;
7
- };
8
+ message: RegisterFormPropsValidatorMessage<T>;
8
9
  };
9
10
  declare type RegisterFormModel = {
10
11
  firstName: string;
@@ -14,9 +15,26 @@ declare type RegisterFormModel = {
14
15
  attributes?: IkasCustomerAttributeValue[];
15
16
  isMarketingAccepted?: boolean;
16
17
  };
18
+ declare type AttributeValue = {
19
+ isChecked?: boolean;
20
+ value?: string;
21
+ selectedIdList?: string[];
22
+ };
23
+ export declare type RegisterFormCustomerAttribute = {
24
+ attribute: IkasCustomerAttribute;
25
+ attributeValue: AttributeValue;
26
+ validator: {
27
+ isRequired: boolean | undefined;
28
+ hasError: boolean | undefined;
29
+ message: string | undefined;
30
+ };
31
+ };
17
32
  export declare class RegisterForm {
18
33
  private model;
19
34
  private validator;
35
+ private message;
36
+ private isFormSubmit;
37
+ private _customerAttributes;
20
38
  constructor(props: RegisterFormProps<RegisterFormModel>);
21
39
  get firstName(): string;
22
40
  set firstName(value: string);
@@ -36,11 +54,17 @@ export declare class RegisterForm {
36
54
  get attributes(): IkasCustomerAttributeValue[] | undefined;
37
55
  set attributes(attributes: IkasCustomerAttributeValue[] | undefined);
38
56
  get redirect(): string | null | undefined;
57
+ get customerAttributes(): RegisterFormCustomerAttribute[] | undefined;
39
58
  onFirstNameChange: (value: string) => void;
40
59
  onLastNameChange: (value: string) => void;
41
60
  onEmailChange: (value: string) => void;
42
61
  onPasswordChange: (value: string) => void;
43
- validateAll(): Promise<boolean>;
62
+ setCustomerAttributes: (customerAttributes: IkasCustomerAttribute[]) => void;
63
+ private getAttributeValue;
64
+ onAttributeChange: (attributeId: string, value: boolean | string | string[]) => void;
65
+ private get formattedAttributesInput();
66
+ private validateCustomerAttribute;
67
+ validateAll(): Promise<boolean | undefined>;
44
68
  register(): Promise<{
45
69
  isFormError: boolean;
46
70
  isSuccess: boolean;
@@ -1 +1 @@
1
- import{__awaiter as e,__generator as t}from'./../../../../ext/tslib/tslib.es6.js';import{makeObservable as r,computed as s,observable as i,action as a}from"mobx";import{Validator as o}from"../index.js";import{IkasBaseStore as n}from"../../../../store/base.js";import"../../../../store/customer/index.js";import"../../../../store/cart/index.js";import{RequiredRule as l,EmailRule as u,MinRule as m}from"../rules/index.js";var d=function(){function d(e){var t=this;this.model={firstName:"",lastName:"",email:"",password:"",attributes:void 0,isMarketingAccepted:!1},this.onFirstNameChange=function(e){t.firstName=e},this.onLastNameChange=function(e){t.lastName=e},this.onEmailChange=function(e){t.email=e},this.onPasswordChange=function(e){t.password=e},r(this,{emailErrorMessage:s,passwordErrorMessage:s,firstNameErrorMessage:s,lastNameErrorMessage:s,hasError:s,redirect:s,model:i,validateAll:a,register:a}),this.validator=new o(this.model,[new l({fieldKey:"firstName",valuePath:"firstName",message:e.message.requiredRule}),new l({fieldKey:"lastName",valuePath:"lastName",message:e.message.requiredRule}),new l({fieldKey:"email",valuePath:"email",message:e.message.requiredRule}),new l({fieldKey:"password",valuePath:"password",message:e.message.requiredRule}),new u({fieldKey:"email",valuePath:"email",message:e.message.emailRule}),new m({fieldKey:"password",valuePath:"password",minValue:6,message:e.message.minRule})])}return Object.defineProperty(d.prototype,"firstName",{get:function(){return this.model.firstName},set:function(e){this.model.firstName=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"lastName",{get:function(){return this.model.lastName},set:function(e){this.model.lastName=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"email",{get:function(){return this.model.email},set:function(e){this.model.email=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"password",{get:function(){return this.model.password},set:function(e){this.model.password=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"isMarketingAccepted",{get:function(){return this.model.isMarketingAccepted},set:function(e){this.model.isMarketingAccepted=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"hasError",{get:function(){return this.validator.hasError},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"firstNameErrorMessage",{get:function(){return this.validator.results.firstName.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"lastNameErrorMessage",{get:function(){return this.validator.results.lastName.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"emailErrorMessage",{get:function(){return this.validator.results.email.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"passwordErrorMessage",{get:function(){return this.validator.results.password.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"attributes",{get:function(){return this.model.attributes},set:function(e){this.model.attributes=e},enumerable:!1,configurable:!0}),Object.defineProperty(d.prototype,"redirect",{get:function(){if("undefined"!=typeof window)return new URLSearchParams(window.location.search).get("redirect")},enumerable:!1,configurable:!0}),d.prototype.validateAll=function(){return this.validator.validateAll()},d.prototype.register=function(){return e(this,void 0,void 0,(function(){var e;return t(this,(function(t){switch(t.label){case 0:return e={isFormError:!1,isSuccess:!1},[4,this.validateAll()];case 1:if(t.sent())return e.isFormError=!0,[2,e];t.label=2;case 2:return t.trys.push([2,4,,5]),[4,n.getInstance().customerStore.register(this.model.firstName,this.model.lastName,this.model.email,this.model.password,this.model.isMarketingAccepted,this.model.attributes)];case 3:return t.sent()&&(e.isSuccess=!0),[2,e];case 4:return t.sent(),[2,e];case 5:return[2]}}))}))},d}();export{d as RegisterForm};
1
+ import{__awaiter as t,__generator as e}from'./../../../../ext/tslib/tslib.es6.js';import{makeObservable as r,computed as i,observable as a,action as s}from"mobx";import{Validator as o}from"../index.js";import{IkasBaseStore as n}from"../../../../store/base.js";import"../../../../store/customer/index.js";import"../../../../store/cart/index.js";import{RequiredRule as u,EmailRule as d,MinRule as m}from"../rules/index.js";import"../../../data/blog/category/index.js";import"../../../data/blog/content/index.js";import"../../../data/blog/meta-data/index.js";import"../../../data/blog/tag/index.js";import"../../../data/blog/index.js";import"../../../data/brand/index.js";import{IkasCustomerAttributeType as l,IkasCustomerAttributeRegisterPageRequirement as c}from"@ikas/storefront-models";import"../../../data/campaign-offer/index.js";import"../../../data/cart/campaign-offer/index.js";import"../../../data/cart/index.js";import"../../../data/category/path-item/index.js";import"../../../data/category/index.js";import"../../../data/checkout/index.js";import"../../../data/checkout/country-settings-model.js";import"../../../data/checkout-settings/index.js";import"../../../data/city/index.js";import"../../../data/country/index.js";import"../../../data/customer/address/index.js";import"../../../data/customer/address/ikas-localized-customer-address.js";import"../../../data/customer/attribute/index.js";import"../../../data/customer/review/summary/index.js";import"../../../data/customer/review/index.js";import"../../../data/customer/index.js";import"../../../data/district/index.js";import"../../../data/favorite-product/index.js";import"../../../data/filter-category/index.js";import"../../../data/html-meta-data/index.js";import"../../../data/image/index.js";import"../../../data/order/address/index.js";import"../../../data/order/line-item/option/value/index.js";import"../../../data/order/line-item/variant/value/index.js";import"../../../data/order/line-item/variant/index.js";import"../../../data/order/line-item/index.js";import"../../../data/order/package/index.js";import"../../../data/order/transaction/index.js";import"../../../data/order/index.js";import"../../../data/payment-gateway/index.js";import"../../../data/product/attribute-value/index.js";import"../../../data/product/filter/index.js";import"../../../data/product/option-set/option/index.js";import"../../../data/product/option-set/index.js";import"../../../data/product/stock-location/index.js";import"../../../data/product/variant/price/index.js";import"../../../data/product/variant/index.js";import"../../../data/variant-type/index.js";import"../../../data/product/index.js";import"../../../data/raffle/index.js";import"../../../data/state/index.js";import"../../../data/theme-json/index.js";import"../../../data/theme-json/custom-data/index.js";import"../../../data/variant-type/variant-value/index.js";var p=function(){function p(t){var e=this;this.model={firstName:"",lastName:"",email:"",password:"",attributes:void 0,isMarketingAccepted:!1},this.isFormSubmit=!1,this._customerAttributes=void 0,this.onFirstNameChange=function(t){e.firstName=t},this.onLastNameChange=function(t){e.lastName=t},this.onEmailChange=function(t){e.email=t},this.onPasswordChange=function(t){e.password=t},this.setCustomerAttributes=function(t){e._customerAttributes=(null==t?void 0:t.filter((function(t){return t.registerPageRequirement!==c.INVISIBLE})).map((function(t){return{attribute:t,attributeValue:{isChecked:void 0,value:void 0,selectedIdList:void 0},validator:{isRequired:t.registerPageRequirement===c.MANDATORY,hasError:!1,message:""}}})))||[]},this.onAttributeChange=function(t,r){var i;if(e._customerAttributes){var a=e._customerAttributes.find((function(e){return e.attribute.id===t}));if(a){var s=null===(i=e._customerAttributes)||void 0===i?void 0:i.findIndex((function(e){return e.attribute.id===t}));void 0!==s&&-1!==s&&(e._customerAttributes[s].attributeValue=e.getAttributeValue(a.attribute,r),e.validateCustomerAttribute())}}},r(this,{emailErrorMessage:i,passwordErrorMessage:i,firstNameErrorMessage:i,lastNameErrorMessage:i,hasError:i,redirect:i,model:a,validateAll:s,register:s,customerAttributes:i,_customerAttributes:a}),this.message=t.message,this.validator=new o(this.model,[new u({fieldKey:"firstName",valuePath:"firstName",message:t.message.requiredRule}),new u({fieldKey:"lastName",valuePath:"lastName",message:t.message.requiredRule}),new u({fieldKey:"email",valuePath:"email",message:t.message.requiredRule}),new u({fieldKey:"password",valuePath:"password",message:t.message.requiredRule}),new d({fieldKey:"email",valuePath:"email",message:t.message.emailRule}),new m({fieldKey:"password",valuePath:"password",minValue:6,message:t.message.minRule})])}return Object.defineProperty(p.prototype,"firstName",{get:function(){return this.model.firstName},set:function(t){this.model.firstName=t},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"lastName",{get:function(){return this.model.lastName},set:function(t){this.model.lastName=t},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"email",{get:function(){return this.model.email},set:function(t){this.model.email=t},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"password",{get:function(){return this.model.password},set:function(t){this.model.password=t},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"isMarketingAccepted",{get:function(){return this.model.isMarketingAccepted},set:function(t){this.model.isMarketingAccepted=t},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"hasError",{get:function(){return this.validator.hasError},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"firstNameErrorMessage",{get:function(){return this.validator.results.firstName.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"lastNameErrorMessage",{get:function(){return this.validator.results.lastName.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"emailErrorMessage",{get:function(){return this.validator.results.email.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"passwordErrorMessage",{get:function(){return this.validator.results.password.errorMessage},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"attributes",{get:function(){return this.model.attributes},set:function(t){this.model.attributes=t},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"redirect",{get:function(){if("undefined"!=typeof window)return new URLSearchParams(window.location.search).get("redirect")},enumerable:!1,configurable:!0}),Object.defineProperty(p.prototype,"customerAttributes",{get:function(){return this._customerAttributes},enumerable:!1,configurable:!0}),p.prototype.getAttributeValue=function(t,e){var r={isChecked:void 0,value:void 0,selectedIdList:void 0};if("string"!=typeof e||t.type!==l.TEXT&&t.type!==l.DATETIME&&t.type!==l.CHOICE||(r.value=e),"string"==typeof e&&t.type===l.NUMERIC){var i=parseInt(e);isNaN(i)?r.value=r.value||"":r.value=e}return"boolean"==typeof e&&t.type===l.BOOLEAN&&(r.isChecked=e),"object"==typeof e&&t.type===l.MULTIPLE_CHOICE&&(r.selectedIdList=e),r},Object.defineProperty(p.prototype,"formattedAttributesInput",{get:function(){if(!this._customerAttributes)return null;if(!this._customerAttributes.some((function(t){return void 0!==t.attributeValue.value||void 0!==t.attributeValue.isChecked||void 0!==t.attributeValue.selectedIdList})))return null;var t=[];return this._customerAttributes.map((function(e){var r=e.attributeValue,i=r.selectedIdList,a=r.isChecked,s=r.value;void 0!==i&&l.MULTIPLE_CHOICE&&i.map((function(r){t.push({customerAttributeId:e.attribute.id,customerAttributeOptionId:r,value:null})})),e.attribute.type===l.BOOLEAN&&t.push({customerAttributeId:e.attribute.id,customerAttributeOptionId:null,value:a?a.toString():"false"}),void 0!==s&&(e.attribute.type!==l.TEXT&&e.attribute.type!==l.NUMERIC||t.push({customerAttributeId:e.attribute.id,customerAttributeOptionId:null,value:s.toString()}),e.attribute.type===l.CHOICE&&t.push({customerAttributeId:e.attribute.id,customerAttributeOptionId:s,value:null}),e.attribute.type===l.DATETIME&&t.push({customerAttributeId:e.attribute.id,customerAttributeOptionId:null,value:new Date(s).getTime().toString()}))})),t},enumerable:!1,configurable:!0}),p.prototype.validateCustomerAttribute=function(){var t,e=this;this._customerAttributes=null===(t=this._customerAttributes)||void 0===t?void 0:t.map((function(t){var r;return t.validator.isRequired&&e.isFormSubmit&&(t.attributeValue.value||(null===(r=t.attributeValue.selectedIdList)||void 0===r?void 0:r.length)?(t.validator.hasError=!1,t.validator.message=""):(t.validator.hasError=!0,t.validator.message="string"==typeof e.message.requiredRule?e.message.requiredRule:e.message.requiredRule(e.model))),t}))},p.prototype.validateAll=function(){var r;return t(this,void 0,void 0,(function(){var t,i;return e(this,(function(e){switch(e.label){case 0:return this.validateCustomerAttribute(),[4,this.validator.validateAll()];case 1:return t=e.sent(),i=null===(r=this._customerAttributes)||void 0===r?void 0:r.some((function(t){return t.validator.hasError})),[2,t||i]}}))}))},p.prototype.register=function(){return t(this,void 0,void 0,(function(){var t;return e(this,(function(e){switch(e.label){case 0:return this.isFormSubmit=!0,t={isFormError:!1,isSuccess:!1},[4,this.validateAll()];case 1:if(e.sent())return t.isFormError=!0,[2,t];e.label=2;case 2:return e.trys.push([2,4,,5]),[4,n.getInstance().customerStore.register(this.model.firstName,this.model.lastName,this.model.email,this.model.password,this.model.isMarketingAccepted,this.model.attributes||this.formattedAttributesInput||void 0)];case 3:return e.sent()&&(t.isSuccess=!0),[2,t];case 4:return e.sent(),[2,t];case 5:return[2]}}))}))},p}();export{p as RegisterForm};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ikas/storefront",
3
- "version": "4.2.3",
3
+ "version": "4.3.0-beta.2",
4
4
  "description": "Storefront functionality for ikas storefront themes.",
5
5
  "author": "ikas",
6
6
  "license": "ISC",
@@ -18,11 +18,11 @@
18
18
  },
19
19
  "dependencies": {},
20
20
  "devDependencies": {
21
- "@ikas/storefront-api": "^4.2.3",
22
- "@ikas/storefront-config": "^4.2.3",
23
- "@ikas/storefront-model-functions": "^4.2.3",
24
- "@ikas/storefront-models": "^4.2.3",
25
- "@ikas/storefront-providers": "^4.2.3",
21
+ "@ikas/storefront-api": "^4.3.0-beta.2",
22
+ "@ikas/storefront-config": "^4.3.0-beta.2",
23
+ "@ikas/storefront-model-functions": "^4.3.0-beta.2",
24
+ "@ikas/storefront-models": "^4.3.0-beta.2",
25
+ "@ikas/storefront-providers": "^4.3.0-beta.2",
26
26
  "@rollup/plugin-commonjs": "^22.0.0",
27
27
  "@rollup/plugin-json": "^4.1.0",
28
28
  "@rollup/plugin-node-resolve": "^13.3.0",
@@ -52,11 +52,11 @@
52
52
  "libphonenumber-js": "^1.10.6"
53
53
  },
54
54
  "peerDependencies": {
55
- "@ikas/storefront-api": "^4.2.3",
56
- "@ikas/storefront-config": "^4.2.3",
57
- "@ikas/storefront-model-functions": "^4.2.3",
58
- "@ikas/storefront-models": "^4.2.3",
59
- "@ikas/storefront-providers": "^4.2.3",
55
+ "@ikas/storefront-api": "^4.3.0-beta.2",
56
+ "@ikas/storefront-config": "^4.3.0-beta.2",
57
+ "@ikas/storefront-model-functions": "^4.3.0-beta.2",
58
+ "@ikas/storefront-models": "^4.3.0-beta.2",
59
+ "@ikas/storefront-providers": "^4.3.0-beta.2",
60
60
  "mobx": "^6.1.3",
61
61
  "mobx-react-lite": "^3.1.5",
62
62
  "next": "12.2.0",