fix: worktime table input fix

This commit is contained in:
2025-03-04 12:38:18 +04:00
parent 20a6c3cfcc
commit be666c5158

View File

@@ -29,20 +29,20 @@ type Props = {
range: dayjs.Dayjs[]; range: dayjs.Dayjs[];
}; };
const useWorkTableColumns = ({ const useWorkTableColumns = ({
month, month,
onUpdate, onUpdate,
data, data,
selectedCells, selectedCells,
setSelectedCells, setSelectedCells,
selectedBoundaries, selectedBoundaries,
range, range,
}: Props) => { }: Props) => {
const totalAmount = useMemo(() => { const totalAmount = useMemo(() => {
return data.reduce((acc, value) => { return data.reduce((acc, value) => {
if (value.data) { if (value.data) {
const sum = value.data.reduce( const sum = value.data.reduce(
(innerAcc, item) => innerAcc + item.amount, (innerAcc, item) => innerAcc + item.amount,
0 0,
); );
return acc + sum; return acc + sum;
} }
@@ -103,15 +103,15 @@ const useWorkTableColumns = ({
mantineTableBodyCellProps: ({ cell }) => ({ mantineTableBodyCellProps: ({ cell }) => ({
style: selectedCells.includes(cell.id) style: selectedCells.includes(cell.id)
? { ? {
backgroundColor: backgroundColor:
"var(--mantine-primary-color-filled)", "var(--mantine-primary-color-filled)",
...getBorderStyles(cell.id), ...getBorderStyles(cell.id),
} }
: {}, : {},
onClick: () => { onClick: () => {
const result = processSelectedCells( const result = processSelectedCells(
selectedCells, selectedCells,
cell.id cell.id,
); );
setSelectedCells(result); setSelectedCells(result);
}, },
@@ -119,21 +119,27 @@ const useWorkTableColumns = ({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error // @ts-expect-error
Cell: ({ cell, row }) => { Cell: ({ cell, row }) => {
let prevValue = formatValue(cell.renderValue());
const onAccept = (value: string) => {
if (value === prevValue) return;
prevValue = value;
return /^\d\d:\d\d$/.test(value) &&
onUpdate(
date.toDate(),
row.original.userId,
value,
);
}
return ( return (
<Flex direction={"column"}> <Flex direction={"column"}>
<Input <Input
component={IMaskInput} component={IMaskInput}
mask="00:00" mask="00:00"
onAccept={value => { onAccept={onAccept}
return /^\d\d:\d\d$/.test(value) &&
onUpdate(
date.toDate(),
row.original.userId,
value,
);
}}
styles={{ input: { textAlign: "center" } }} styles={{ input: { textAlign: "center" } }}
defaultValue={formatValue(cell.renderValue())} value={formatValue(cell.renderValue())}
/> />
</Flex> </Flex>
); );