Skip to content

Commit

Permalink
fix(CommentView): provide cancel handler for CommentForm
Browse files Browse the repository at this point in the history
  • Loading branch information
awinogradov committed Aug 14, 2023
1 parent 6381f79 commit b3d06b3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/CommentView/CommentView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,13 @@ export const CommentView: FC<CommentViewProps> = ({
const onCommentDoubleClick = useCallback<React.MouseEventHandler>((e) => {
if (e.detail === 2) {
setEditMode(true);
setFocused(true);
}
}, []);

const onCommentSubmit = useCallback(
async (form: CommentSchema) => {
setEditMode(false);
setBusy(true);
setFocused(false);

Expand All @@ -175,12 +177,22 @@ export const CommentView: FC<CommentViewProps> = ({
[onSubmit, onChange, description],
);

const onCommentCancel = useCallback(() => {
setEditMode(false);
setFocused(false);
setCommentDescription({ description });
onCancel?.();
}, [description, onCancel]);

const dropdownItems = useMemo(
() => [
{
label: tr('Edit'),
icon: <EditIcon size="xxs" />,
onClick: () => setEditMode(true),
onClick: () => {
setEditMode(true);
setFocused(true);
},
},
{
label: tr('Delete'),
Expand Down Expand Up @@ -210,7 +222,7 @@ export const CommentView: FC<CommentViewProps> = ({
autoFocus
onChange={setCommentDescription}
onSubmit={onCommentSubmit}
onCancel={onCancel}
onCancel={onCommentCancel}
actionButton={
<Button
size="m"
Expand Down

0 comments on commit b3d06b3

Please sign in to comment.