Chore: Migrate REST API - getCustomFields to Typescript (#3856)
* Chore: Migrate REST API - getCustomFields to Typescript * minor tweak
This commit is contained in:
parent
9becdf564e
commit
c758fa5c9f
|
@ -103,6 +103,8 @@ export type OmnichannelEndpoints = {
|
||||||
{
|
{
|
||||||
_id: string;
|
_id: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
visibility?: string;
|
||||||
|
scope?: string;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}>;
|
}>;
|
||||||
|
|
|
@ -47,12 +47,6 @@ interface ITitle {
|
||||||
theme: string;
|
theme: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IField {
|
|
||||||
_id: string;
|
|
||||||
visibility: string;
|
|
||||||
scope: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IInputs {
|
interface IInputs {
|
||||||
livechatData: {
|
livechatData: {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
|
@ -115,17 +109,17 @@ const LivechatEditView = ({
|
||||||
const visitor = route.params?.roomUser ?? {};
|
const visitor = route.params?.roomUser ?? {};
|
||||||
|
|
||||||
const getCustomFields = async () => {
|
const getCustomFields = async () => {
|
||||||
const result: any = await RocketChat.getCustomFields();
|
const result = await RocketChat.getCustomFields();
|
||||||
if (result.success && result.customFields?.length) {
|
if (result.success && result.customFields?.length) {
|
||||||
const visitorCustomFields = result.customFields
|
const visitorCustomFields = result.customFields
|
||||||
.filter((field: IField) => field.visibility !== 'hidden' && field.scope === 'visitor')
|
.filter(field => field.visibility !== 'hidden' && field.scope === 'visitor')
|
||||||
.map((field: IField) => ({ [field._id]: (visitor.livechatData && visitor.livechatData[field._id]) || '' }))
|
.map(field => ({ [field._id]: (visitor.livechatData && visitor.livechatData[field._id]) || '' }))
|
||||||
.reduce((ret: IField, field: IField) => ({ ...field, ...ret }));
|
.reduce((ret, field) => ({ ...field, ...ret }), {});
|
||||||
|
|
||||||
const livechatCustomFields = result.customFields
|
const livechatCustomFields = result.customFields
|
||||||
.filter((field: IField) => field.visibility !== 'hidden' && field.scope === 'room')
|
.filter(field => field.visibility !== 'hidden' && field.scope === 'room')
|
||||||
.map((field: IField) => ({ [field._id]: (livechat.livechatData && livechat.livechatData[field._id]) || '' }))
|
.map(field => ({ [field._id]: (livechat.livechatData && livechat.livechatData[field._id]) || '' }))
|
||||||
.reduce((ret: IField, field: IField) => ({ ...field, ...ret }));
|
.reduce((ret, field) => ({ ...field, ...ret }), {});
|
||||||
|
|
||||||
return setCustomFields({ visitor: visitorCustomFields, livechat: livechatCustomFields });
|
return setCustomFields({ visitor: visitorCustomFields, livechat: livechatCustomFields });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue