Skip to content

Commit

Permalink
Merge pull request #6879 from DonOmalVindula/fix/19638
Browse files Browse the repository at this point in the history
Fix issue in updating and retrieving street address in user profile
  • Loading branch information
DonOmalVindula authored Sep 9, 2024
2 parents c9946e0 + 7472abc commit 38870c5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-dolphins-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wso2is/admin.users.v1": patch
---

Fix issue in updating and retrieving street address in user profile
66 changes: 51 additions & 15 deletions features/admin.users.v1/components/user-profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,32 @@ export const UserProfile: FunctionComponent<UserProfilePropsInterface> = (
.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,
Expand Down Expand Up @@ -795,15 +816,30 @@ export const UserProfile: FunctionComponent<UserProfilePropsInterface> = (
}
);
} 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]]: [
Expand All @@ -828,7 +864,7 @@ export const UserProfile: FunctionComponent<UserProfilePropsInterface> = (
};
// 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);
Expand Down

0 comments on commit 38870c5

Please sign in to comment.