Skip to content

Commit

Permalink
Fix issue in updating and retrieving street address in user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
DonOmalVindula committed Sep 9, 2024
1 parent fc756dc commit a53f2d9
Showing 1 changed file with 50 additions and 15 deletions.
65 changes: 50 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,31 @@ 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];

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,
Expand Down Expand Up @@ -795,15 +815,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 +863,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 a53f2d9

Please sign in to comment.