From c758fa5c9f6cb5fa08cc475b84f3755bd09288b3 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Tue, 8 Mar 2022 11:37:38 -0300 Subject: [PATCH] Chore: Migrate REST API - getCustomFields to Typescript (#3856) * Chore: Migrate REST API - getCustomFields to Typescript * minor tweak --- app/definitions/rest/v1/omnichannel.ts | 2 ++ app/views/LivechatEditView.tsx | 20 +++++++------------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/app/definitions/rest/v1/omnichannel.ts b/app/definitions/rest/v1/omnichannel.ts index 4d2350c9..c34963a5 100644 --- a/app/definitions/rest/v1/omnichannel.ts +++ b/app/definitions/rest/v1/omnichannel.ts @@ -103,6 +103,8 @@ export type OmnichannelEndpoints = { { _id: string; label: string; + visibility?: string; + scope?: string; } ]; }>; diff --git a/app/views/LivechatEditView.tsx b/app/views/LivechatEditView.tsx index f590463c..39e893e7 100644 --- a/app/views/LivechatEditView.tsx +++ b/app/views/LivechatEditView.tsx @@ -47,12 +47,6 @@ interface ITitle { theme: string; } -interface IField { - _id: string; - visibility: string; - scope: string; -} - interface IInputs { livechatData: { [key: string]: any; @@ -115,17 +109,17 @@ const LivechatEditView = ({ const visitor = route.params?.roomUser ?? {}; const getCustomFields = async () => { - const result: any = await RocketChat.getCustomFields(); + const result = await RocketChat.getCustomFields(); if (result.success && result.customFields?.length) { const visitorCustomFields = result.customFields - .filter((field: IField) => field.visibility !== 'hidden' && field.scope === 'visitor') - .map((field: IField) => ({ [field._id]: (visitor.livechatData && visitor.livechatData[field._id]) || '' })) - .reduce((ret: IField, field: IField) => ({ ...field, ...ret })); + .filter(field => field.visibility !== 'hidden' && field.scope === 'visitor') + .map(field => ({ [field._id]: (visitor.livechatData && visitor.livechatData[field._id]) || '' })) + .reduce((ret, field) => ({ ...field, ...ret }), {}); const livechatCustomFields = result.customFields - .filter((field: IField) => field.visibility !== 'hidden' && field.scope === 'room') - .map((field: IField) => ({ [field._id]: (livechat.livechatData && livechat.livechatData[field._id]) || '' })) - .reduce((ret: IField, field: IField) => ({ ...field, ...ret })); + .filter(field => field.visibility !== 'hidden' && field.scope === 'room') + .map(field => ({ [field._id]: (livechat.livechatData && livechat.livechatData[field._id]) || '' })) + .reduce((ret, field) => ({ ...field, ...ret }), {}); return setCustomFields({ visitor: visitorCustomFields, livechat: livechatCustomFields }); }