diff --git a/package-lock.json b/package-lock.json index 482e13b21..c69003826 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@sentry/nextjs": "7.60.0", "@tanstack/react-query": "4.29.5", "@tanstack/react-query-devtools": "4.29.5", - "@taskany/bricks": "1.24.0", + "@taskany/bricks": "1.25.0", "@taskany/colors": "1.1.0", "@taskany/icons": "1.0.0", "@tippyjs/react": "4.2.6", @@ -5869,9 +5869,9 @@ } }, "node_modules/@taskany/bricks": { - "version": "1.24.0", - "resolved": "https://registry.npmjs.org/@taskany/bricks/-/bricks-1.24.0.tgz", - "integrity": "sha512-w0ebvHySh0CIO84zDcJSjIvmYgtA9vYhDHTP2V/dFf5DQoWLGE8k3dhTuvBrjoSeLJ8hRGDzhDr0ZZj2JqHTfw==", + "version": "1.25.0", + "resolved": "https://registry.npmjs.org/@taskany/bricks/-/bricks-1.25.0.tgz", + "integrity": "sha512-CkBB41CQuCXZE+0X5IodM9qeRMPuP8qQgxtpvgIzKP5wxlVgyDXtQ7PSvrndzcVfrCE+kyd+WIWWcrJnTZCHWw==", "dependencies": { "@monaco-editor/react": "4.5.1", "@taskany/colors": "1.1.0", @@ -22861,9 +22861,9 @@ } }, "@taskany/bricks": { - "version": "1.24.0", - "resolved": "https://registry.npmjs.org/@taskany/bricks/-/bricks-1.24.0.tgz", - "integrity": "sha512-w0ebvHySh0CIO84zDcJSjIvmYgtA9vYhDHTP2V/dFf5DQoWLGE8k3dhTuvBrjoSeLJ8hRGDzhDr0ZZj2JqHTfw==", + "version": "1.25.0", + "resolved": "https://registry.npmjs.org/@taskany/bricks/-/bricks-1.25.0.tgz", + "integrity": "sha512-CkBB41CQuCXZE+0X5IodM9qeRMPuP8qQgxtpvgIzKP5wxlVgyDXtQ7PSvrndzcVfrCE+kyd+WIWWcrJnTZCHWw==", "requires": { "@monaco-editor/react": "4.5.1", "@taskany/colors": "1.1.0", diff --git a/package.json b/package.json index f1bbfdb85..2cc49185a 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@sentry/nextjs": "7.60.0", "@tanstack/react-query": "4.29.5", "@tanstack/react-query-devtools": "4.29.5", - "@taskany/bricks": "1.24.0", + "@taskany/bricks": "1.25.0", "@taskany/colors": "1.1.0", "@taskany/icons": "1.0.0", "@tippyjs/react": "4.2.6", diff --git a/src/components/CommentCreateForm/CommentCreateForm.tsx b/src/components/CommentCreateForm/CommentCreateForm.tsx index 2c6854c3c..0dbbf1fd2 100644 --- a/src/components/CommentCreateForm/CommentCreateForm.tsx +++ b/src/components/CommentCreateForm/CommentCreateForm.tsx @@ -33,9 +33,8 @@ const CommentCreateForm: React.FC = ({ goalId, states, o const [pushState, setPushState] = useState(); const createComment = useCallback( - (form: GoalCommentSchema) => { - // FIXME: maybe async/await would be better API - create(({ id }) => { + async (form: GoalCommentSchema) => { + await create(({ id }) => { onSubmit?.(id); setPushState(undefined); })(form); diff --git a/src/components/CommentForm/CommentForm.tsx b/src/components/CommentForm/CommentForm.tsx index 64f9fa6dc..7e21923c1 100644 --- a/src/components/CommentForm/CommentForm.tsx +++ b/src/components/CommentForm/CommentForm.tsx @@ -21,7 +21,7 @@ interface CommentFormProps { description?: string; renderActionButton: (props: { busy?: boolean }) => React.ReactNode; - onSubmit?: (form: GoalCommentSchema) => void; + onSubmit?: (form: GoalCommentSchema) => void | Promise; onFocus?: () => void; onCancel?: () => void; } @@ -85,6 +85,11 @@ export const CommentForm: React.FC = ({ }, }); + const setBusyAndCommentFocused = useCallback((busy: boolean, commentFocused: boolean) => { + setBusy(busy); + setCommentFocused(commentFocused); + }, []); + const onCommentFocus = useCallback(() => { setCommentFocused(true); onFocus?.(); @@ -92,19 +97,20 @@ export const CommentForm: React.FC = ({ const onCommentCancel = useCallback(() => { reset(); - setBusy(false); - setCommentFocused(false); + setBusyAndCommentFocused(false, false); onCancel?.(); - }, [onCancel, reset]); + }, [onCancel, reset, setBusyAndCommentFocused]); const onCommentSubmit = useCallback( - (form: GoalCommentSchema) => { - setBusy(true); - setCommentFocused(false); - onSubmit?.(form); + async (form: GoalCommentSchema) => { + setBusyAndCommentFocused(true, false); reset(); + + await onSubmit?.(form); + + setBusyAndCommentFocused(false, true); }, - [onSubmit, reset], + [onSubmit, reset, setBusyAndCommentFocused], ); useClickOutside(ref, () => { diff --git a/src/hooks/useCommentResource.ts b/src/hooks/useCommentResource.ts index 7923182a6..6c8b80124 100644 --- a/src/hooks/useCommentResource.ts +++ b/src/hooks/useCommentResource.ts @@ -22,6 +22,7 @@ export const useCommentResource = () => { const [data] = await notifyPromise(promise, 'commentCreate'); data && cb(data); + return data; }; const update =