From e8d35a7854765ffeee249d86f91dbdcac8446444 Mon Sep 17 00:00:00 2001 From: mythilytm Date: Thu, 24 Oct 2024 18:02:02 -0400 Subject: [PATCH] clean up error handling --- .../src/components/search/SearchForm/index.tsx | 2 +- plugin-hrm-form/src/utils/task.ts | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/plugin-hrm-form/src/components/search/SearchForm/index.tsx b/plugin-hrm-form/src/components/search/SearchForm/index.tsx index 7fc52126ba..890e9d3087 100644 --- a/plugin-hrm-form/src/components/search/SearchForm/index.tsx +++ b/plugin-hrm-form/src/components/search/SearchForm/index.tsx @@ -151,7 +151,7 @@ const SearchForm: React.FC = ({ [channelTypes.voice]: 'PreviousContacts-PhoneNumber', [channelTypes.sms]: 'PreviousContacts-PhoneNumber', [channelTypes.whatsapp]: 'PreviousContacts-WhatsappNumber', - [channelTypes.messenger]: 'PreviousContacts-FacebookUser', + [channelTypes.facebook]: 'PreviousContacts-FacebookUser', [channelTypes.telegram]: 'PreviousContacts-TelegramUser', [channelTypes.instagram]: 'PreviousContacts-InstagramUser', [channelTypes.line]: 'PreviousContacts-LineUser', diff --git a/plugin-hrm-form/src/utils/task.ts b/plugin-hrm-form/src/utils/task.ts index 920bc6d345..28ae63d05a 100644 --- a/plugin-hrm-form/src/utils/task.ts +++ b/plugin-hrm-form/src/utils/task.ts @@ -58,20 +58,13 @@ export const getNumberFromTask = (task: CustomITask) => { return getContactValueFromWebchat(task); } - const transformedNumber = channelTransformations[channelType as ChannelTypes]; - - // Ensure transformedNumber is an array before calling reduce - if ((!Array.isArray(transformedNumber) || transformedNumber.length === 0) && channelType !== undefined) { - console.error(`Channel type ${channelType} is not supported or transformation array is invalid`, transformedNumber); - return null; - } - - if (defaultFrom === undefined || defaultFrom === null || !defaultFrom) { - console.error(`defaultFrom is undefined for channelType ${channelType}`); + if (!channelTransformations[channelType] && channelType !== 'undefined') { + console.error(`Channel type ${channelType} is not supported`); return null; } - return transformedNumber.reduce((accum, f) => f(accum), defaultFrom); + // otherwise, return the "defaultFrom" with the transformations on the identifier corresponding to each channel + return channelTransformations[channelType as ChannelTypes].reduce((accum, f) => f(accum), defaultFrom); }; /**