Feat/activities custom objects (#3213)
* WIP * WIP - MultiObjectSearch * WIP * WIP * Finished working version * Fix * Fixed and cleaned * Fix * Disabled files and emails for custom objects * Cleaned console.log * Fixed attachment * Fixed * fix lint --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
import { ChangeEvent, useRef } from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
import { isNonEmptyArray } from '@sniptt/guards';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { AttachmentList } from '@/activities/files/components/AttachmentList';
|
||||
import { useAttachments } from '@/activities/files/hooks/useAttachments';
|
||||
import { Attachment } from '@/activities/files/types/Attachment';
|
||||
import { getFileType } from '@/activities/files/utils/getFileType';
|
||||
import { ActivityTargetableEntity } from '@/activities/types/ActivityTargetableEntity';
|
||||
import { ActivityTargetableObject } from '@/activities/types/ActivityTargetableEntity';
|
||||
import { getActivityTargetObjectFieldIdName } from '@/activities/utils/getTargetObjectFilterFieldName';
|
||||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
|
||||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||
import { useCreateOneRecord } from '@/object-record/hooks/useCreateOneRecord';
|
||||
@ -56,13 +58,13 @@ const StyledFileInput = styled.input`
|
||||
`;
|
||||
|
||||
export const Attachments = ({
|
||||
targetableEntity,
|
||||
targetableObject,
|
||||
}: {
|
||||
targetableEntity: ActivityTargetableEntity;
|
||||
targetableObject: ActivityTargetableObject;
|
||||
}) => {
|
||||
const inputFileRef = useRef<HTMLInputElement>(null);
|
||||
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState);
|
||||
const { attachments } = useAttachments(targetableEntity);
|
||||
const { attachments } = useAttachments(targetableObject);
|
||||
|
||||
const [uploadFile] = useUploadFileMutation();
|
||||
|
||||
@ -92,22 +94,23 @@ export const Attachments = ({
|
||||
if (!attachmentUrl) {
|
||||
return;
|
||||
}
|
||||
if (!createOneAttachment) {
|
||||
return;
|
||||
}
|
||||
|
||||
await createOneAttachment({
|
||||
const targetableObjectFieldIdName = getActivityTargetObjectFieldIdName({
|
||||
nameSingular: targetableObject.targetObjectNameSingular,
|
||||
});
|
||||
|
||||
const attachmentToCreate = {
|
||||
authorId: currentWorkspaceMember?.id,
|
||||
name: file.name,
|
||||
fullPath: attachmentUrl,
|
||||
type: getFileType(file.name),
|
||||
companyId:
|
||||
targetableEntity.type === 'Company' ? targetableEntity.id : null,
|
||||
personId: targetableEntity.type === 'Person' ? targetableEntity.id : null,
|
||||
});
|
||||
[targetableObjectFieldIdName]: targetableObject.id,
|
||||
};
|
||||
|
||||
await createOneAttachment(attachmentToCreate);
|
||||
};
|
||||
|
||||
if (attachments?.length === 0 && targetableEntity.type !== 'Custom') {
|
||||
if (!isNonEmptyArray(attachments)) {
|
||||
return (
|
||||
<StyledTaskGroupEmptyContainer>
|
||||
<StyledFileInput
|
||||
|
||||
Reference in New Issue
Block a user