Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Create discussion form Create button is disabled when starting discussion from message #32864

Merged
merged 8 commits into from
Jul 24, 2024
5 changes: 5 additions & 0 deletions .changeset/perfect-coins-camp.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug
const t = useTranslation();

const {
formState: { isDirty, isSubmitting, isValidating, errors },
formState: { isSubmitting, isValidating, errors },
handleSubmit,
control,
watch,
register,
} = useForm({
mode: 'onBlur',
defaultValues: {
Expand Down Expand Up @@ -175,7 +174,11 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug
<Field>
<FieldLabel htmlFor={topicId}>{t('Topic')}</FieldLabel>
<FieldRow>
<TextInput id={topicId} aria-describedby={`${topicId}-hint`} {...register('topic')} />
<Controller
name='topic'
control={control}
render={({ field }) => <TextInput id={topicId} {...field} aria-describedby={`${topicId}-hint`} />}
/>
</FieldRow>
<FieldRow>
<FieldHint id={`${topicId}-hint`}>{t('Displayed_next_to_name')}</FieldHint>
Expand Down Expand Up @@ -243,7 +246,7 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug
<Modal.Footer>
<Modal.FooterControllers>
<Button onClick={onClose}>{t('Cancel')}</Button>
<Button type='submit' primary disabled={!isDirty} loading={isSubmitting || isValidating}>
<Button type='submit' primary loading={isSubmitting || isValidating}>
{t('Create')}
</Button>
</Modal.FooterControllers>
Expand Down
9 changes: 4 additions & 5 deletions apps/meteor/tests/e2e/message-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
Loading