-
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.
refactor: Omnichannel Department re-write (#28948)
- Loading branch information
1 parent
6e2f78f
commit 6a474ff
Showing
26 changed files
with
868 additions
and
802 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,6 @@ | ||
--- | ||
'@rocket.chat/meteor': minor | ||
'@rocket.chat/rest-typings': patch | ||
--- | ||
|
||
Refactored Omnichannel department pages to use best practices, also fixed existing bugs |
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
41 changes: 0 additions & 41 deletions
41
apps/meteor/client/views/omnichannel/departments/AgentRow.js
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
30 changes: 30 additions & 0 deletions
30
apps/meteor/client/views/omnichannel/departments/DepartmentAgentsTable/AgentAvatar.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,30 @@ | ||
import { Box } from '@rocket.chat/fuselage'; | ||
import { useMediaQuery } from '@rocket.chat/fuselage-hooks'; | ||
import React, { memo } from 'react'; | ||
|
||
import UserAvatar from '../../../../components/avatar/UserAvatar'; | ||
|
||
const AgentAvatar = ({ name, username, eTag }: { name: string; username: string; eTag?: string }) => { | ||
const mediaQuery = useMediaQuery('(min-width: 1024px)'); | ||
|
||
return ( | ||
<Box display='flex' alignItems='center'> | ||
<UserAvatar size={mediaQuery ? 'x28' : 'x40'} title={username} username={username} etag={eTag} /> | ||
<Box display='flex' withTruncatedText mi='x8'> | ||
<Box display='flex' flexDirection='column' alignSelf='center' withTruncatedText> | ||
<Box fontScale='p2m' withTruncatedText color='default'> | ||
{name || username} | ||
</Box> | ||
{!mediaQuery && name && ( | ||
<Box fontScale='p2' color='hint' withTruncatedText> | ||
{' '} | ||
{`@${username}`}{' '} | ||
</Box> | ||
)} | ||
</Box> | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default memo(AgentAvatar); |
37 changes: 37 additions & 0 deletions
37
apps/meteor/client/views/omnichannel/departments/DepartmentAgentsTable/AgentRow.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,37 @@ | ||
import { NumberInput, TableCell, TableRow } from '@rocket.chat/fuselage'; | ||
import { useTranslation } from '@rocket.chat/ui-contexts'; | ||
import React, { memo } from 'react'; | ||
import type { UseFormRegister } from 'react-hook-form'; | ||
|
||
import type { FormValues, IDepartmentAgent } from '../EditDepartment'; | ||
import AgentAvatar from './AgentAvatar'; | ||
import RemoveAgentButton from './RemoveAgentButton'; | ||
|
||
type AgentRowProps = { | ||
agent: IDepartmentAgent; | ||
index: number; | ||
register: UseFormRegister<FormValues>; | ||
onRemove: (agentId: string) => void; | ||
}; | ||
|
||
const AgentRow = ({ index, agent, register, onRemove }: AgentRowProps) => { | ||
const t = useTranslation(); | ||
|
||
return ( | ||
<TableRow key={agent.agentId} tabIndex={0} role='link' action qa-user-id={agent.agentId}> | ||
<TableCell withTruncatedText> | ||
<AgentAvatar name={agent.name || ''} username={agent.username || ''} /> | ||
</TableCell> | ||
<TableCell fontScale='p2' color='hint' withTruncatedText> | ||
<NumberInput title={t('Count')} maxWidth='100%' {...register(`agentList.${index}.count`, { valueAsNumber: true })} /> | ||
</TableCell> | ||
<TableCell fontScale='p2' color='hint' withTruncatedText> | ||
<NumberInput title={t('Order')} maxWidth='100%' {...register(`agentList.${index}.order`, { valueAsNumber: true })} /> | ||
</TableCell> | ||
<TableCell fontScale='p2' color='hint'> | ||
<RemoveAgentButton agentId={agent.agentId} onRemove={onRemove} /> | ||
</TableCell> | ||
</TableRow> | ||
); | ||
}; | ||
export default memo(AgentRow); |
43 changes: 43 additions & 0 deletions
43
...teor/client/views/omnichannel/departments/DepartmentAgentsTable/DepartmentAgentsTable.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,43 @@ | ||
import { useTranslation } from '@rocket.chat/ui-contexts'; | ||
import React from 'react'; | ||
import type { Control, UseFormRegister } from 'react-hook-form'; | ||
import { useWatch, useFieldArray } from 'react-hook-form'; | ||
|
||
import { GenericTable, GenericTableBody, GenericTableHeader, GenericTableHeaderCell } from '../../../../components/GenericTable'; | ||
import type { FormValues } from '../EditDepartment'; | ||
import AddAgent from './AddAgent'; | ||
import AgentRow from './AgentRow'; | ||
|
||
type DepartmentAgentsTableProps = { | ||
control: Control<FormValues>; | ||
register: UseFormRegister<FormValues>; | ||
}; | ||
|
||
function DepartmentAgentsTable({ control, register }: DepartmentAgentsTableProps) { | ||
const t = useTranslation(); | ||
const { fields, append, remove } = useFieldArray({ control, name: 'agentList' }); | ||
const agentList = useWatch({ control, name: 'agentList' }); | ||
|
||
return ( | ||
<> | ||
<AddAgent agentList={agentList} data-qa='DepartmentSelect-AgentsTable' onAdd={append} /> | ||
|
||
<GenericTable> | ||
<GenericTableHeader> | ||
<GenericTableHeaderCell w='x200'>{t('Name')}</GenericTableHeaderCell> | ||
<GenericTableHeaderCell w='x140'>{t('Count')}</GenericTableHeaderCell> | ||
<GenericTableHeaderCell w='x120'>{t('Order')}</GenericTableHeaderCell> | ||
<GenericTableHeaderCell w='x40'>{t('Remove')}</GenericTableHeaderCell> | ||
</GenericTableHeader> | ||
|
||
<GenericTableBody> | ||
{fields.map((agent, index) => ( | ||
<AgentRow key={agent.id} index={index} agent={agent} register={register} onRemove={() => remove(index)} /> | ||
))} | ||
</GenericTableBody> | ||
</GenericTable> | ||
</> | ||
); | ||
} | ||
|
||
export default DepartmentAgentsTable; |
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
63 changes: 63 additions & 0 deletions
63
apps/meteor/client/views/omnichannel/departments/DepartmentTags/index.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,63 @@ | ||
import { Button, Chip, Field, TextInput } from '@rocket.chat/fuselage'; | ||
import { useTranslation } from '@rocket.chat/ui-contexts'; | ||
import type { FormEvent } from 'react'; | ||
import React, { useCallback, useState } from 'react'; | ||
|
||
type DepartmentTagsProps = { | ||
error: string; | ||
value: string[]; | ||
onChange: (tags: string[]) => void; | ||
}; | ||
|
||
export const DepartmentTags = ({ error, value: tags, onChange }: DepartmentTagsProps) => { | ||
const t = useTranslation(); | ||
const [tagText, setTagText] = useState(''); | ||
|
||
const handleAddTag = useCallback(() => { | ||
if (tags.includes(tagText)) { | ||
return; | ||
} | ||
|
||
setTagText(''); | ||
onChange([...tags, tagText]); | ||
}, [onChange, tagText, tags]); | ||
|
||
const handleTagChipClick = (tag: string) => () => { | ||
onChange(tags.filter((_tag) => _tag !== tag)); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Field.Row> | ||
<TextInput | ||
data-qa='DepartmentEditTextInput-ConversationClosingTags' | ||
error={error} | ||
placeholder={t('Enter_a_tag')} | ||
value={tagText} | ||
onChange={(e: FormEvent<HTMLInputElement>) => setTagText(e.currentTarget.value)} | ||
/> | ||
<Button | ||
disabled={Boolean(!tagText.trim()) || tags.includes(tagText)} | ||
data-qa='DepartmentEditAddButton-ConversationClosingTags' | ||
mis='x8' | ||
title={t('Add')} | ||
onClick={handleAddTag} | ||
> | ||
{t('Add')} | ||
</Button> | ||
</Field.Row> | ||
|
||
<Field.Hint>{t('Conversation_closing_tags_description')}</Field.Hint> | ||
|
||
{tags?.length > 0 && ( | ||
<Field.Row justifyContent='flex-start'> | ||
{tags.map((tag, i) => ( | ||
<Chip key={i} onClick={handleTagChipClick(tag)} mie='x8'> | ||
{tag} | ||
</Chip> | ||
))} | ||
</Field.Row> | ||
)} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.