From a53f2d9cdc1da76913ca717c86de91103dbb0fb4 Mon Sep 17 00:00:00 2001 From: DonOmalVindula Date: Mon, 9 Sep 2024 16:29:30 +0530 Subject: [PATCH 1/4] Fix issue in updating and retrieving street address in user profile --- .../components/user-profile.tsx | 65 ++++++++++++++----- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/features/admin.users.v1/components/user-profile.tsx b/features/admin.users.v1/components/user-profile.tsx index 2f92409a851..d9b058f39d5 100644 --- a/features/admin.users.v1/components/user-profile.tsx +++ b/features/admin.users.v1/components/user-profile.tsx @@ -366,11 +366,31 @@ export const UserProfile: FunctionComponent = ( .find((subAttribute: MultiValueAttributeInterface) => subAttribute.type === schemaSecondaryProperty); - if (schemaName === "addresses") { - tempProfileInfo.set( - schema.name, - subValue ? subValue.formatted : "" - ); + if (schemaName.includes("addresses")) { + // Ex: addresses#home.streetAddress + const addressSubSchema: string = schema?.name?.split(".")[1]; + + if (schemaName.split("#").length > 1) { + // Ex: addresses#home + const addressSchema: string = schemaName.split("#")[0]; + const addressType: string = schemaName.split("#")[1]; + + const subValue: SubValueInterface = userInfo[addressSchema] && + Array.isArray(userInfo[addressSchema]) && + userInfo[addressSchema] + .find((subAttribute: MultiValueAttributeInterface) => + subAttribute.type === addressType); + + tempProfileInfo.set( + schema.name, + subValue[addressSubSchema] ? subValue[addressSubSchema] : "" + ); + } else { + tempProfileInfo.set( + schema.name, + subValue ? subValue.formatted : "" + ); + } } else { tempProfileInfo.set( schema.name, @@ -795,15 +815,30 @@ export const UserProfile: FunctionComponent = ( } ); } else { - if (schemaNames[0] === "addresses") { - opValue = { - [schemaNames[0]]: [ - { - formatted: values.get(schema.name), - type: schemaNames[1] - } - ] - }; + if (schemaNames[0].includes("addresses")) { + if (schemaNames[0].split("#").length > 1) { + // Ex: addresses#home + const addressSchema: string = schemaNames[0]?.split("#")[0]; + const addressType: string = schemaNames[0]?.split("#")[1]; + + opValue = { + [addressSchema]: [ + { + type: addressType, + [schemaNames[1]]: values.get(schema.name) + } + ] + }; + } else { + opValue = { + [schemaNames[0]]: [ + { + formatted: values.get(schema.name), + type: schemaNames[1] + } + ] + }; + } } else if (schemaNames[0] !== "emails" && schemaNames[0] !== "phoneNumbers") { opValue = { [schemaNames[0]]: [ @@ -828,7 +863,7 @@ export const UserProfile: FunctionComponent = ( }; // This is required as the api doesn't support patching the address attributes at the // sub attribute level using 'replace' operation. - if (schemaNames[0] === "addresses") { + if (schemaNames[0].includes("addresses")) { operation.op = "add"; } data.Operations.push(operation); From 03ce70a9ce524dcc2b7176784077de5c478ebf0f Mon Sep 17 00:00:00 2001 From: DonOmalVindula Date: Mon, 9 Sep 2024 16:31:34 +0530 Subject: [PATCH 2/4] Add changeset --- .changeset/poor-dolphins-peel.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/poor-dolphins-peel.md diff --git a/.changeset/poor-dolphins-peel.md b/.changeset/poor-dolphins-peel.md new file mode 100644 index 00000000000..d3a4c1b702e --- /dev/null +++ b/.changeset/poor-dolphins-peel.md @@ -0,0 +1,5 @@ +--- +"@wso2is/admin.users.v1": patch +--- + +Fix issue in updating and retrieving street address in user profile From edc03124609a6baf190f5d770efbfb2d3cecbbb5 Mon Sep 17 00:00:00 2001 From: DonOmalVindula Date: Mon, 9 Sep 2024 16:43:37 +0530 Subject: [PATCH 3/4] Add null checks --- features/admin.users.v1/components/user-profile.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/features/admin.users.v1/components/user-profile.tsx b/features/admin.users.v1/components/user-profile.tsx index d9b058f39d5..c7cbd8cf4fb 100644 --- a/features/admin.users.v1/components/user-profile.tsx +++ b/features/admin.users.v1/components/user-profile.tsx @@ -369,11 +369,12 @@ export const UserProfile: FunctionComponent = ( if (schemaName.includes("addresses")) { // Ex: addresses#home.streetAddress const addressSubSchema: string = schema?.name?.split(".")[1]; + const addressSchemaArray: string[] = schemaName?.split("."); - if (schemaName.split("#").length > 1) { + if (addressSchemaArray.length > 1) { // Ex: addresses#home - const addressSchema: string = schemaName.split("#")[0]; - const addressType: string = schemaName.split("#")[1]; + const addressSchema: string = addressSchemaArray[0]; + const addressType: string = addressSchemaArray[1]; const subValue: SubValueInterface = userInfo[addressSchema] && Array.isArray(userInfo[addressSchema]) && @@ -383,7 +384,7 @@ export const UserProfile: FunctionComponent = ( tempProfileInfo.set( schema.name, - subValue[addressSubSchema] ? subValue[addressSubSchema] : "" + (subValue && subValue[addressSubSchema]) ? subValue[addressSubSchema] : "" ); } else { tempProfileInfo.set( From 7472abc6e60beb1dd1db7da87ca03cee8a6ba093 Mon Sep 17 00:00:00 2001 From: DonOmalVindula Date: Mon, 9 Sep 2024 17:28:11 +0530 Subject: [PATCH 4/4] Fix bug --- features/admin.users.v1/components/user-profile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/admin.users.v1/components/user-profile.tsx b/features/admin.users.v1/components/user-profile.tsx index c7cbd8cf4fb..ea690948348 100644 --- a/features/admin.users.v1/components/user-profile.tsx +++ b/features/admin.users.v1/components/user-profile.tsx @@ -369,7 +369,7 @@ export const UserProfile: FunctionComponent = ( if (schemaName.includes("addresses")) { // Ex: addresses#home.streetAddress const addressSubSchema: string = schema?.name?.split(".")[1]; - const addressSchemaArray: string[] = schemaName?.split("."); + const addressSchemaArray: string[] = schemaName?.split("#"); if (addressSchemaArray.length > 1) { // Ex: addresses#home