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: Don't show join default channels option for edit user form #31750

Merged
merged 11 commits into from
May 21, 2024
6 changes: 6 additions & 0 deletions .changeset/real-bobcats-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/rest-typings': patch
'@rocket.chat/meteor': patch
---

Don't show Join default channels option on edit user form and stop accepting this param on API
yash-rajpal marked this conversation as resolved.
Show resolved Hide resolved
38 changes: 22 additions & 16 deletions apps/meteor/client/views/admin/users/AdminUserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ const getInitialValue = ({
data,
defaultUserRoles,
isSmtpEnabled,
isEditingExistingUser,
}: {
data?: Serialized<IUser>;
defaultUserRoles?: IUser['roles'];
isSmtpEnabled?: boolean;
isEditingExistingUser?: boolean;
}) => ({
roles: data?.roles ?? defaultUserRoles,
name: data?.name ?? '',
Expand All @@ -69,7 +71,7 @@ const getInitialValue = ({
requirePasswordChange: data?.requirePasswordChange || false,
customFields: data?.customFields ?? {},
statusText: data?.statusText ?? '',
joinDefaultChannels: true,
...(!isEditingExistingUser && { joinDefaultChannels: true }),
sendWelcomeEmail: isSmtpEnabled,
avatar: '' as AvatarObject,
});
Expand Down Expand Up @@ -97,14 +99,16 @@ const UserForm = ({ userData, onReload, ...props }: AdminUserFormProps) => {

const goToUser = useCallback((id) => router.navigate(`/admin/users/info/${id}`), [router]);

const isEditingExistingUser = Boolean(userData?._id);

const {
control,
watch,
handleSubmit,
reset,
formState: { errors, isDirty },
} = useForm({
defaultValues: getInitialValue({ data: userData, defaultUserRoles, isSmtpEnabled }),
defaultValues: getInitialValue({ data: userData, defaultUserRoles, isSmtpEnabled, isEditingExistingUser }),
mode: 'onBlur',
});

Expand Down Expand Up @@ -166,7 +170,7 @@ const UserForm = ({ userData, onReload, ...props }: AdminUserFormProps) => {
<>
<ContextualbarScrollableContent {...props}>
<FieldGroup>
{userData?._id && (
{isEditingExistingUser && (
<Field>
<Controller
name='avatar'
Expand Down Expand Up @@ -346,7 +350,7 @@ const UserForm = ({ userData, onReload, ...props }: AdminUserFormProps) => {
<Controller
control={control}
name='password'
rules={{ required: !userData?._id && t('The_field_is_required', t('Password')) }}
rules={{ required: !isEditingExistingUser && t('The_field_is_required', t('Password')) }}
render={({ field }) => (
<PasswordInput
{...field}
Expand Down Expand Up @@ -434,18 +438,20 @@ const UserForm = ({ userData, onReload, ...props }: AdminUserFormProps) => {
</FieldRow>
{errors?.roles && <FieldError>{errors.roles.message}</FieldError>}
</Field>
<Field>
<FieldRow>
<FieldLabel htmlFor={joinDefaultChannelsId}>{t('Join_default_channels')}</FieldLabel>
<Controller
control={control}
name='joinDefaultChannels'
render={({ field: { ref, onChange, value } }) => (
<ToggleSwitch id={joinDefaultChannelsId} ref={ref} onChange={onChange} checked={value} />
)}
/>
</FieldRow>
</Field>
{!isEditingExistingUser && (
<Field>
<FieldRow>
<FieldLabel htmlFor={joinDefaultChannelsId}>{t('Join_default_channels')}</FieldLabel>
<Controller
control={control}
name='joinDefaultChannels'
render={({ field: { ref, onChange, value } }) => (
<ToggleSwitch id={joinDefaultChannelsId} ref={ref} onChange={onChange} checked={value} />
)}
/>
</FieldRow>
</Field>
)}
<Field>
<FieldRow>
<FieldLabel htmlFor={sendWelcomeEmailId}>{t('Send_welcome_email')}</FieldLabel>
Expand Down
5 changes: 0 additions & 5 deletions packages/rest-typings/src/v1/users/UsersUpdateParamsPOST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export type UsersUpdateParamsPOST = {
nickname?: string;
statusText?: string;
roles?: string[];
joinDefaultChannels?: boolean;
yash-rajpal marked this conversation as resolved.
Show resolved Hide resolved
requirePasswordChange?: boolean;
setRandomPassword?: boolean;
sendWelcomeEmail?: boolean;
Expand Down Expand Up @@ -78,10 +77,6 @@ const UsersUpdateParamsPostSchema = {
},
nullable: true,
},
joinDefaultChannels: {
type: 'boolean',
nullable: true,
},
requirePasswordChange: {
type: 'boolean',
nullable: true,
Expand Down
Loading