-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PAYMENTS-18330): form loaded event
- Loading branch information
Showing
16 changed files
with
149 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export enum FieldsType { | ||
text = 'text', | ||
check = 'check', | ||
select = 'select', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { singleton } from 'tsyringe'; | ||
import { Field } from './field.interface'; | ||
import { FieldsType } from './fields-type.enum'; | ||
|
||
@singleton() | ||
export class FormLoader { | ||
private _fields!: { [key: string]: boolean }; | ||
private _isAllFieldsLoaded!: Promise<void>; | ||
|
||
private _resolve!: () => void; | ||
private _isPromiseResolved = false; | ||
|
||
public async setupAndAwaitFieldsLoading(fields: Field[]): Promise<void> { | ||
this._isAllFieldsLoaded = new Promise((resolve) => { | ||
this._resolve = () => { | ||
resolve(); | ||
}; | ||
}); | ||
|
||
this._isPromiseResolved = false; | ||
this._fields = {}; | ||
|
||
const filteredFields = this.filterFields(fields); | ||
|
||
const isFormWithoutFields = !filteredFields.length; | ||
|
||
if (isFormWithoutFields) { | ||
this._resolve(); | ||
this._isPromiseResolved = true; | ||
} | ||
|
||
filteredFields.forEach((field) => { | ||
this._fields[field.name] = false; | ||
}); | ||
|
||
return this._isAllFieldsLoaded; | ||
} | ||
|
||
public setFieldLoaded(name: string): void { | ||
if (name in this._fields) { | ||
this._fields[name] = true; | ||
} | ||
|
||
if (this.isAllFieldsLoaded && !this._isPromiseResolved) { | ||
this._resolve(); | ||
this._isPromiseResolved = true; | ||
} | ||
} | ||
|
||
private get isAllFieldsLoaded(): boolean { | ||
return Object.values(this._fields).every((value) => value); | ||
} | ||
|
||
private filterFields(fields: Field[]): Field[] { | ||
return fields.filter((field) => { | ||
const isTextControl = field.type === FieldsType.text; | ||
const isCheckboxControl = field.type === FieldsType.check; | ||
const isSelectControl = field.type === FieldsType.select; | ||
const isQrCodeControl = field.name === 'qr'; | ||
|
||
return ( | ||
isTextControl || isCheckboxControl || isSelectControl || isQrCodeControl | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 14 additions & 10 deletions
24
src/features/headless-checkout/web-components/qr-code/qr-code.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.