mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Merge 51c4070879
into 7d84185d0e
This commit is contained in:
commit
671e577689
5 changed files with 46 additions and 7 deletions
|
@ -149,9 +149,17 @@ const UserNew = () => {
|
|||
}).catch(err => {
|
||||
console.error('[usernew] failed to update user policy', err);
|
||||
});
|
||||
}, function () {
|
||||
toast(globalize.translate('ErrorDefault'));
|
||||
loading.hide();
|
||||
}, function (error) {
|
||||
try {
|
||||
console.error('[usernew] failed to create new user', error);
|
||||
error.text().then((errorMessage: string) => {
|
||||
toast(errorMessage);
|
||||
loading.hide();
|
||||
});
|
||||
} catch {
|
||||
toast(globalize.translate('ErrorDefault'));
|
||||
loading.hide();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -198,6 +206,7 @@ const UserNew = () => {
|
|||
type='text'
|
||||
id='txtUsername'
|
||||
label='LabelName'
|
||||
validator={{ pattern: '^([\\w \\-\'._@+]*)([\\w\\-\'._@+])([\\w \\-\'._@+]*)$', errMessage: globalize.translate('MessageInvalidUsernameFormat') }}
|
||||
options={'required'}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
@ -230,7 +230,16 @@ const UserEdit = () => {
|
|||
)).then(() => {
|
||||
onSaveComplete();
|
||||
}).catch(err => {
|
||||
console.error('[useredit] failed to update user', err);
|
||||
try {
|
||||
console.error('[useredit] failed to update user', err);
|
||||
err.text().then((errorMessage: string) => {
|
||||
toast(errorMessage);
|
||||
loading.hide();
|
||||
});
|
||||
} catch {
|
||||
toast(globalize.translate('ErrorDefault'));
|
||||
loading.hide();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -318,6 +327,7 @@ const UserEdit = () => {
|
|||
type='text'
|
||||
id='txtUserName'
|
||||
label='LabelName'
|
||||
validator={{ pattern: '^([\\w \\-\'._@+]*)([\\w\\-\'._@+])([\\w \\-\'._@+]*)$', errMessage: globalize.translate('MessageInvalidUsernameFormat') }}
|
||||
options={'required'}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
@ -2,23 +2,30 @@ import React, { type FC, useCallback, useEffect, useMemo, useRef } from 'react';
|
|||
|
||||
import globalize from 'lib/globalize';
|
||||
|
||||
import './InputElementInvalidMessage.scss';
|
||||
|
||||
interface CreateInputElementParams {
|
||||
type?: string
|
||||
id?: string
|
||||
label?: string
|
||||
initialValue?: string
|
||||
validator?: { pattern: string, errMessage: string }
|
||||
options?: string
|
||||
}
|
||||
|
||||
const createInputElement = ({ type, id, label, initialValue, options }: CreateInputElementParams) => ({
|
||||
const createInputElement = ({ type, id, label, initialValue, validator, options }: CreateInputElementParams) => ({
|
||||
__html: `<input
|
||||
is="emby-input"
|
||||
type="${type}"
|
||||
id="${id}"
|
||||
label="${label}"
|
||||
value="${initialValue}"
|
||||
${validator ? 'pattern="' + validator.pattern + '"' : ''}
|
||||
${options}
|
||||
/>`
|
||||
/>
|
||||
<div class="inputElementInvalidMessage">
|
||||
${validator?.errMessage || ''}
|
||||
</div>`
|
||||
});
|
||||
|
||||
type InputElementProps = {
|
||||
|
@ -33,7 +40,9 @@ const InputElement: FC<InputElementProps> = ({
|
|||
type,
|
||||
id,
|
||||
label,
|
||||
validator,
|
||||
options = ''
|
||||
|
||||
}) => {
|
||||
const container = useRef<HTMLDivElement>(null);
|
||||
|
||||
|
@ -44,14 +53,16 @@ const InputElement: FC<InputElementProps> = ({
|
|||
id,
|
||||
label: globalize.translate(label),
|
||||
initialValue,
|
||||
validator,
|
||||
options
|
||||
})
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
), []);
|
||||
|
||||
const onInput = useCallback((e: Event) => {
|
||||
if (validator) (e.target as HTMLElement).parentElement?.querySelector('.inputElementInvalidMessage')?.classList.add('inputReadyForValidation');
|
||||
onChange((e.target as HTMLInputElement).value);
|
||||
}, [ onChange ]);
|
||||
}, [ onChange, validator ]);
|
||||
|
||||
useEffect(() => {
|
||||
const inputElement = container?.current?.querySelector<HTMLInputElement>('input');
|
||||
|
|
8
src/elements/InputElementInvalidMessage.scss
Normal file
8
src/elements/InputElementInvalidMessage.scss
Normal file
|
@ -0,0 +1,8 @@
|
|||
.inputElementInvalidMessage {
|
||||
color: red;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.emby-input:invalid + .inputElementInvalidMessage.inputReadyForValidation {
|
||||
display: block;
|
||||
}
|
|
@ -1124,6 +1124,7 @@
|
|||
"MessageImageTypeNotSelected": "Please select an image type from the drop-down menu.",
|
||||
"MessageInvalidForgotPasswordPin": "An invalid or expired PIN code was entered. Please try again.",
|
||||
"MessageInvalidUser": "Invalid username or password. Please try again.",
|
||||
"MessageInvalidUsernameFormat": "Username must not be empty and contain only numbers, letters, spaces, or the following symbols -'._@+",
|
||||
"MessageItemsAdded": "Items added.",
|
||||
"MessageItemSaved": "Item saved.",
|
||||
"MessageLeaveEmptyToInherit": "Leave empty to inherit settings from a parent item or the global default value.",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue