From e17b625d9d3ae38d1c75b2c5c105d3c96c21c6a4 Mon Sep 17 00:00:00 2001 From: Douglas Fabris Date: Tue, 27 Aug 2024 18:48:10 -0300 Subject: [PATCH] refactor: Uses `source` instead of `room` to render the `OmnichannelRoomIcon` (#33118) --- .../OmnichannelAppSourceRoomIcon.tsx | 50 +++++----------- .../OmnichannelCoreSourceRoomIcon.tsx | 28 ++++----- .../OmnichannelRoomIcon.tsx | 39 ++++++++----- ...mIcon.ts => OmnichannelRoomIconManager.ts} | 6 +- .../provider/OmnichannelRoomIconProvider.tsx | 12 ++-- .../client/components/RoomIcon/RoomIcon.tsx | 6 +- .../directory/components/SourceField.tsx | 2 +- .../views/room/Header/HeaderIconWithRoom.tsx | 2 +- .../room/HeaderV2/HeaderIconWithRoom.tsx | 2 +- packages/core-typings/src/IRoom.ts | 57 ++++++++++--------- 10 files changed, 92 insertions(+), 112 deletions(-) rename apps/meteor/client/components/RoomIcon/OmnichannelRoomIcon/lib/{OmnichannelRoomIcon.ts => OmnichannelRoomIconManager.ts} (88%) diff --git a/apps/meteor/client/components/RoomIcon/OmnichannelRoomIcon/OmnichannelAppSourceRoomIcon.tsx b/apps/meteor/client/components/RoomIcon/OmnichannelRoomIcon/OmnichannelAppSourceRoomIcon.tsx index 60f3af65eb9d1..6a841c30491be 100644 --- a/apps/meteor/client/components/RoomIcon/OmnichannelRoomIcon/OmnichannelAppSourceRoomIcon.tsx +++ b/apps/meteor/client/components/RoomIcon/OmnichannelRoomIcon/OmnichannelAppSourceRoomIcon.tsx @@ -1,53 +1,29 @@ -import { UserStatus, type IOmnichannelRoomFromAppSource } from '@rocket.chat/core-typings'; +import { type IOmnichannelSourceFromApp } from '@rocket.chat/core-typings'; import { Icon, Box } from '@rocket.chat/fuselage'; -import type { ComponentProps, ReactElement } from 'react'; +import type { ComponentProps } from 'react'; import React from 'react'; import { AsyncStatePhase } from '../../../lib/asyncState/AsyncStatePhase'; import { useOmnichannelRoomIcon } from './context/OmnichannelRoomIconContext'; -const colors = { - busy: 'status-font-on-danger', - away: 'status-font-on-warning', - online: 'status-font-on-success', - offline: 'annotation', - disabled: 'annotation', +type OmnichannelAppSourceRoomIconProps = { + source: IOmnichannelSourceFromApp; + color: ComponentProps['color']; + size: ComponentProps['size']; + placement: 'sidebar' | 'default'; }; -const convertBoxSizeToNumber = (boxSize: ComponentProps['size']): number => { - switch (boxSize) { - case 'x20': { - return 20; - } - case 'x24': { - return 24; - } - case 'x16': - default: { - return 16; - } - } -}; +export const OmnichannelAppSourceRoomIcon = ({ source, color, size, placement }: OmnichannelAppSourceRoomIconProps) => { + const icon = (placement === 'sidebar' && source.sidebarIcon) || source.defaultIcon; + const { phase, value } = useOmnichannelRoomIcon(source.id, icon || ''); -export const OmnichannelAppSourceRoomIcon = ({ - room, - size = 16, - placement = 'default', -}: { - room: IOmnichannelRoomFromAppSource; - size: ComponentProps['size']; - placement: 'sidebar' | 'default'; -}): ReactElement => { - const color = colors[room.v.status || UserStatus.OFFLINE]; - const icon = (placement === 'sidebar' && room.source.sidebarIcon) || room.source.defaultIcon; - const { phase, value } = useOmnichannelRoomIcon(room.source.id, icon || ''); - const fontSize = convertBoxSizeToNumber(size); if ([AsyncStatePhase.REJECTED, AsyncStatePhase.LOADING].includes(phase)) { return ; } + return ( - -