From 8c6cd0063374081c22b9c01d1c0bf303fea145a3 Mon Sep 17 00:00:00 2001 From: gabriellsh Date: Tue, 23 Jul 2024 10:45:40 -0300 Subject: [PATCH 1/3] Fix create discussion from message --- .../components/CreateDiscussion/CreateDiscussion.tsx | 11 +++++++++-- apps/meteor/tests/e2e/message-actions.spec.ts | 9 ++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx b/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx index e6bce31b0b87..115b47ee18e5 100644 --- a/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx +++ b/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx @@ -18,7 +18,7 @@ import { useUniqueId } from '@rocket.chat/fuselage-hooks'; import { useTranslation, useEndpoint } from '@rocket.chat/ui-contexts'; import { useMutation } from '@tanstack/react-query'; import type { ReactElement } from 'react'; -import React from 'react'; +import React, { useEffect } from 'react'; import { useForm, Controller } from 'react-hook-form'; import { goToRoomById } from '../../lib/utils/goToRoomById'; @@ -51,10 +51,11 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug control, watch, register, + reset, } = useForm({ mode: 'onBlur', defaultValues: { - name: nameSuggestion || '', + name: '', parentRoom: '', encrypted: false, usernames: [], @@ -63,6 +64,12 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug }, }); + useEffect(() => { + if (!isDirty && typeof nameSuggestion === 'string' && nameSuggestion.length > 0) { + reset({ name: nameSuggestion }, { keepDefaultValues: true }); + } + }, [nameSuggestion, reset, isDirty]); + const { encrypted } = watch(); const createDiscussion = useEndpoint('POST', '/v1/rooms.createDiscussion'); diff --git a/apps/meteor/tests/e2e/message-actions.spec.ts b/apps/meteor/tests/e2e/message-actions.spec.ts index 327a0499f2d7..bc916af89bae 100644 --- a/apps/meteor/tests/e2e/message-actions.spec.ts +++ b/apps/meteor/tests/e2e/message-actions.spec.ts @@ -76,11 +76,10 @@ test.describe.serial('message-actions', () => { await poHomeChannel.content.sendMessage(message); await poHomeChannel.content.openLastMessageMenu(); await page.locator('role=menuitem[name="Start a Discussion"]').click(); - await page.locator('input[name="topic"]').fill('1'); - await page.getByRole('dialog').getByRole('button', { name: 'create' }).click(); - // There is some condition checking if the form has been edited. - // the "Create" button should not be disabled if starting a discussion from a message - // TODO: Fix form and remove line below + const createButton = page.getByRole('dialog').getByRole('button', { name: 'create' }); + // Name should be prefilled thus making the create button enabled + await expect(createButton).not.toBeDisabled(); + await createButton.click(); await expect(page.locator('header h1')).toHaveText(message); }); From 40409801c2e67638234756dee2935ddcd97144a6 Mon Sep 17 00:00:00 2001 From: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Date: Tue, 23 Jul 2024 10:55:38 -0300 Subject: [PATCH 2/3] Add cs --- .changeset/perfect-coins-camp.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/perfect-coins-camp.md diff --git a/.changeset/perfect-coins-camp.md b/.changeset/perfect-coins-camp.md new file mode 100644 index 000000000000..4dbddf965742 --- /dev/null +++ b/.changeset/perfect-coins-camp.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": patch +--- + +fixed an issue in the "Create discussion" form, that would have the "Create" action button disabled even though the form is prefilled when opening it from the message action From 505532c724943b33a3314da9debe4d03ad9bf253 Mon Sep 17 00:00:00 2001 From: gabriellsh Date: Tue, 23 Jul 2024 15:51:24 -0300 Subject: [PATCH 3/3] fix review --- .../CreateDiscussion/CreateDiscussion.tsx | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx b/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx index 115b47ee18e5..cd39a187cd89 100644 --- a/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx +++ b/apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx @@ -18,7 +18,7 @@ import { useUniqueId } from '@rocket.chat/fuselage-hooks'; import { useTranslation, useEndpoint } from '@rocket.chat/ui-contexts'; import { useMutation } from '@tanstack/react-query'; import type { ReactElement } from 'react'; -import React, { useEffect } from 'react'; +import React from 'react'; import { useForm, Controller } from 'react-hook-form'; import { goToRoomById } from '../../lib/utils/goToRoomById'; @@ -46,16 +46,14 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug const t = useTranslation(); const { - formState: { isDirty, isSubmitting, isValidating, errors }, + formState: { isSubmitting, isValidating, errors }, handleSubmit, control, watch, - register, - reset, } = useForm({ mode: 'onBlur', defaultValues: { - name: '', + name: nameSuggestion || '', parentRoom: '', encrypted: false, usernames: [], @@ -64,12 +62,6 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug }, }); - useEffect(() => { - if (!isDirty && typeof nameSuggestion === 'string' && nameSuggestion.length > 0) { - reset({ name: nameSuggestion }, { keepDefaultValues: true }); - } - }, [nameSuggestion, reset, isDirty]); - const { encrypted } = watch(); const createDiscussion = useEndpoint('POST', '/v1/rooms.createDiscussion'); @@ -182,7 +174,11 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug {t('Topic')} - + } + /> {t('Displayed_next_to_name')} @@ -250,7 +246,7 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug -