-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom fields in user-profile-widget
- Loading branch information
1 parent
6c990bf
commit 170f145
Showing
5 changed files
with
52 additions
and
4 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
41 changes: 41 additions & 0 deletions
41
...get/src/lib/widget/mixins/initMixin/initComponentsMixins/initUserCustomAttributesMixin.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { UserAttributeDriver } from '@descope/sdk-component-drivers'; | ||
import { compose, createSingletonMixin } from '@descope/sdk-helpers'; | ||
import { loggerMixin } from '@descope/sdk-mixins'; | ||
import { getUserCustomAttrs } from '../../../state/selectors'; | ||
import { stateManagementMixin } from '../../stateManagementMixin'; | ||
import { initWidgetRootMixin } from './initWidgetRootMixin'; | ||
|
||
export const initUserCustomAttributesMixin = createSingletonMixin( | ||
<T extends CustomElementConstructor>(superclass: T) => | ||
class UserCustomAttributesMixinClass extends compose( | ||
stateManagementMixin, | ||
loggerMixin, | ||
initWidgetRootMixin, | ||
)(superclass) { | ||
customValueUserAttr: UserAttributeDriver; | ||
|
||
#initCustomValueUserAttrs() { | ||
const allCustomAttributesComponents = this.shadowRoot?.querySelectorAll( | ||
'descope-user-attribute[data-id^="customAttributes."]', | ||
); | ||
|
||
Array.from(allCustomAttributesComponents).forEach((nodeEle) => { | ||
const attrName = nodeEle.getAttribute('data-id'); | ||
const customAttrName = attrName.replace('customAttributes.', ''); | ||
|
||
const compInstance = new UserAttributeDriver(nodeEle, { | ||
logger: this.logger, | ||
}); | ||
|
||
const userCustomAttributesData = getUserCustomAttrs(this.state); | ||
compInstance.value = userCustomAttributesData[customAttrName]; | ||
}); | ||
} | ||
|
||
async onWidgetRootReady() { | ||
await super.onWidgetRootReady?.(); | ||
|
||
this.#initCustomValueUserAttrs(); | ||
} | ||
}, | ||
); |
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
File renamed without changes.