import { ActionIcon, Box, Button, Tooltip } from '@mantine/core'; import { type MRT_Row, type MRT_TableInstance } from '../types'; interface Props = {}> { row: MRT_Row; table: MRT_TableInstance; variant?: 'icon' | 'text'; } export const MRT_EditActionButtons = = {}>({ row, table, variant = 'icon', }: Props) => { const { getState, options: { icons: { IconCircleX, IconDeviceFloppy }, localization, onCreatingRowCancel, onCreatingRowSave, onEditingRowSave, onEditingRowCancel, }, refs: { editInputRefs }, setCreatingRow, setEditingRow, } = table; const { creatingRow, editingRow, isSaving } = getState(); const isCreating = creatingRow?.id === row.id; const isEditing = editingRow?.id === row.id; const handleCancel = () => { if (isCreating) { onCreatingRowCancel?.({ row, table }); setCreatingRow(null); } else if (isEditing) { onEditingRowCancel?.({ row, table }); setEditingRow(null); } row._valuesCache = {} as any; //reset values cache }; const handleSubmitRow = () => { //look for auto-filled input values Object.values(editInputRefs?.current) .filter((inputRef) => row.id === inputRef?.name?.split('_')?.[0]) ?.forEach((input) => { if ( input.value !== undefined && Object.hasOwn(row?._valuesCache as object, input.name) ) { // @ts-ignore row._valuesCache[input.name] = input.value; } }); if (isCreating) onCreatingRowSave?.({ exitCreatingMode: () => setCreatingRow(null), row, table, values: row._valuesCache, }); else if (isEditing) { onEditingRowSave?.({ exitEditingMode: () => setEditingRow(null), row, table, values: row?._valuesCache, }); } }; return ( e.stopPropagation()} sx={{ display: 'flex', gap: '12px' }} > {variant === 'icon' ? ( <> ) : ( <> )} ); };