-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use external service for triggers (#31268)
Co-authored-by: Aleksander Nicacio da Silva <[email protected]> Co-authored-by: Martin Schoeler <[email protected]> Co-authored-by: Marcos Spessatto Defendi <[email protected]>
- Loading branch information
1 parent
871efa5
commit b9e897a
Showing
36 changed files
with
1,666 additions
and
410 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@rocket.chat/meteor': minor | ||
'@rocket.chat/core-typings': minor | ||
'@rocket.chat/livechat': minor | ||
--- | ||
|
||
Added new Livechat trigger action "Send message (external service)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
apps/meteor/client/views/omnichannel/triggers/ConditionForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import type { SelectOption } from '@rocket.chat/fuselage'; | ||
import { Field, FieldGroup, FieldLabel, FieldRow, NumberInput, Select, TextInput } from '@rocket.chat/fuselage'; | ||
import { useUniqueId } from '@rocket.chat/fuselage-hooks'; | ||
import { useTranslation } from '@rocket.chat/ui-contexts'; | ||
import type { ComponentProps } from 'react'; | ||
import React, { useMemo } from 'react'; | ||
import type { Control } from 'react-hook-form'; | ||
import { Controller, useWatch } from 'react-hook-form'; | ||
|
||
import type { TriggersPayload } from './EditTrigger'; | ||
|
||
type ConditionFormType = ComponentProps<typeof Field> & { | ||
index: number; | ||
control: Control<TriggersPayload>; | ||
}; | ||
|
||
export const ConditionForm = ({ control, index, ...props }: ConditionFormType) => { | ||
const conditionFieldId = useUniqueId(); | ||
const t = useTranslation(); | ||
const conditionName = useWatch({ control, name: `conditions.${index}.name` }); | ||
|
||
const placeholders: { [conditionName: string]: string } = useMemo( | ||
() => ({ | ||
'page-url': t('Enter_a_regex'), | ||
'time-on-site': t('Time_in_seconds'), | ||
}), | ||
[t], | ||
); | ||
|
||
const conditionOptions: SelectOption[] = useMemo( | ||
() => [ | ||
['page-url', t('Visitor_page_URL')], | ||
['time-on-site', t('Visitor_time_on_site')], | ||
['chat-opened-by-visitor', t('Chat_opened_by_visitor')], | ||
['after-guest-registration', t('After_guest_registration')], | ||
], | ||
[t], | ||
); | ||
|
||
const conditionValuePlaceholder = placeholders[conditionName]; | ||
|
||
return ( | ||
<FieldGroup {...props}> | ||
<Field> | ||
<FieldLabel htmlFor={conditionFieldId}>{t('Condition')}</FieldLabel> | ||
<FieldRow> | ||
<Controller | ||
name={`conditions.${index}.name`} | ||
control={control} | ||
render={({ field }) => ( | ||
<Select {...field} id={conditionFieldId} options={conditionOptions} placeholder={t('Select_an_option')} /> | ||
)} | ||
/> | ||
</FieldRow> | ||
|
||
{conditionValuePlaceholder && ( | ||
<FieldRow> | ||
<Controller | ||
name={`conditions.${index}.value`} | ||
control={control} | ||
render={({ field }) => { | ||
if (conditionName === 'time-on-site') { | ||
return <NumberInput {...field} placeholder={conditionValuePlaceholder} />; | ||
} | ||
|
||
return <TextInput {...field} placeholder={conditionValuePlaceholder} />; | ||
}} | ||
/> | ||
</FieldRow> | ||
)} | ||
</Field> | ||
</FieldGroup> | ||
); | ||
}; |
Oops, something went wrong.