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