Skip to content

Commit

Permalink
Fixed reset input values in NoteInputDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
pkirilin committed Mar 6, 2024
1 parent 7275a57 commit 79e0ce6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/frontend/src/features/notes/ui/NotesTableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DeleteIcon from '@mui/icons-material/Delete';
import EditIcon from '@mui/icons-material/Edit';
import { IconButton, Stack, TableCell, TableRow, Tooltip } from '@mui/material';
import { type FC, useEffect, useState } from 'react';
import { type FC, useEffect, useState, useMemo } from 'react';
import { type ProductSelectOption } from 'src/features/products';
import { useRouterId } from 'src/hooks';
import { notesApi } from '../api';
Expand Down Expand Up @@ -30,6 +30,7 @@ export const NotesTableRow: FC<NotesTableRowProps> = ({
const [isDeleteDialogOpened, setIsDeleteDialogOpened] = useState(false);
const [editNote, editNoteResponse] = notesApi.useEditNoteMutation();
const [deleteNote, deleteNoteResponse] = notesApi.useDeleteNoteMutation();
const product = useMemo(() => toProductSelectOption(note), [note]);

useEffect(() => {
if ((editNoteResponse.isSuccess || deleteNoteResponse.isSuccess) && notesChanged) {
Expand Down Expand Up @@ -70,7 +71,7 @@ export const NotesTableRow: FC<NotesTableRowProps> = ({
isOpened={isEditDialogOpened}
mealType={note.mealType}
pageId={pageId}
product={toProductSelectOption(note)}
product={product}
products={products}
productsLoading={productsLoading}
quantity={note.productQuantity}
Expand Down
35 changes: 18 additions & 17 deletions src/frontend/src/hooks/useInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from 'react';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { type InputOptions, type MapToInputPropsFunction, type ValidatorFunction } from 'src/types';

// Single space is used to avoid shifting form control when it becomes invalid
Expand Down Expand Up @@ -53,20 +53,21 @@ export default function useInput<TValue, TProps>({
}
}, [errorHelperText, isTouched, validate, value]);

const inputProps = mapToInputProps({
value,
setValue,
helperText,
isInvalid,
});

return {
value,
setValue,
clearValue,
helperText,
isInvalid,
isTouched,
inputProps,
};
return useMemo(
() => ({
value,
setValue,
clearValue,
helperText,
isInvalid,
isTouched,
inputProps: mapToInputProps({
value,
setValue,
helperText,
isInvalid,
}),
}),
[clearValue, helperText, isInvalid, isTouched, mapToInputProps, setValue, value],
);
}

0 comments on commit 79e0ce6

Please sign in to comment.