Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eleven-yaks-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

Replaces the cancel button by reset in notification and export messages contextual bar.
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ const ExportMessages = () => {

const {
control,
formState: { errors, isSubmitting },
formState: { errors, isSubmitting, isDirty },
watch,
register,
setValue,
handleSubmit,
clearErrors,
reset,
} = useForm<ExportMessagesFormValues>({
mode: 'onBlur',
defaultValues: {
Expand Down Expand Up @@ -126,7 +127,7 @@ const ExportMessages = () => {
setValue('format', 'json');
}

setValue('messagesCount', messageCount);
setValue('messagesCount', messageCount, { shouldDirty: true });
}, [type, setValue, messageCount]);

const handleExport = async ({ type, toUsers, dateFrom, dateTo, format, subject, additionalEmails }: ExportMessagesFormValues) => {
Expand Down Expand Up @@ -345,8 +346,10 @@ const ExportMessages = () => {
</ContextualbarScrollableContent>
<ContextualbarFooter>
<ButtonGroup stretch>
<Button onClick={closeTab}>{t('Cancel')}</Button>
<Button loading={isSubmitting} form={formId} primary type='submit'>
<Button type='reset' disabled={!isDirty || isSubmitting} onClick={() => reset()}>
{t('Reset')}
</Button>
<Button disabled={!isDirty} loading={isSubmitting} form={formId} primary type='submit'>
{type === 'download' ? t('Download') : t('Send')}
</Button>
</ButtonGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const NotificationPreferences = ({
const { t } = useTranslation();
const {
formState: { isDirty, isSubmitting },
reset,
} = useFormContext();

return (
Expand All @@ -47,7 +48,9 @@ const NotificationPreferences = ({
</ContextualbarScrollableContent>
<ContextualbarFooter>
<ButtonGroup stretch>
{handleClose && <Button onClick={handleClose}>{t('Cancel')}</Button>}
<Button type='reset' disabled={!isDirty || isSubmitting} onClick={() => reset()}>
{t('Reset')}
</Button>
<Button primary disabled={!isDirty} loading={isSubmitting} onClick={handleSave}>
{t('Save')}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,21 @@ const NotificationPreferencesForm = ({ notificationOptions, handlePlaySound }: N
control={control}
name='turnOn'
render={({ field: { value, onChange } }) => (
<NotificationToggle label={t('Turn_ON')} description={t('Receive_alerts')} onChange={onChange} defaultChecked={value} />
<NotificationToggle label={t('Turn_ON')} description={t('Receive_alerts')} onChange={onChange} checked={value} />
)}
/>
<Controller
control={control}
name='muteGroupMentions'
render={({ field: { value, onChange } }) => (
<NotificationToggle label={t('Mute_Group_Mentions')} onChange={onChange} defaultChecked={value} />
<NotificationToggle label={t('Mute_Group_Mentions')} onChange={onChange} checked={value} />
)}
/>
<Controller
control={control}
name='showCounter'
render={({ field: { value, onChange } }) => (
<NotificationToggle
label={t('Show_counter')}
description={t('Display_unread_counter')}
onChange={onChange}
defaultChecked={value}
/>
<NotificationToggle label={t('Show_counter')} description={t('Display_unread_counter')} onChange={onChange} checked={value} />
)}
/>
{!showCounter && (
Expand All @@ -57,7 +52,7 @@ const NotificationPreferencesForm = ({ notificationOptions, handlePlaySound }: N
label={t('Show_mentions')}
description={t('Display_mentions_counter')}
onChange={onChange}
defaultChecked={value}
checked={value}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { Field, FieldLabel, FieldDescription, FieldGroup, ToggleSwitch, FieldRow } from '@rocket.chat/fuselage';
import type { ReactElement } from 'react';
import type { ComponentProps, ReactElement } from 'react';
import { memo, useId } from 'react';

type NotificationToggleProps = {
label: string;
description?: string;
onChange: (e: unknown) => void;
defaultChecked: boolean;
};
} & ComponentProps<typeof ToggleSwitch>;

const NotificationToggle = ({ label, description, onChange, defaultChecked }: NotificationToggleProps): ReactElement => {
const NotificationToggle = ({ label, description, onChange, ...props }: NotificationToggleProps): ReactElement => {
const fieldId = useId();

return (
<FieldGroup>
<Field>
<FieldRow>
<FieldLabel htmlFor={fieldId}>{label}</FieldLabel>
<ToggleSwitch id={fieldId} aria-describedby={`${fieldId}-hint`} onChange={onChange} defaultChecked={defaultChecked} />
<ToggleSwitch id={fieldId} aria-describedby={`${fieldId}-hint`} onChange={onChange} {...props} />
</FieldRow>
{description && <FieldDescription id={`${fieldId}-hint`}>{description}</FieldDescription>}
</Field>
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/export-messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test.describe.serial('export-messages', () => {
await poHomeChannel.tabs.btnExportMessages.click();

await poHomeChannel.content.getMessageByText('hello world').click();
await poHomeChannel.tabs.exportMessages.btnCancel.click();
await poHomeChannel.btnContextualbarClose.click();
await poHomeChannel.content.sendMessage('hello export');

await expect(poHomeChannel.content.getMessageByText('hello export')).toBeVisible();
Expand Down
Loading