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 diff --git a/features/admin.users.v1/components/user-profile.tsx b/features/admin.users.v1/components/user-profile.tsx index 2f92409a851..ea690948348 100644 --- a/features/admin.users.v1/components/user-profile.tsx +++ b/features/admin.users.v1/components/user-profile.tsx @@ -366,11 +366,32 @@ 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]; + const addressSchemaArray: string[] = schemaName?.split("#"); + + if (addressSchemaArray.length > 1) { + // Ex: addresses#home + const addressSchema: string = addressSchemaArray[0]; + const addressType: string = addressSchemaArray[1]; + + const subValue: SubValueInterface = userInfo[addressSchema] && + Array.isArray(userInfo[addressSchema]) && + userInfo[addressSchema] + .find((subAttribute: MultiValueAttributeInterface) => + subAttribute.type === addressType); + + tempProfileInfo.set( + schema.name, + (subValue && subValue[addressSubSchema]) ? subValue[addressSubSchema] : "" + ); + } else { + tempProfileInfo.set( + schema.name, + subValue ? subValue.formatted : "" + ); + } } else { tempProfileInfo.set( schema.name, @@ -795,15 +816,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 +864,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);