RocketChat/Rocket.Chat

View on GitHub
apps/meteor/client/components/message/content/attachments/AttachmentsItem.tsx

Summary

Maintainability
A
0 mins
Test Coverage
import type { MessageAttachmentBase } from '@rocket.chat/core-typings';
import { isFileAttachment, isQuoteAttachment } from '@rocket.chat/core-typings';
import type { ReactElement } from 'react';
import React, { memo } from 'react';

import DefaultAttachment from './DefaultAttachment';
import FileAttachment from './FileAttachment';
import { QuoteAttachment } from './QuoteAttachment';

type AttachmentsItemProps = {
    attachment: MessageAttachmentBase;
    id: string | undefined;
};

const AttachmentsItem = ({ attachment, id }: AttachmentsItemProps): ReactElement => {
    if (isFileAttachment(attachment)) {
        return <FileAttachment id={id} {...attachment} />;
    }

    if (isQuoteAttachment(attachment)) {
        return <QuoteAttachment attachment={attachment} />;
    }

    return <DefaultAttachment {...(attachment as any)} />;
};

export default memo(AttachmentsItem);