From dcea69317812a471aacaccefb809bf2dda68e5cd Mon Sep 17 00:00:00 2001 From: Aleksander Nicacio da Silva Date: Wed, 20 Mar 2024 19:40:27 -0300 Subject: [PATCH 1/6] feat: added Livechat's new theming settings to appearance page --- .../imports/server/rest/appearance.ts | 6 +- .../app/livechat/server/api/lib/appearance.ts | 4 + .../appearance/AppearanceFieldLabel.tsx | 30 +++++ .../omnichannel/appearance/AppearanceForm.tsx | 104 +++++++++++++++++- packages/rest-typings/src/v1/omnichannel.ts | 4 +- 5 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 apps/meteor/client/views/omnichannel/appearance/AppearanceFieldLabel.tsx diff --git a/apps/meteor/app/livechat/imports/server/rest/appearance.ts b/apps/meteor/app/livechat/imports/server/rest/appearance.ts index 5a0a884d97b2d..62c32e6b93e83 100644 --- a/apps/meteor/app/livechat/imports/server/rest/appearance.ts +++ b/apps/meteor/app/livechat/imports/server/rest/appearance.ts @@ -45,6 +45,10 @@ API.v1.addRoute( 'Livechat_name_field_registration_form', 'Livechat_email_field_registration_form', 'Livechat_registration_form_message', + 'Livechat_hide_watermark', + 'Livechat_background', + 'Livechat_widget_position', + 'Livechat_hide_system_messages', ]; const valid = settings.every((setting) => validSettingList.includes(setting._id)); @@ -69,7 +73,7 @@ API.v1.addRoute( case 'int': return { _id: dbSetting._id, - value: coerceInt(setting.value), + value: coerceInt(setting.value as number), }; default: return { diff --git a/apps/meteor/app/livechat/server/api/lib/appearance.ts b/apps/meteor/app/livechat/server/api/lib/appearance.ts index d0a0a3df6b174..785413ead9d1c 100644 --- a/apps/meteor/app/livechat/server/api/lib/appearance.ts +++ b/apps/meteor/app/livechat/server/api/lib/appearance.ts @@ -24,6 +24,10 @@ export async function findAppearance(): Promise<{ appearance: ISetting[] }> { 'Livechat_email_field_registration_form', 'Livechat_registration_form_message', 'Livechat_conversation_finished_text', + 'Livechat_hide_watermark', + 'Livechat_background', + 'Livechat_widget_position', + 'Livechat_hide_system_messages', ], }, }; diff --git a/apps/meteor/client/views/omnichannel/appearance/AppearanceFieldLabel.tsx b/apps/meteor/client/views/omnichannel/appearance/AppearanceFieldLabel.tsx new file mode 100644 index 0000000000000..138dab5283b3b --- /dev/null +++ b/apps/meteor/client/views/omnichannel/appearance/AppearanceFieldLabel.tsx @@ -0,0 +1,30 @@ +import { FieldLabel as BaseFieldLabel, Box, Tag } from '@rocket.chat/fuselage'; +import { useTranslation } from '@rocket.chat/ui-contexts'; +import type { ComponentProps } from 'react'; +import React from 'react'; + +import { useHasLicenseModule } from '../../../../ee/client/hooks/useHasLicenseModule'; + +type FieldLabelProps = ComponentProps & { + premium?: boolean; + children: string; +}; + +export const FieldLabel = ({ children: label, premium = false }: FieldLabelProps) => { + const t = useTranslation(); + const hasLicense = useHasLicenseModule('livechat-enterprise'); + const shouldDisableEnterprise = premium && !hasLicense; + + if (!shouldDisableEnterprise) { + return {label}; + } + + return ( + + + {label} + + {t('Premium')} + + ); +}; diff --git a/apps/meteor/client/views/omnichannel/appearance/AppearanceForm.tsx b/apps/meteor/client/views/omnichannel/appearance/AppearanceForm.tsx index 258cda39e9622..452fea1c5b89e 100644 --- a/apps/meteor/client/views/omnichannel/appearance/AppearanceForm.tsx +++ b/apps/meteor/client/views/omnichannel/appearance/AppearanceForm.tsx @@ -1,6 +1,5 @@ import { Field, - FieldLabel, FieldRow, TextInput, ToggleSwitch, @@ -9,6 +8,9 @@ import { InputBox, TextAreaInput, NumberInput, + Select, + MultiSelect, + FieldHint, } from '@rocket.chat/fuselage'; import { useUniqueId } from '@rocket.chat/fuselage-hooks'; import { useTranslation } from '@rocket.chat/ui-contexts'; @@ -16,8 +18,13 @@ import type { ChangeEvent } from 'react'; import React from 'react'; import { Controller, useFormContext } from 'react-hook-form'; +import { useHasLicenseModule } from '../../../../ee/client/hooks/useHasLicenseModule'; +import MarkdownText from '../../../components/MarkdownText'; +import { FieldLabel } from './AppearanceFieldLabel'; + const AppearanceForm = () => { const t = useTranslation(); + const isEnterprise = useHasLicenseModule('livechat-enterprise'); const { control, watch } = useFormContext(); const { Livechat_enable_message_character_limit } = watch(); @@ -41,9 +48,101 @@ const AppearanceForm = () => { const livechatRegistrationFormMessageField = useUniqueId(); const livechatConversationFinishedMessageField = useUniqueId(); const livechatConversationFinishedTextField = useUniqueId(); + const livechatHideWatermarkField = useUniqueId(); + const livechatWidgetPositionField = useUniqueId(); + const livechatBackgroundField = useUniqueId(); + const livechatHideSystemMessagesField = useUniqueId(); return ( + + + + + + {t('Livechat_hide_watermark')} + + ( + + )} + /> + + + + + + {t('Livechat_background')} + + + ( + + )} + /> + + + + + + + + + {t('Livechat_widget_position_on_the_screen')} + + + ( +