Skip to content

Commit

Permalink
Merge branch 'release-7.1.0' into regression/custom-fields-error-cont…
Browse files Browse the repository at this point in the history
…act-migration
  • Loading branch information
matheusbsilva137 authored Nov 26, 2024
2 parents e4f94c0 + e72e9d6 commit 3ed0fc9
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
{
_id: 'visitor1',
username: 'Username',
activity: ['2024-11'],
lastChat: {
_id: 'last-chat-id',
ts: testDate,
Expand Down Expand Up @@ -122,6 +123,10 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
details: {
type: OmnichannelSourceType.WIDGET,
},
lastChat: {
_id: 'last-chat-id',
ts: testDate,
},
},
],
customFields: undefined,
Expand All @@ -137,14 +142,11 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
{
_id: 'visitor1',
username: 'Username',
lastChat: {
_id: 'last-chat-id',
ts: testDate,
},
livechatData: {
customFieldId: 'customFieldValue',
invalidCustomFieldId: 'invalidCustomFieldValue',
},
activity: [],
},
{
type: OmnichannelSourceType.WIDGET,
Expand All @@ -153,7 +155,7 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
name: 'Username',
emails: undefined,
phones: undefined,
unknown: false,
unknown: true,
channels: [
{
name: 'sms',
Expand All @@ -173,10 +175,6 @@ const dataMap: [Partial<ILivechatVisitor>, IOmnichannelSource, CreateContactPara
customFields: {
customFieldId: 'customFieldValue',
},
lastChat: {
_id: 'last-chat-id',
ts: testDate,
},
contactManager: undefined,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function mapVisitorToContact(visitor: ILivechatVisitor, source: IOm
name: visitor.name || visitor.username,
emails: visitor.visitorEmails?.map(({ address }) => address),
phones: visitor.phone?.map(({ phoneNumber }) => phoneNumber),
unknown: true,
unknown: !visitor.activity || visitor.activity.length === 0,
channels: [
{
name: source.label || source.type.toString(),
Expand All @@ -24,6 +24,7 @@ export async function mapVisitorToContact(visitor: ILivechatVisitor, source: IOm
blocked: false,
verified: false,
details: source,
lastChat: visitor.lastChat,
},
],
customFields:
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/NavBarV2/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const NavBar = () => {
<NavBarGroup role='toolbar' ref={omnichannelToolbarRef} {...omnichannelToolbarProps}>
{showOmnichannelQueueLink && <NavBarItemOmnichannelQueue title={t('Queue')} />}
{isCallReady && <NavBarItemOmniChannelCallDialPad />}
<NavBarItemOmnichannelContact title={t('Contacts')} />
<NavBarItemOmnichannelContact title={t('Contact_Center')} />
{isCallEnabled && <NavBarItemOmnichannelCallToggle />}
<NavBarItemOmnichannelLivechatToggle />
</NavBarGroup>
Expand Down
4 changes: 0 additions & 4 deletions apps/meteor/client/views/admin/EditableSettingsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export type EditableSettingsContextValue = {
_id: ISetting['_id'],
) => [subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => ISetting['_id'][]];
readonly dispatch: (changes: Partial<EditableSetting>[]) => void;
readonly isEnterprise: boolean;
};

export const EditableSettingsContext = createContext<EditableSettingsContextValue>({
Expand All @@ -37,11 +36,8 @@ export const EditableSettingsContext = createContext<EditableSettingsContextValu
queryGroupSections: () => [(): (() => void) => (): void => undefined, (): string[] => []],
queryGroupTabs: () => [(): (() => void) => (): void => undefined, (): ISetting['_id'][] => []],
dispatch: () => undefined,
isEnterprise: false,
});

export const useIsEnterprise = (): boolean => useContext(EditableSettingsContext).isEnterprise;

export const useEditableSetting = (_id: ISetting['_id']): EditableSetting | undefined => {
const { queryEditableSetting } = useContext(EditableSettingsContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { FilterOperators } from 'mongodb';
import type { MutableRefObject, ReactNode } from 'react';
import React, { useEffect, useMemo, useRef } from 'react';

import { useIsEnterprise } from '../../../hooks/useIsEnterprise';
import { createReactiveSubscriptionFactory } from '../../../lib/createReactiveSubscriptionFactory';
import type { EditableSetting, EditableSettingsContextValue } from '../EditableSettingsContext';
import { EditableSettingsContext } from '../EditableSettingsContext';
Expand Down Expand Up @@ -193,20 +192,15 @@ const EditableSettingsProvider = ({ children, query = defaultQuery, omit = defau
Tracker.flush();
});

const { data } = useIsEnterprise();

const isEnterprise = data?.isEnterprise ?? false;

const contextValue = useMemo<EditableSettingsContextValue>(
() => ({
queryEditableSetting,
queryEditableSettings,
queryGroupSections,
queryGroupTabs,
dispatch,
isEnterprise,
}),
[queryEditableSetting, queryEditableSettings, queryGroupSections, queryGroupTabs, dispatch, isEnterprise],
[queryEditableSetting, queryEditableSettings, queryGroupSections, queryGroupTabs, dispatch],
);

return <EditableSettingsContext.Provider children={children} value={contextValue} />;
Expand Down
8 changes: 5 additions & 3 deletions apps/meteor/client/views/admin/settings/Setting/Setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { useTranslation } from 'react-i18next';

import MemoizedSetting from './MemoizedSetting';
import MarkdownText from '../../../../components/MarkdownText';
import { useEditableSetting, useEditableSettingsDispatch, useIsEnterprise } from '../../EditableSettingsContext';
import { useEditableSetting, useEditableSettingsDispatch } from '../../EditableSettingsContext';
import { useHasSettingModule } from '../hooks/useHasSettingModule';

type SettingProps = {
className?: string;
Expand All @@ -20,7 +21,7 @@ type SettingProps = {
function Setting({ className = undefined, settingId, sectionChanged }: SettingProps): ReactElement {
const setting = useEditableSetting(settingId);
const persistedSetting = useSettingStructure(settingId);
const isEnterprise = useIsEnterprise();
const hasSettingModule = useHasSettingModule(setting);

if (!setting || !persistedSetting) {
throw new Error(`Setting ${settingId} not found`);
Expand Down Expand Up @@ -105,12 +106,13 @@ function Setting({ className = undefined, settingId, sectionChanged }: SettingPr
) : undefined,
[i18n, i18nDescription, t],
);

const callout = useMemo(
() => alert && <span dangerouslySetInnerHTML={{ __html: i18n.exists(alert) ? t(alert) : alert }} />,
[alert, i18n, t],
);

const shouldDisableEnterprise = setting.enterprise && !isEnterprise;
const shouldDisableEnterprise = setting.enterprise && !hasSettingModule;

const PRICING_URL = 'https://go.rocket.chat/i/see-paid-plan-customize-homepage';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ISetting, LicenseModule } from '@rocket.chat/core-typings';
import { useMemo } from 'react';

import { useLicenseBase } from '../../../../hooks/useLicense';

export const useHasSettingModule = (setting?: ISetting) => {
const { data } = useLicenseBase({
select: (data) => ({ isEnterprise: Boolean(data?.license.license), activeModules: data?.license.activeModules }),
});

const isEnterprise = data?.isEnterprise ?? false;

const hasSettingModule = useMemo(() => {
if (!setting?.modules || setting?.modules.length === 0) {
return false;
}

return setting.modules.every((module) => data?.activeModules.includes(module as LicenseModule));
}, [data?.activeModules, setting?.modules]);

if (!setting) {
throw new Error('No setting provided');
}

return isEnterprise && hasSettingModule;
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import type { RadioDropDownGroup, RadioDropDownOnSelected } from '../definitions

type AppsFiltersProps = {
text: string;
setText: React.Dispatch<React.SetStateAction<string>> & {
flush: () => void;
cancel: () => void;
};
setText: (text: string) => void;
freePaidFilterStructure: RadioDropDownGroup;
freePaidFilterOnSelected: RadioDropDownOnSelected;
categories: CategoryDropDownListProps['categories'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useDebouncedState } from '@rocket.chat/fuselage-hooks';
import { useDebouncedValue } from '@rocket.chat/fuselage-hooks';
import { useRouteParameter, useRouter } from '@rocket.chat/ui-contexts';
import type { ReactElement } from 'react';
import React, { useEffect, useMemo, useState, useCallback } from 'react';
Expand Down Expand Up @@ -29,7 +29,8 @@ type AppsContext = 'explore' | 'installed' | 'premium' | 'private' | 'requested'
const AppsPageContent = (): ReactElement => {
const { t } = useTranslation();
const { marketplaceApps, installedApps, privateApps, reload } = useAppsResult();
const [text, setText] = useDebouncedState('', 500);
const [text, setText] = useState('');
const debouncedText = useDebouncedValue(text, 500);
const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination();

const router = useRouter();
Expand Down Expand Up @@ -127,7 +128,7 @@ const AppsPageContent = (): ReactElement => {
const [categories, selectedCategories, categoryTagList, onSelected] = useCategories();
const appsResult = useFilteredApps({
appsData: getAppsData(),
text,
text: debouncedText,
current,
itemsPerPage,
categories: useMemo(() => selectedCategories.map(({ label }) => label), [selectedCategories]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ILivechatContact, Serialized } from '@rocket.chat/core-typings';
import { Box, Button, ButtonGroup, Callout, IconButton, Tabs, TabsItem } from '@rocket.chat/fuselage';
import { UserAvatar } from '@rocket.chat/ui-avatar';
import { usePermission, useRouter, useRouteParameter, useSetModal } from '@rocket.chat/ui-contexts';
import { usePermission, useRouteParameter, useSetModal } from '@rocket.chat/ui-contexts';
import React from 'react';
import { useTranslation } from 'react-i18next';

Expand All @@ -22,21 +22,16 @@ type ContactInfoProps = {
const ContactInfo = ({ contact, onClose }: ContactInfoProps) => {
const { t } = useTranslation();

const { getRouteName } = useRouter();
const setModal = useSetModal();
const currentRouteName = getRouteName();
const handleNavigate = useContactRoute();
const context = useRouteParameter('context');

const formatDate = useFormatDate();

const canEditContact = usePermission('edit-omnichannel-contact');

const { name, emails, phones, conflictingFields, createdAt, lastChat, contactManager, customFields: userCustomFields } = contact;

const hasConflicts = conflictingFields && conflictingFields?.length > 0;
const showContactHistory = (currentRouteName === 'live' || currentRouteName === 'omnichannel-directory') && lastChat;

const customFieldEntries = useValidCustomFields(userCustomFields);

return (
Expand Down Expand Up @@ -90,11 +85,9 @@ const ContactInfo = ({ contact, onClose }: ContactInfoProps) => {
<TabsItem onClick={() => handleNavigate({ context: 'channels' })} selected={context === 'channels'}>
{t('Channels')}
</TabsItem>
{showContactHistory && (
<TabsItem onClick={() => handleNavigate({ context: 'history' })} selected={context === 'history'}>
{t('History')}
</TabsItem>
)}
<TabsItem onClick={() => handleNavigate({ context: 'history' })} selected={context === 'history'}>
{t('History')}
</TabsItem>
</Tabs>
{context === 'details' && (
<ContactInfoDetails
Expand All @@ -106,7 +99,7 @@ const ContactInfo = ({ contact, onClose }: ContactInfoProps) => {
/>
)}
{context === 'channels' && <ContactInfoChannels contactId={contact?._id} />}
{context === 'history' && showContactHistory && <ContactInfoHistory contact={contact} />}
{context === 'history' && <ContactInfoHistory contact={contact} />}
</>
);
};
Expand Down
Loading

0 comments on commit 3ed0fc9

Please sign in to comment.