A full-featured CRM built with React, shadcn/ui, and Supabase.
Move attach button down to NoteInputs
fzaninottobe96c0fa6094
diff --git a/registry.json b/registry.jsonindex 7e54e8f3..b2973846 100644--- a/registry.json+++ b/registry.json@@ -369,10 +369,6 @@"path": "src/components/atomic-crm/notes/NoteShowPage.tsx","type": "registry:component"},- {- "path": "src/components/atomic-crm/notes/NoteMenuButton.tsx",- "type": "registry:component"- },{"path": "src/components/atomic-crm/notes/NoteInputsMobile.tsx","type": "registry:component"diff --git a/src/components/atomic-crm/notes/NoteCreateSheet.tsx b/src/components/atomic-crm/notes/NoteCreateSheet.tsxindex 2e24eaa3..5ef0c1dd 100644--- a/src/components/atomic-crm/notes/NoteCreateSheet.tsx+++ b/src/components/atomic-crm/notes/NoteCreateSheet.tsx@@ -12,7 +12,6 @@ import {import { CreateSheet } from "../misc/CreateSheet";import { foreignKeyMapping } from "./foreignKeyMapping";import { NoteInputsMobile } from "./NoteInputsMobile";-import { NoteMenuButton } from "./NoteMenuButton";import { getCurrentDate } from "./utils";export interface NoteCreateSheetProps {@@ -69,7 +68,7 @@ export const NoteCreateSheet = ({<CreateSheetresource="contact_notes"title={- <span className="text-xl font-semibold truncate pr-10">+ <span className="text-xl font-semibold truncate">{!selectContact? translate("resources.notes.sheet.create_for", {name: getContactRepresentation(contact!),@@ -90,7 +89,6 @@ export const NoteCreateSheet = ({mutationOptions={{ onSuccess: handleSuccess }}open={open}onOpenChange={onOpenChange}- headerActions={<NoteMenuButton />}><NoteInputsMobile selectContact={selectContact} /></CreateSheet>diff --git a/src/components/atomic-crm/notes/NoteEditSheet.tsx b/src/components/atomic-crm/notes/NoteEditSheet.tsxindex 6b03b38c..22eb5faf 100644--- a/src/components/atomic-crm/notes/NoteEditSheet.tsx+++ b/src/components/atomic-crm/notes/NoteEditSheet.tsx@@ -1,4 +1,4 @@-import { ReferenceField } from "@/components/admin";+import { EllipsisVertical, Trash2 } from "lucide-react";import {type Identifier,useCreatePath,@@ -7,10 +7,17 @@ import {useRecordContext,useTranslate,} from "ra-core";+import { ReferenceField } from "@/components/admin";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuTrigger,+} from "@/components/ui/dropdown-menu";+import { EditSheet } from "../misc/EditSheet";import { foreignKeyMapping } from "./foreignKeyMapping";import { NoteInputsMobile } from "./NoteInputsMobile";-import { NoteMenuButton } from "./NoteMenuButton";export interface NoteEditSheetProps {open: boolean;@@ -43,7 +50,7 @@ export const NoteEditSheet = ({source={foreignKeyMapping["contacts"]}reference="contacts"render={({ referenceRecord }) => (- <span className="text-xl font-semibold truncate pr-10">+ <span className="text-xl font-semibold truncate">{referenceRecord? translate("resources.notes.sheet.edit_for", {name: getContactRepresentation(referenceRecord),@@ -76,6 +83,7 @@ const NoteEditMenuButton = ({onOpenChange: (open: boolean) => void;getRedirectTo: (record: any) => string;}) => {+ const translate = useTranslate();const record = useRecordContext();const { handleDelete } = useDeleteController({record,@@ -89,5 +97,29 @@ const NoteEditMenuButton = ({handleDelete();};- return <NoteMenuButton onDelete={onDelete} />;+ return (+ <DropdownMenu modal={false}>+ <DropdownMenuTrigger asChild>+ <button+ type="button"+ className="opacity-70 transition-opacity hover:opacity-100 rounded-xs"+ >+ <EllipsisVertical className="size-6" />+ <span className="sr-only">+ {translate("ra.action.open_menu", { _: "More" })}+ </span>+ </button>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end">+ <DropdownMenuItem+ variant="destructive"+ className="h-12 md:h-8 px-4 md:px-2 text-base md:text-sm"+ onSelect={onDelete}+ >+ <Trash2 />+ {translate("ra.action.delete")}+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ );};diff --git a/src/components/atomic-crm/notes/NoteInputsMobile.tsx b/src/components/atomic-crm/notes/NoteInputsMobile.tsxindex 2e9bb39b..4b3c031d 100644--- a/src/components/atomic-crm/notes/NoteInputsMobile.tsx+++ b/src/components/atomic-crm/notes/NoteInputsMobile.tsx@@ -1,4 +1,5 @@import { useCallback, useRef } from "react";+import { Paperclip } from "lucide-react";import { required, useInput, useTranslate, ValidationError } from "ra-core";import { RecordContextProvider } from "ra-core";import { AutocompleteInput, ReferenceInput } from "@/components/admin";@@ -48,7 +49,7 @@ export const NoteInputsMobile = ({)}</div>{selectContact && (- <div className="px-4">+ <div className="px-4 py-4"><ReferenceInputsource={foreignKeyMapping["contacts"]}reference="contacts"@@ -65,11 +66,59 @@ export const NoteInputsMobile = ({)}<div className="px-4"><AttachmentPreviewsMobile />+ <AttachButton /></div></div>);};+const AttachButton = () => {+ const inputRef = useRef<HTMLInputElement>(null);+ const { getValues, setValue } = useFormContext();+ const translate = useTranslate();++ const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {+ const fileList = e.target.files;+ if (!fileList || fileList.length === 0) return;++ const newFiles = Array.from(fileList).map((file) => ({+ rawFile: file,+ src: URL.createObjectURL(file),+ title: file.name,+ }));++ const existing = getValues("attachments") || [];+ const currentFiles = Array.isArray(existing) ? existing : [existing];+ setValue("attachments", [...currentFiles, ...newFiles], {+ shouldDirty: true,+ });++ e.target.value = "";+ };++ return (+ <>+ <button+ type="button"+ className="flex items-center gap-2 py-3 text-sm text-muted-foreground"+ onClick={() => inputRef.current?.click()}+ >+ <Paperclip className="size-4" />+ {translate("resources.notes.actions.attach_document", {+ _: "Attach document",+ })}+ </button>+ <input+ ref={inputRef}+ type="file"+ multiple+ className="hidden"+ onChange={handleFileChange}+ />+ </>+ );+};+const AttachmentPreviewsMobile = () => {const { control, setValue } = useFormContext();const attachments = useWatch({ control, name: "attachments" });diff --git a/src/components/atomic-crm/notes/NoteMenuButton.tsx b/src/components/atomic-crm/notes/NoteMenuButton.tsxdeleted file mode 100644index ed9e3c3c..00000000--- a/src/components/atomic-crm/notes/NoteMenuButton.tsx+++ /dev/null@@ -1,81 +0,0 @@-import { useRef } from "react";-import { EllipsisVertical, Paperclip, Trash2 } from "lucide-react";-import { useFormContext } from "react-hook-form";-import { useTranslate } from "ra-core";-import {- DropdownMenu,- DropdownMenuContent,- DropdownMenuItem,- DropdownMenuTrigger,-} from "@/components/ui/dropdown-menu";--export const NoteMenuButton = ({ onDelete }: { onDelete?: () => void }) => {- const inputRef = useRef<HTMLInputElement>(null);- const { getValues, setValue } = useFormContext();- const translate = useTranslate();-- const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {- const fileList = e.target.files;- if (!fileList || fileList.length === 0) return;-- const newFiles = Array.from(fileList).map((file) => ({- rawFile: file,- src: URL.createObjectURL(file),- title: file.name,- }));-- const existing = getValues("attachments") || [];- const currentFiles = Array.isArray(existing) ? existing : [existing];- setValue("attachments", [...currentFiles, ...newFiles], {- shouldDirty: true,- });-- e.target.value = "";- };-- return (- <>- <DropdownMenu modal={false}>- <DropdownMenuTrigger asChild>- <button- type="button"- className="opacity-70 transition-opacity hover:opacity-100 rounded-xs"- >- <EllipsisVertical className="size-6" />- <span className="sr-only">- {translate("ra.action.open_menu", { _: "More" })}- </span>- </button>- </DropdownMenuTrigger>- <DropdownMenuContent align="end">- <DropdownMenuItem- className="h-12 md:h-8 px-4 md:px-2 text-base md:text-sm"- onSelect={() => inputRef.current?.click()}- >- <Paperclip />- {translate("resources.notes.actions.attach_document", {- _: "Attach document",- })}- </DropdownMenuItem>- {onDelete && (- <DropdownMenuItem- variant="destructive"- className="h-12 md:h-8 px-4 md:px-2 text-base md:text-sm"- onSelect={onDelete}- >- <Trash2 />- {translate("ra.action.delete")}- </DropdownMenuItem>- )}- </DropdownMenuContent>- </DropdownMenu>- <input- ref={inputRef}- type="file"- multiple- className="hidden"- onChange={handleFileChange}- />- </>- );-};