Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Feat(crm): Set isImage into dataProvider

Anthony Rimet5733a3e2a4b0
diff --git a/src/dataProvider.ts b/src/dataProvider.ts
index 45443449..9b78ea1c 100644
--- a/src/dataProvider.ts
+++ b/src/dataProvider.ts
@@ -11,6 +11,7 @@ import {
import { getActivityLog } from './dataProvider/activity';
import { supabase } from './supabase';
import {
+ AttachmentNote,
Contact,
ContactNote,
Deal,
@@ -345,3 +346,17 @@ const uploadToBucket = async (fi: RAFile) => {
return fi;
};
+
+/**
+ * Return if an attachment is an image.
+ * @param attachment
+ * @returns boolean
+ */
+export const isImage = (attachment: AttachmentNote) => {
+ const pathFile = attachment.src;
+ const extension = pathFile.split('.').pop();
+ if (!extension) {
+ return false;
+ }
+ return ['jpg', 'jpeg', 'png', 'gif', 'svg'].includes(extension);
+};
diff --git a/src/notes/NoteAttachments.tsx b/src/notes/NoteAttachments.tsx
index 16c53ea4..55c27ebc 100644
--- a/src/notes/NoteAttachments.tsx
+++ b/src/notes/NoteAttachments.tsx
@@ -2,6 +2,7 @@ import { ImageList, ImageListItem, Stack } from '@mui/material';
import { AttachmentNote, ContactNote, DealNote } from '../types';
import { FileField } from 'react-admin';
import AttachFileIcon from '@mui/icons-material/AttachFile';
+import { isImage } from '../dataProvider';
export const NoteAttachments = ({ note }: { note: ContactNote | DealNote }) => {
if (!note.attachments || note.attachments.length === 0) {
@@ -9,10 +10,10 @@ export const NoteAttachments = ({ note }: { note: ContactNote | DealNote }) => {
}
const imageAttachments = note.attachments.filter(
- (attachment: AttachmentNote) => isImage(attachment.src)
+ (attachment: AttachmentNote) => isImage(attachment)
);
const otherAttachments = note.attachments.filter(
- (attachment: AttachmentNote) => !isImage(attachment.src)
+ (attachment: AttachmentNote) => !isImage(attachment)
);
return (
@@ -59,11 +60,3 @@ export const NoteAttachments = ({ note }: { note: ContactNote | DealNote }) => {
</Stack>
);
};
-
-const isImage = (pathFile: string) => {
- const extension = pathFile.split('.').pop();
- if (!extension) {
- return false;
- }
- return ['jpg', 'jpeg', 'png', 'gif', 'svg'].includes(extension);
-};