Skip to content

Commit

Permalink
refactor: 💬 Change required field text positional argument to named
Browse files Browse the repository at this point in the history
  • Loading branch information
rique223 committed Aug 19, 2024
1 parent 1778647 commit 873233f
Show file tree
Hide file tree
Showing 48 changed files with 97 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug
<Controller
control={control}
name='parentRoom'
rules={{ required: t('The_field_is_required', t('Discussion_target_channel')) }}
rules={{ required: t('The_field_is_required', { field: t('Discussion_target_channel') }) }}
render={({ field: { name, onBlur, onChange, value } }) => (
<RoomAutoComplete
name={name}
Expand Down Expand Up @@ -152,7 +152,7 @@ const CreateDiscussion = ({ onClose, defaultParentRoom, parentMessageId, nameSug
<Controller
name='name'
control={control}
rules={{ required: t('The_field_is_required', t('Name')) }}
rules={{ required: t('The_field_is_required', { field: t('Name') }) }}
render={({ field }) => (
<TextInput
id={discussionNameId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ const CloseChatModal = ({
const requestData = transcriptEmail && visitorEmail ? { email: visitorEmail, subject } : undefined;

if (!comment?.trim() && commentRequired) {
setError('comment', { type: 'custom', message: t('The_field_is_required', t('Comment')) });
setError('comment', { type: 'custom', message: t('The_field_is_required', { field: t('Comment') }) });
}

if (transcriptEmail && !subject) {
setError('subject', { type: 'custom', message: t('The_field_is_required', t('Subject')) });
setError('subject', { type: 'custom', message: t('The_field_is_required', { field: t('Subject') }) });
}

if (!tags?.length && tagRequired) {
Expand Down Expand Up @@ -154,7 +154,7 @@ const CloseChatModal = ({
<FieldRow>
<TextInput
{...register('comment')}
error={errors.comment && t('The_field_is_required', t('Comment'))}
error={errors.comment && t('The_field_is_required', { field: t('Comment') })}
flexGrow={1}
placeholder={t('Please_add_a_comment')}
/>
Expand Down Expand Up @@ -201,7 +201,7 @@ const CloseChatModal = ({
<TextInput
{...register('subject', { required: true })}
className='active'
error={errors.subject && t('The_field_is_required', t('Subject'))}
error={errors.subject && t('The_field_is_required', { field: t('Subject') })}
flexGrow={1}
/>
</FieldRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const TranscriptModal = ({ email: emailDefault = '', room, onRequest, onSend, on
disabled={!!emailDefault || !!transcriptRequest}
error={errors.email?.message}
flexGrow={1}
{...register('email', { required: t('The_field_is_required', t('Email')) })}
{...register('email', { required: t('The_field_is_required', { field: t('Email') }) })}
/>
</FieldRow>
<FieldError>{errors.email?.message}</FieldError>
Expand All @@ -86,7 +86,7 @@ const TranscriptModal = ({ email: emailDefault = '', room, onRequest, onSend, on
disabled={!!transcriptRequest}
error={errors.subject?.message}
flexGrow={1}
{...register('subject', { required: t('The_field_is_required', t('Subject')) })}
{...register('subject', { required: t('The_field_is_required', { field: t('Subject') }) })}
/>
</FieldRow>
<FieldError>{errors.subject?.message}</FieldError>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const BusinessHoursMultiple = ({ className }: { className?: ComponentProps<typeo
<Controller
name='name'
control={control}
rules={{ required: t('The_field_is_required', t('Name')) }}
rules={{ required: t('The_field_is_required', { field: t('Name') }) }}
render={({ field }) => <TextInput id={nameField} {...field} aria-describedby={`${departmentsField}-error`} />}
/>
</FieldRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const CannedResponseForm = () => {
<Controller
name='shortcut'
control={control}
rules={{ required: t('The_field_is_required', t('Shortcut')) }}
rules={{ required: t('The_field_is_required', { field: t('Shortcut') }) }}
render={({ field }) => (
<TextInput
{...field}
Expand Down Expand Up @@ -76,7 +76,7 @@ const CannedResponseForm = () => {
<Controller
name='text'
control={control}
rules={{ required: t('The_field_is_required', t('Message')) }}
rules={{ required: t('The_field_is_required', { field: t('Message') }) }}
render={({ field: { value, onChange, name, onBlur } }) => (
<CannedResponsesComposer
id={messageField}
Expand Down Expand Up @@ -168,7 +168,7 @@ const CannedResponseForm = () => {
<Controller
name='departmentId'
control={control}
rules={{ required: t('The_field_is_required', t('Department')) }}
rules={{ required: t('The_field_is_required', { field: t('Department') }) }}
render={({ field: { value, onChange } }) => (
<AutoCompleteDepartment
{...(hasMonitorPermission && { onlyMyDepartments: hasMonitorPermission })}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const PriorityEditForm = ({ data, onSave, onCancel }: PriorityEditFormProps): Re
<Controller
name='name'
control={control}
rules={{ required: t('The_field_is_required', t('Name')), validate: (v) => v?.trim() !== '' }}
rules={{ required: t('The_field_is_required', { field: t('Name') }), validate: (v) => v?.trim() !== '' }}
render={({ field: { value, onChange } }): ReactElement => (
<StringSettingInput
_id=''
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/omnichannel/slaPolicies/SlaEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ function SlaEdit({ data, isNew, slaId, reload, ...props }: SlaEditProps): ReactE
const { field: nameField } = useController({
control,
name: 'name',
rules: { required: t('The_field_is_required', t('Name')) },
rules: { required: t('The_field_is_required', { field: t('Name') }) },
});

const { field: dueTimeField } = useController({
control,
name: 'dueTimeInMinutes',
rules: {
validate(value) {
return Number(value || 0) <= 0 ? t('The_field_is_required', t('Estimated_wait_time_in_minutes')) : true;
return Number(value || 0) <= 0 ? t('The_field_is_required', { field: t('Estimated_wait_time_in_minutes') }) : true;
},
},
});
Expand Down
8 changes: 4 additions & 4 deletions apps/meteor/client/omnichannel/units/UnitEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const UnitEdit = ({ unitData, unitMonitors, unitDepartments }: UnitEditProps) =>
<Controller
name='name'
control={control}
rules={{ required: t('The_field_is_required', t('Name')) }}
rules={{ required: t('The_field_is_required', { field: t('Name') }) }}
render={({ field }) => (
<TextInput
id={nameField}
Expand All @@ -195,7 +195,7 @@ const UnitEdit = ({ unitData, unitMonitors, unitDepartments }: UnitEditProps) =>
<Controller
name='visibility'
control={control}
rules={{ required: t('The_field_is_required', t('Visibility')) }}
rules={{ required: t('The_field_is_required', { field: t('Visibility') }) }}
render={({ field }) => (
<Select
id={visibilityField}
Expand All @@ -220,7 +220,7 @@ const UnitEdit = ({ unitData, unitMonitors, unitDepartments }: UnitEditProps) =>
<Controller
name='departments'
control={control}
rules={{ required: t('The_field_is_required', t('Departments')) }}
rules={{ required: t('The_field_is_required', { field: t('Departments') }) }}
render={({ field: { name, value, onChange, onBlur } }) => (
<PaginatedMultiSelectFiltered
id={departmentsField}
Expand Down Expand Up @@ -267,7 +267,7 @@ const UnitEdit = ({ unitData, unitMonitors, unitDepartments }: UnitEditProps) =>
<Controller
name='monitors'
control={control}
rules={{ required: t('The_field_is_required', t('Monitors')) }}
rules={{ required: t('The_field_is_required', { field: t('Monitors') }) }}
render={({ field: { name, value, onChange, onBlur } }) => (
<PaginatedMultiSelectFiltered
id={monitorsField}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const CreateChannelModal = ({ teamId = '', onClose, reload }: CreateChannelModal
id={nameId}
data-qa-type='channel-name-input'
{...register('name', {
required: t('The_field_is_required', t('Name')),
required: t('The_field_is_required', { field: t('Name') }),
validate: (value) => validateChannelName(value),
})}
error={errors.name?.message}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const CreateTeamModal = ({ onClose }: { onClose: () => void }): ReactElement =>
id={nameId}
aria-invalid={errors.name ? 'true' : 'false'}
{...register('name', {
required: t('The_field_is_required', t('Name')),
required: t('The_field_is_required', { field: t('Name') }),
validate: (value) => validateTeamName(value),
})}
addon={<Icon size='x20' name={isPrivate ? 'team-lock' : 'team'} />}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/sidebarv2/header/CreateTeamModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const CreateTeamModal = ({ onClose }: CreateTeamModalProps) => {
id={nameId}
aria-invalid={errors.name ? 'true' : 'false'}
{...register('name', {
required: t('The_field_is_required', t('Name')),
required: t('The_field_is_required', { field: t('Name') }),
validate: (value) => validateTeamName(value),
})}
addon={<Icon size='x20' name={isPrivate ? 'team-lock' : 'team'} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const AccountIntegrationsPage = () => {
<Controller
control={control}
name='accountSelected'
rules={{ required: t('The_field_is_required', t('WebDAV_Accounts')) }}
rules={{ required: t('The_field_is_required', { field: t('WebDAV_Accounts') }) }}
render={({ field }) => <SelectLegacy {...field} options={options} placeholder={t('Select_an_option')} />}
/>
<Button type='submit' danger>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
control={control}
name='name'
rules={{
required: requireName && t('The_field_is_required', t('Name')),
required: requireName && t('The_field_is_required', { field: t('Name') }),
}}
render={({ field }) => (
<TextInput
Expand Down Expand Up @@ -198,7 +198,7 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
control={control}
name='username'
rules={{
required: t('The_field_is_required', t('Username')),
required: t('The_field_is_required', { field: t('Username') }),
validate: (username) => validateUsername(username),
}}
render={({ field }) => (
Expand Down Expand Up @@ -308,7 +308,7 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle
control={control}
name='email'
rules={{
required: t('The_field_is_required', t('Email')),
required: t('The_field_is_required', { field: t('Email') }),
validate: { validateEmail: (email) => (validateEmail(email) ? undefined : t('error-invalid-email-address')) },
}}
render={({ field }) => (
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/views/account/security/ChangePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ChangePassword = (props: AllHTMLAttributes<HTMLFormElement>) => {
control={control}
name='password'
rules={{
required: t('The_field_is_required', t('New_password')),
required: t('The_field_is_required', { field: t('New_password') }),
validate: () => (password?.length && !passwordIsValid ? t('Password_must_meet_the_complexity_requirements') : true),
}}
render={({ field }) => (
Expand Down Expand Up @@ -85,7 +85,7 @@ const ChangePassword = (props: AllHTMLAttributes<HTMLFormElement>) => {
control={control}
name='confirmationPassword'
rules={{
required: t('The_field_is_required', t('Confirm_password')),
required: t('The_field_is_required', { field: t('Confirm_password') }),
validate: (confirmationPassword) => (password !== confirmationPassword ? t('Passwords_do_not_match') : true),
}}
render={({ field }) => (
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/views/account/security/EndToEnd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const EndToEnd = (props: ComponentProps<typeof Box>): ReactElement => {
<Controller
control={control}
name='password'
rules={{ required: t('The_field_is_required', t('New_encryption_password')) }}
rules={{ required: t('The_field_is_required', { field: t('New_encryption_password') }) }}
render={({ field }) => (
<PasswordInput
{...field}
Expand Down Expand Up @@ -110,7 +110,7 @@ const EndToEnd = (props: ComponentProps<typeof Box>): ReactElement => {
control={control}
name='passwordConfirm'
rules={{
required: t('The_field_is_required', t('Confirm_new_encryption_password')),
required: t('The_field_is_required', { field: t('Confirm_new_encryption_password') }),
validate: (value: string) => (password !== value ? 'Your passwords do no match' : true),
}}
render={({ field }) => (
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/views/admin/customEmoji/AddCustomEmoji.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const AddCustomEmoji = ({ close, onChange, ...props }: AddCustomEmojiProps): Rea
<FieldRow>
<TextInput value={name} onChange={handleChangeName} placeholder={t('Name')} />
</FieldRow>
{errors.name && <FieldError>{t('The_field_is_required', t('Name'))}</FieldError>}
{errors.name && <FieldError>{t('The_field_is_required', { field: t('Name') })}</FieldError>}
</Field>
<Field>
<FieldLabel>{t('Aliases')}</FieldLabel>
Expand All @@ -96,7 +96,7 @@ const AddCustomEmoji = ({ close, onChange, ...props }: AddCustomEmojiProps): Rea
{t('Custom_Emoji')}
<IconButton secondary small icon='upload' onClick={clickUpload} />
</FieldLabel>
{errors.emoji && <FieldError>{t('The_field_is_required', t('Custom_Emoji'))}</FieldError>}
{errors.emoji && <FieldError>{t('The_field_is_required', { field: t('Custom_Emoji') })}</FieldError>}
{newEmojiPreview && (
<Box display='flex' flexDirection='row' mi='neg-x4' justifyContent='center'>
<Margins inline={4}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const EditCustomEmoji = ({ close, onChange, data, ...props }: EditCustomEmojiPro
<FieldRow>
<TextInput value={name} onChange={handleChangeName} placeholder={t('Name')} />
</FieldRow>
{errors.name && <FieldError>{t('The_field_is_required', t('Name'))}</FieldError>}
{errors.name && <FieldError>{t('The_field_is_required', { field: t('Name') })}</FieldError>}
</Field>
<Field>
<FieldLabel>{t('Aliases')}</FieldLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const AddCustomSound = ({ goToNew, close, onChange, ...props }: AddCustomSoundPr
const validation = validate(soundData, soundFile) as Array<Parameters<typeof t>[0]>;

validation.forEach((error) => {
throw new Error(t('The_field_is_required', t(error)));
throw new Error(t('The_field_is_required', { field: t(error) }));
});

try {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/views/admin/customSounds/EditSound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function EditSound({ close, onChange, data, ...props }: EditSoundProps): ReactEl
validation.forEach((error) =>
dispatchToastMessage({
type: 'error',
message: t('The_field_is_required', t(error)),
message: t('The_field_is_required', { field: t(error) }),
}),
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const CustomUserStatusForm = ({ onClose, onReload, status }: CustomUserStatusFor
<Field>
<FieldLabel>{t('Name')}</FieldLabel>
<FieldRow>
<TextInput {...register('name', { required: t('The_field_is_required', t('Name')) })} placeholder={t('Name')} />
<TextInput {...register('name', { required: t('The_field_is_required', { field: t('Name') }) })} placeholder={t('Name')} />
</FieldRow>
{errors.name && <FieldError>{errors.name.message}</FieldError>}
</Field>
Expand All @@ -105,7 +105,7 @@ const CustomUserStatusForm = ({ onClose, onReload, status }: CustomUserStatusFor
<Controller
name='statusType'
control={control}
rules={{ required: t('The_field_is_required', t('Presence')) }}
rules={{ required: t('The_field_is_required', { field: t('Presence') }) }}
render={({ field }): ReactElement => <Select {...field} placeholder={t('Presence')} options={presenceOptions} />}
/>
</FieldRow>
Expand Down
Loading

0 comments on commit 873233f

Please sign in to comment.