|
|
|
|
@ -5,7 +5,14 @@ import type { ReactElement, Dispatch, SetStateAction } from 'react'; |
|
|
|
|
import React, { useEffect } from 'react'; |
|
|
|
|
import { Controller, useForm } from 'react-hook-form'; |
|
|
|
|
|
|
|
|
|
import { Contextualbar, ContextualbarScrollableContent, ContextualbarHeader, ContextualbarClose } from '../../../components/Contextualbar'; |
|
|
|
|
import { |
|
|
|
|
Contextualbar, |
|
|
|
|
ContextualbarScrollableContent, |
|
|
|
|
ContextualbarHeader, |
|
|
|
|
ContextualbarClose, |
|
|
|
|
ContextualbarDialog, |
|
|
|
|
ContextualbarTitle, |
|
|
|
|
} from '../../../components/Contextualbar'; |
|
|
|
|
|
|
|
|
|
type CustomFieldsListProps = { |
|
|
|
|
setCustomFields: Dispatch<SetStateAction<{ [key: string]: string } | undefined>>; |
|
|
|
|
@ -26,44 +33,46 @@ const CustomFieldsList = ({ setCustomFields, allCustomFields }: CustomFieldsList |
|
|
|
|
const currentChatsRoute = useRoute('omnichannel-current-chats'); |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<Contextualbar> |
|
|
|
|
<ContextualbarHeader> |
|
|
|
|
{t('Filter_by_Custom_Fields')} |
|
|
|
|
<ContextualbarClose onClick={(): void => currentChatsRoute.push({ context: '' })} /> |
|
|
|
|
</ContextualbarHeader> |
|
|
|
|
<ContextualbarScrollableContent is='form'> |
|
|
|
|
{/* TODO: REMOVE FILTER ONCE THE ENDPOINT SUPPORTS A SCOPE PARAMETER */} |
|
|
|
|
{allCustomFields |
|
|
|
|
.filter((customField) => customField.scope !== 'visitor') |
|
|
|
|
.map((customField: ILivechatCustomField) => { |
|
|
|
|
if (customField.type === 'select') { |
|
|
|
|
<ContextualbarDialog> |
|
|
|
|
<Contextualbar> |
|
|
|
|
<ContextualbarHeader> |
|
|
|
|
<ContextualbarTitle>{t('Filter_by_Custom_Fields')}</ContextualbarTitle> |
|
|
|
|
<ContextualbarClose onClick={(): void => currentChatsRoute.push({ context: '' })} /> |
|
|
|
|
</ContextualbarHeader> |
|
|
|
|
<ContextualbarScrollableContent is='form'> |
|
|
|
|
{/* TODO: REMOVE FILTER ONCE THE ENDPOINT SUPPORTS A SCOPE PARAMETER */} |
|
|
|
|
{allCustomFields |
|
|
|
|
.filter((customField) => customField.scope !== 'visitor') |
|
|
|
|
.map((customField: ILivechatCustomField) => { |
|
|
|
|
if (customField.type === 'select') { |
|
|
|
|
return ( |
|
|
|
|
<Field key={customField._id}> |
|
|
|
|
<FieldLabel>{customField.label}</FieldLabel> |
|
|
|
|
<FieldRow> |
|
|
|
|
<Controller |
|
|
|
|
name={customField._id} |
|
|
|
|
control={control} |
|
|
|
|
render={({ field }): ReactElement => ( |
|
|
|
|
<Select {...field} options={(customField.options || '').split(',').map((item) => [item, item])} /> |
|
|
|
|
)} |
|
|
|
|
/> |
|
|
|
|
</FieldRow> |
|
|
|
|
</Field> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<Field key={customField._id}> |
|
|
|
|
<FieldLabel>{customField.label}</FieldLabel> |
|
|
|
|
<FieldRow> |
|
|
|
|
<Controller |
|
|
|
|
name={customField._id} |
|
|
|
|
control={control} |
|
|
|
|
render={({ field }): ReactElement => ( |
|
|
|
|
<Select {...field} options={(customField.options || '').split(',').map((item) => [item, item])} /> |
|
|
|
|
)} |
|
|
|
|
/> |
|
|
|
|
<TextInput flexGrow={1} {...register(customField._id)} /> |
|
|
|
|
</FieldRow> |
|
|
|
|
</Field> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<Field key={customField._id}> |
|
|
|
|
<FieldLabel>{customField.label}</FieldLabel> |
|
|
|
|
<FieldRow> |
|
|
|
|
<TextInput flexGrow={1} {...register(customField._id)} /> |
|
|
|
|
</FieldRow> |
|
|
|
|
</Field> |
|
|
|
|
); |
|
|
|
|
})} |
|
|
|
|
</ContextualbarScrollableContent> |
|
|
|
|
</Contextualbar> |
|
|
|
|
})} |
|
|
|
|
</ContextualbarScrollableContent> |
|
|
|
|
</Contextualbar> |
|
|
|
|
</ContextualbarDialog> |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|