|
|
|
|
@ -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 ?? '', |
|
|
|
|
@ -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, |
|
|
|
|
}); |
|
|
|
|
@ -97,6 +99,8 @@ 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, |
|
|
|
|
@ -104,7 +108,7 @@ const UserForm = ({ userData, onReload, ...props }: AdminUserFormProps) => { |
|
|
|
|
reset, |
|
|
|
|
formState: { errors, isDirty }, |
|
|
|
|
} = useForm({ |
|
|
|
|
defaultValues: getInitialValue({ data: userData, defaultUserRoles, isSmtpEnabled }), |
|
|
|
|
defaultValues: getInitialValue({ data: userData, defaultUserRoles, isSmtpEnabled, isEditingExistingUser }), |
|
|
|
|
mode: 'onBlur', |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
@ -166,7 +170,7 @@ const UserForm = ({ userData, onReload, ...props }: AdminUserFormProps) => { |
|
|
|
|
<> |
|
|
|
|
<ContextualbarScrollableContent {...props}> |
|
|
|
|
<FieldGroup> |
|
|
|
|
{userData?._id && ( |
|
|
|
|
{isEditingExistingUser && ( |
|
|
|
|
<Field> |
|
|
|
|
<Controller |
|
|
|
|
name='avatar' |
|
|
|
|
@ -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} |
|
|
|
|
@ -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> |
|
|
|
|
|