Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support custom fields in user-profile-widget + Edit/Delete flows #843

Merged
merged 27 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
170f145
Support custom fields in user-profile-widget
Nitzperetz Nov 10, 2024
88ebdf4
Merge branch 'main' into feat/user_profile_widget_add_custom_fields
Nitzperetz Nov 10, 2024
84f8ed4
getCustomAttributes in higher scope
Nitzperetz Nov 10, 2024
5580e33
Update tsconfig.json
Nitzperetz Nov 10, 2024
24279c9
getCustomAttributes add subscribe
Nitzperetz Nov 10, 2024
97db9a6
Merge branch 'feat/user_profile_widget_add_custom_fields' of github.c…
Nitzperetz Nov 10, 2024
acadf65
getCustomAttributes add cache
Nitzperetz Nov 11, 2024
b784625
update func for custom fields display and package.json start for reac…
Nitzperetz Nov 12, 2024
0332f05
Update package.json
Nitzperetz Nov 12, 2024
c57559b
Merge branch 'main' into feat/user_profile_widget_add_custom_fields
Nitzperetz Nov 12, 2024
baa58d3
Merge branch 'main' into feat/user_profile_widget_add_custom_fields
nirgur Nov 12, 2024
22b0eac
edit/delete flows in user custom attributes field
Nitzperetz Nov 20, 2024
67a460e
Merge branch 'feat/user_profile_widget_add_custom_fields' of github.c…
Nitzperetz Nov 20, 2024
347fe6d
update from main
Nitzperetz Nov 20, 2024
80f27d8
update from main
Nitzperetz Nov 20, 2024
d0925fe
cov
Nitzperetz Nov 20, 2024
8e4f22e
Merge branch 'main' into feat/user_profile_widget_add_custom_fields
Nitzperetz Nov 26, 2024
3900167
extract functions
Nitzperetz Nov 27, 2024
c0c835e
Merge branch 'feat/user_profile_widget_add_custom_fields' of github.c…
Nitzperetz Nov 27, 2024
4a291bc
Add custom fields route and use for custom fields mixin
Nitzperetz Dec 1, 2024
2023969
cr comments - adding tests and some refactoring.
Nitzperetz Dec 2, 2024
a7dcc9c
remove API and use data-type
Nitzperetz Dec 2, 2024
a4485dd
Merge branch 'main' into feat/user_profile_widget_add_custom_fields
Nitzperetz Dec 2, 2024
5a47c1d
extract func
Nitzperetz Dec 2, 2024
b259448
Merge branches 'feat/user_profile_widget_add_custom_fields' and 'feat…
Nitzperetz Dec 2, 2024
0fd266a
lock
nirgur Dec 2, 2024
e0cb78b
update pnpm
Nitzperetz Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/sdks/react-sdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"noErrorTruncation": true,
},
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", "build", "dist", "test", "examples"]
"exclude": ["node_modules", "build", "dist", "test"]
Nitzperetz marked this conversation as resolved.
Show resolved Hide resolved
}
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;
Nitzperetz marked this conversation as resolved.
Show resolved Hide resolved

#initCustomValueUserAttrs() {
Nitzperetz marked this conversation as resolved.
Show resolved Hide resolved
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);
Nitzperetz marked this conversation as resolved.
Show resolved Hide resolved
compInstance.value = userCustomAttributesData[customAttrName];
Nitzperetz marked this conversation as resolved.
Show resolved Hide resolved
});
}

async onWidgetRootReady() {
await super.onWidgetRootReady?.();

this.#initCustomValueUserAttrs();
}
},
);
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { compose, createSingletonMixin } from '@descope/sdk-helpers';
import { debuggerMixin, themeMixin } from '@descope/sdk-mixins';
import { flowRedirectUrlMixin } from '../flowRedirectUrlMixin';
import { initAvatarMixin } from './initComponentsMixins/initAvatarMixin';
import { initEmailUserAttrMixin } from './initComponentsMixins/initEmailUserAttrMixin';
import { initLogoutMixin } from './initComponentsMixins/initLogoutMixin';
import { initNameUserAttrMixin } from './initComponentsMixins/initNameUserAttrMixin';
import { initPhoneUserAttrMixin } from './initComponentsMixins/initPhoneUserAttrMixin';
import { initPasskeyUserAuthMethodMixin } from './initComponentsMixins/initPasskeyUserAuthMethodMixin';
import { initPasswordUserAuthMethodMixin } from './initComponentsMixins/initPasswordUserAuthMethodMixin';
import { initLogoutMixin } from './initComponentsMixins/initLogoutMixin';
import { flowRedirectUrlMixin } from '../flowRedirectUrlMixin';
import { initPhoneUserAttrMixin } from './initComponentsMixins/initPhoneUserAttrMixin';
import { initUserCustomAttributesMixin } from './initComponentsMixins/initUserCustomAttributesMixin';

export const initMixin = createSingletonMixin(
<T extends CustomElementConstructor>(superclass: T) =>
Expand All @@ -16,6 +17,7 @@ export const initMixin = createSingletonMixin(
debuggerMixin,
themeMixin,
flowRedirectUrlMixin, // This mixin must be before all other mixins that loads flows
initUserCustomAttributesMixin,
initEmailUserAttrMixin,
initAvatarMixin,
initNameUserAttrMixin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ export const getIsPhoneVerified = createSelector(
);
export const getHasPasskey = createSelector(getMe, (me) => me.webauthn);
export const getHasPassword = createSelector(getMe, (me) => me.password);

export const getUserCustomAttrs = createSelector(
getMe,
(me) => me.customAttributes,
);
Loading