Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVE] Convert tag edit with department data to tsx #24369

Merged
merged 7 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions definition/rest/v1/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ export type OmnichannelEndpoints = {
departments: ILivechatDepartment[];
}>;
};

'livechat/department.listByIds': {
GET: (params: { ids: string[]; fields?: Record<string, unknown> }) => { departments: ILivechatDepartment[] };
};

'livechat/custom-fields': {
GET: (params: PaginatedRequest<{ text: string }>) => PaginatedResult<{
customFields: [
Expand Down
2 changes: 2 additions & 0 deletions ee/client/audit/Result.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ const Result = memo(({ setDataRef }) => {
return <Box ref={ref} />;
});

Result.displayName = 'Result';

export default Result;
2 changes: 1 addition & 1 deletion ee/client/omnichannel/tags/TagEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useToastMessageDispatch } from '../../../../client/contexts/ToastMessag
import { useTranslation } from '../../../../client/contexts/TranslationContext';
import { useForm } from '../../../../client/hooks/useForm';

function TagEdit({ title, data, tagId, isNew, reload, currentDepartments, ...props }) {
function TagEdit({ title, data, tagId, reload, currentDepartments, ...props }) {
const t = useTranslation();
const tagsRoute = useRoute('omnichannel-tags');

Expand Down
6 changes: 3 additions & 3 deletions ee/client/omnichannel/tags/TagEditWithData.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useEndpointData } from '../../../../client/hooks/useEndpointData';
import TagEdit from './TagEdit';
import TagEditWithDepartmentData from './TagEditWithDepartmentData';

function TagEditWithData({ tagId, reload }) {
function TagEditWithData({ tagId, reload, title }) {
const query = useMemo(() => ({ tagId }), [tagId]);
const { value: data, phase: state, error } = useEndpointData('livechat/tags.getOne', query);

Expand All @@ -29,9 +29,9 @@ function TagEditWithData({ tagId, reload }) {
return (
<>
{data && data.departments && data.departments.length > 0 ? (
<TagEditWithDepartmentData tagId={tagId} data={data} reload={reload} />
<TagEditWithDepartmentData tagId={tagId} data={data} reload={reload} title={title} />
) : (
<TagEdit tagId={tagId} data={data} reload={reload} />
<TagEdit tagId={tagId} data={data} reload={reload} title={title} />
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { Callout } from '@rocket.chat/fuselage';
import React, { useMemo } from 'react';
import React, { ReactElement, useMemo, ReactNode } from 'react';

import { FormSkeleton } from '../../../../client/components/Skeleton';
import { useTranslation } from '../../../../client/contexts/TranslationContext';
import { AsyncStatePhase } from '../../../../client/hooks/useAsyncState';
import { useEndpointData } from '../../../../client/hooks/useEndpointData';
import { ILivechatTag } from '../../../../definition/ILivechatTag';
import TagEdit from './TagEdit';

function TagEditWithDepartmentData({ data, ...props }) {
type TagEditWithDepartmentDataPropsType = {
data: ILivechatTag;
title: ReactNode;
tagId: ILivechatTag['_id'];
reload: () => void;
};

function TagEditWithDepartmentData({ data, title, ...props }: TagEditWithDepartmentDataPropsType): ReactElement {
const t = useTranslation();

const {
Expand All @@ -16,7 +24,7 @@ function TagEditWithDepartmentData({ data, ...props }) {
error: currentDepartmentsError,
} = useEndpointData(
'livechat/department.listByIds',
useMemo(() => ({ ids: data && data.departments ? data.departments : [] }), [data]),
useMemo(() => ({ ids: data?.departments ? data.departments : [] }), [data]),
);

if ([currentDepartmentsState].includes(AsyncStatePhase.LOADING)) {
Expand All @@ -31,7 +39,7 @@ function TagEditWithDepartmentData({ data, ...props }) {
);
}

return <TagEdit currentDepartments={currentDepartments} data={data} {...props} />;
return <TagEdit title={title} currentDepartments={currentDepartments} data={data} {...props} />;
}

export default TagEditWithDepartmentData;