Skip to content

Commit

Permalink
Fix delete primary value
Browse files Browse the repository at this point in the history
  • Loading branch information
PasinduYeshan committed Feb 6, 2025
1 parent d3f4494 commit 5a219c2
Showing 1 changed file with 39 additions and 33 deletions.
72 changes: 39 additions & 33 deletions features/admin.users.v1/components/user-profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1572,12 +1572,29 @@ export const UserProfile: FunctionComponent<UserProfilePropsInterface> = (
const handleMultiValuedItemDelete = (schema: ProfileSchemaInterface, attributeValue: string) => {

const filteredValues: string[] =
multiValuedAttributeValues[schema?.name]?.filter((value: string) => value !== attributeValue);
multiValuedAttributeValues[schema?.name]?.filter((value: string) => value !== attributeValue) || [];

setMultiValuedAttributeValues({
...multiValuedAttributeValues,
setMultiValuedAttributeValues((prevValues: Record<string, string[]>) => ({
...prevValues,
[schema.name]: filteredValues
});
}));

if (schema.name === EMAIL_ADDRESSES_ATTRIBUTE) {
if (primaryValues[EMAIL_ATTRIBUTE] === attributeValue) {
setPrimaryValues((prevPrimaryValues: Record<string, string>) => ({
...prevPrimaryValues,
[EMAIL_ATTRIBUTE]: ""
}));
}
} else if (schema.name === MOBILE_NUMBERS_ATTRIBUTE) {
if (primaryValues[MOBILE_ATTRIBUTE] === attributeValue) {
setPrimaryValues((prevPrimaryValues: Record<string, string>) => ({
...prevPrimaryValues,
[MOBILE_ATTRIBUTE]: ""
}));
}
}

setIsFormStale(true);
};

Expand Down Expand Up @@ -1671,10 +1688,10 @@ export const UserProfile: FunctionComponent<UserProfilePropsInterface> = (
*/
const handleMakePrimary = (schemaName: string, attributeValue: string) => {

setPrimaryValues({
...primaryValues,
setPrimaryValues((prevPrimaryValues: Record<string, string>) => ({
...prevPrimaryValues,
[schemaName]: attributeValue
});
}));
setIsFormStale(true);
};

Expand All @@ -1687,36 +1704,25 @@ export const UserProfile: FunctionComponent<UserProfilePropsInterface> = (
const handleAddMultiValuedItem = (schema: ProfileSchemaInterface, attributeValue: string) => {

if (isEmpty(attributeValue)) return;
setMultiValuedAttributeValues({
...multiValuedAttributeValues,
[schema.name]: [
...multiValuedAttributeValues[schema.name],
attributeValue
]
});

if (schema.name === EMAIL_ADDRESSES_ATTRIBUTE) {
const existingPrimaryEmail: string = profileInfo?.get(EMAIL_ATTRIBUTE);
setMultiValuedAttributeValues((prevValues: Record<string, string[]>) => ({
...prevValues,
[schema.name]: [ ...(prevValues[schema.name] || []), attributeValue ]
}));

if (isEmpty(existingPrimaryEmail)) {
setPrimaryValues(
{
...primaryValues,
[EMAIL_ATTRIBUTE]: attributeValue
}
);
const updatePrimaryValue = (primaryKey: string) => {
if (isEmpty(primaryValues[primaryKey])) {
setPrimaryValues((prevPrimaryValues: Record<string, string>) => ({
...prevPrimaryValues,
[primaryKey]: attributeValue
}));
}
} else if (schema.name === MOBILE_NUMBERS_ATTRIBUTE) {
const existingPrimaryMobile: string = profileInfo?.get(MOBILE_ATTRIBUTE);
};

if (isEmpty(existingPrimaryMobile)) {
setPrimaryValues(
{
...primaryValues,
[MOBILE_ATTRIBUTE]: attributeValue
}
);
}
if (schema.name === EMAIL_ADDRESSES_ATTRIBUTE) {
updatePrimaryValue(EMAIL_ATTRIBUTE);
} else if (schema.name === MOBILE_NUMBERS_ATTRIBUTE) {
updatePrimaryValue(MOBILE_ATTRIBUTE);
}
setIsFormStale(true);
};
Expand Down

0 comments on commit 5a219c2

Please sign in to comment.