Fix type and lint errors after upgrading corresponding dependencies

This commit is contained in:
ErickSkrauch 2021-07-13 22:40:31 +02:00
parent 404fcb804a
commit 12f5e711c4
No known key found for this signature in database
GPG Key ID: 669339FCBB30EE0E
18 changed files with 151 additions and 159 deletions

View File

@ -41,11 +41,11 @@ export function authenticate(
} }
try { try {
const { token: newToken, refreshToken: newRefreshToken, user } = await validateToken( const {
accountId, token: newToken,
token, refreshToken: newRefreshToken,
refreshToken, user,
); } = await validateToken(accountId, token, refreshToken);
const newAccount: Account = { const newAccount: Account = {
id: user.id, id: user.id,
username: user.username, username: user.username,

View File

@ -405,7 +405,7 @@ class PanelTransition extends React.PureComponent<Props, State> {
getHeader({ key, style, data }: TransitionPlainStyle): ReactElement { getHeader({ key, style, data }: TransitionPlainStyle): ReactElement {
const { Title } = data as AnimationData; const { Title } = data as AnimationData;
const { transformSpring } = (style as unknown) as AnimationStyle; const { transformSpring } = style as unknown as AnimationStyle;
let { hasBackButton } = data; let { hasBackButton } = data;
@ -414,7 +414,7 @@ class PanelTransition extends React.PureComponent<Props, State> {
} }
const transitionStyle = { const transitionStyle = {
...this.getDefaultTransitionStyles(key, (style as unknown) as AnimationStyle), ...this.getDefaultTransitionStyles(key, style as unknown as AnimationStyle),
opacity: 1, // reset default opacity: 1, // reset default
}; };
@ -448,7 +448,7 @@ class PanelTransition extends React.PureComponent<Props, State> {
getBody({ key, style, data }: TransitionPlainStyle): ReactElement { getBody({ key, style, data }: TransitionPlainStyle): ReactElement {
const { Body } = data as AnimationData; const { Body } = data as AnimationData;
const { transformSpring } = (style as unknown) as AnimationStyle; const { transformSpring } = style as unknown as AnimationStyle;
const { direction } = this.state; const { direction } = this.state;
let transform = this.translate(transformSpring, direction); let transform = this.translate(transformSpring, direction);
@ -460,7 +460,7 @@ class PanelTransition extends React.PureComponent<Props, State> {
} }
const transitionStyle: CSSProperties = { const transitionStyle: CSSProperties = {
...this.getDefaultTransitionStyles(key, (style as unknown) as AnimationStyle), ...this.getDefaultTransitionStyles(key, style as unknown as AnimationStyle),
top: 'auto', // reset default top: 'auto', // reset default
[verticalOrigin]: 0, [verticalOrigin]: 0,
...transform, ...transform,
@ -486,7 +486,7 @@ class PanelTransition extends React.PureComponent<Props, State> {
getFooter({ key, style, data }: TransitionPlainStyle): ReactElement { getFooter({ key, style, data }: TransitionPlainStyle): ReactElement {
const { Footer } = data as AnimationData; const { Footer } = data as AnimationData;
const transitionStyle = this.getDefaultTransitionStyles(key, (style as unknown) as AnimationStyle); const transitionStyle = this.getDefaultTransitionStyles(key, style as unknown as AnimationStyle);
return ( return (
<div key={`footer/${key}`} style={transitionStyle}> <div key={`footer/${key}`} style={transitionStyle}>
@ -498,7 +498,7 @@ class PanelTransition extends React.PureComponent<Props, State> {
getLinks({ key, style, data }: TransitionPlainStyle): ReactElement { getLinks({ key, style, data }: TransitionPlainStyle): ReactElement {
const { Links } = data as AnimationData; const { Links } = data as AnimationData;
const transitionStyle = this.getDefaultTransitionStyles(key, (style as unknown) as AnimationStyle); const transitionStyle = this.getDefaultTransitionStyles(key, style as unknown as AnimationStyle);
return ( return (
<div key={`links/${key}`} style={transitionStyle}> <div key={`links/${key}`} style={transitionStyle}>

View File

@ -15,18 +15,19 @@ interface Props {
const AccountSwitcher: ComponentType<Props> = ({ accounts, onAccountClick }) => { const AccountSwitcher: ComponentType<Props> = ({ accounts, onAccountClick }) => {
const [selectedAccount, setSelectedAccount] = useState<number>(); const [selectedAccount, setSelectedAccount] = useState<number>();
const onAccountClickCallback = useCallback( const onAccountClickCallback = useCallback(
(account: Account): MouseEventHandler => async (event) => { (account: Account): MouseEventHandler =>
event.stopPropagation(); async (event) => {
event.stopPropagation();
setSelectedAccount(account.id); setSelectedAccount(account.id);
try { try {
if (onAccountClick) { if (onAccountClick) {
await onAccountClick(account); await onAccountClick(account);
}
} finally {
setSelectedAccount(undefined);
} }
} finally { },
setSelectedAccount(undefined);
}
},
[onAccountClick], [onAccountClick],
); );

View File

@ -44,7 +44,7 @@ const typeToForm: TypeToForm = {
type TypeToLabel = Record<ApplicationType, MessageDescriptor>; type TypeToLabel = Record<ApplicationType, MessageDescriptor>;
const typeToLabel: TypeToLabel = ((Object.keys(typeToForm) as unknown) as Array<ApplicationType>).reduce( const typeToLabel: TypeToLabel = (Object.keys(typeToForm) as unknown as Array<ApplicationType>).reduce(
(result, key) => { (result, key) => {
result[key] = typeToForm[key].label; result[key] = typeToForm[key].label;

View File

@ -14,7 +14,7 @@ interface Props {
const ApplicationTypeSwitcher: ComponentType<Props> = ({ appTypes, selectedType, setType }) => ( const ApplicationTypeSwitcher: ComponentType<Props> = ({ appTypes, selectedType, setType }) => (
<div> <div>
{((Object.keys(appTypes) as unknown) as Array<ApplicationType>).map((type) => ( {(Object.keys(appTypes) as unknown as Array<ApplicationType>).map((type) => (
<div className={styles.radioContainer} key={type}> <div className={styles.radioContainer} key={type}>
<Radio <Radio
onChange={() => setType(type)} onChange={() => setType(type)}

View File

@ -14,10 +14,11 @@ const FooterMenu: ComponentType = () => {
const dispatch = useReduxDispatch(); const dispatch = useReduxDispatch();
const createPopupHandler = useCallback( const createPopupHandler = useCallback(
(popup: ComponentType): MouseEventHandler<HTMLAnchorElement> => (event) => { (popup: ComponentType): MouseEventHandler<HTMLAnchorElement> =>
event.preventDefault(); (event) => {
dispatch(createPopup({ Popup: popup })); event.preventDefault();
}, dispatch(createPopup({ Popup: popup }));
},
[dispatch], [dispatch],
); );

View File

@ -11,7 +11,7 @@ import FormInputComponent from './FormInputComponent';
type I18nString = string | MessageDescriptor; type I18nString = string | MessageDescriptor;
type ItemLabel = I18nString | React.ReactElement; type ItemLabel = I18nString | React.ReactElement;
interface Props extends InputHTMLAttributes<HTMLInputElement> { interface Props extends InputHTMLAttributes<HTMLDivElement> {
label: I18nString; label: I18nString;
items: Record<string, ItemLabel>; items: Record<string, ItemLabel>;
block?: boolean; block?: boolean;

View File

@ -39,9 +39,7 @@ export default class FormModel {
* *
* @returns {object} - ref and name props for component * @returns {object} - ref and name props for component
*/ */
bindField( bindField(name: string): {
name: string,
): {
name: string; name: string;
ref: (el: any) => void; ref: (el: any) => void;
error?: ValidationError; error?: ValidationError;

View File

@ -27,19 +27,21 @@ const AccountSwitcher: ComponentType<Props> = ({
}) => { }) => {
const available = accounts.filter((account) => account.id !== activeAccount.id); const available = accounts.filter((account) => account.id !== activeAccount.id);
const onAccountClickCallback = useCallback( const onAccountClickCallback = useCallback(
(account: Account): MouseEventHandler => (event) => { (account: Account): MouseEventHandler =>
event.preventDefault(); (event) => {
onAccountClick(account); event.preventDefault();
}, onAccountClick(account);
},
[onAccountClick], [onAccountClick],
); );
const onAccountRemoveCallback = useCallback( const onAccountRemoveCallback = useCallback(
(account: Account): MouseEventHandler => (event) => { (account: Account): MouseEventHandler =>
event.preventDefault(); (event) => {
event.stopPropagation(); event.preventDefault();
event.stopPropagation();
onRemoveClick(account); onRemoveClick(account);
}, },
[onRemoveClick], [onRemoveClick],
); );

View File

@ -88,9 +88,7 @@ export { default as debounce } from 'debounce';
* *
* @returns {object} - decoded jwt payload * @returns {object} - decoded jwt payload
*/ */
export function getJwtPayloads( export function getJwtPayloads(jwt: string): {
jwt: string,
): {
sub: string; sub: string;
jti: number; jti: number;
exp: number; exp: number;

View File

@ -78,94 +78,96 @@ export default connect(
}), }),
{ {
refreshUserData, refreshUserData,
onSubmit: ({ form, sendData }: { form: FormModel; sendData: () => Promise<any> }) => (dispatch: Dispatch) => { onSubmit:
form.beginLoading(); ({ form, sendData }: { form: FormModel; sendData: () => Promise<any> }) =>
(dispatch: Dispatch) => {
form.beginLoading();
return sendData() return sendData()
.catch((resp) => { .catch((resp) => {
const requirePassword = resp.errors && !!resp.errors.password; const requirePassword = resp.errors && !!resp.errors.password;
// prevalidate user input, because requestPassword popup will block the // prevalidate user input, because requestPassword popup will block the
// entire form from input, so it must be valid // entire form from input, so it must be valid
if (resp.errors) { if (resp.errors) {
delete resp.errors.password; delete resp.errors.password;
if (resp.errors.email && resp.data && resp.data.canRepeatIn) { if (resp.errors.email && resp.data && resp.data.canRepeatIn) {
resp.errors.email = { resp.errors.email = {
type: resp.errors.email, type: resp.errors.email,
payload: { payload: {
msLeft: resp.data.canRepeatIn * 1000, msLeft: resp.data.canRepeatIn * 1000,
}, },
}; };
}
if (Object.keys(resp.errors).length) {
form.setErrors(resp.errors);
return Promise.reject(resp);
}
if (requirePassword) {
return requestPassword(form);
}
} }
if (Object.keys(resp.errors).length) { return Promise.reject(resp);
form.setErrors(resp.errors); })
.catch((resp) => {
if (!resp || !resp.errors) {
logger.warn('Unexpected profile editing error', {
resp,
});
} else {
return Promise.reject(resp); return Promise.reject(resp);
} }
})
.finally(() => form.endLoading());
if (requirePassword) { function requestPassword(form: FormModel) {
return requestPassword(form); return new Promise((resolve, reject) => {
} dispatch(
} createPopup({
Popup(props: { onClose: () => Promise<any> }) {
const onSubmit = () => {
form.beginLoading();
return Promise.reject(resp); sendData()
}) .then(resolve)
.catch((resp) => { .then(props.onClose)
if (!resp || !resp.errors) { .catch((resp) => {
logger.warn('Unexpected profile editing error', { if (resp.errors) {
resp, form.setErrors(resp.errors);
});
} else {
return Promise.reject(resp);
}
})
.finally(() => form.endLoading());
function requestPassword(form: FormModel) { const parentFormHasErrors =
return new Promise((resolve, reject) => { Object.keys(resp.errors).filter((name) => name !== 'password')
dispatch( .length > 0;
createPopup({
Popup(props: { onClose: () => Promise<any> }) {
const onSubmit = () => {
form.beginLoading();
sendData() if (parentFormHasErrors) {
.then(resolve) // something wrong with parent form, hiding popup and show that form
.then(props.onClose) props.onClose();
.catch((resp) => { reject(resp);
if (resp.errors) { logger.warn(
form.setErrors(resp.errors); 'Profile: can not submit password popup due to errors in source form',
{ resp },
const parentFormHasErrors = );
Object.keys(resp.errors).filter((name) => name !== 'password') }
.length > 0; } else {
return Promise.reject(resp);
if (parentFormHasErrors) {
// something wrong with parent form, hiding popup and show that form
props.onClose();
reject(resp);
logger.warn(
'Profile: can not submit password popup due to errors in source form',
{ resp },
);
} }
} else { })
return Promise.reject(resp); .finally(() => form.endLoading());
} };
})
.finally(() => form.endLoading());
};
return <PasswordRequestForm form={form} onSubmit={onSubmit} />; return <PasswordRequestForm form={form} onSubmit={onSubmit} />;
}, },
// TODO: this property should be automatically extracted from the popup's isClosable prop // TODO: this property should be automatically extracted from the popup's isClosable prop
disableOverlayClose: true, disableOverlayClose: true,
}), }),
); );
}); });
} }
}, },
}, },
)(ProfileController); )(ProfileController);

View File

@ -1,8 +1,6 @@
import request, { Resp } from 'app/services/request'; import request, { Resp } from 'app/services/request';
export function getSecret( export function getSecret(id: number): Promise<
id: number,
): Promise<
Resp<{ Resp<{
qr: string; qr: string;
secret: string; secret: string;

View File

@ -66,9 +66,7 @@ class I18N {
await intlPolyfill('en'); await intlPolyfill('en');
} }
async require( async require(locale: string): Promise<{
locale: string,
): Promise<{
locale: string; locale: string;
messages: Record<string, string>; messages: Record<string, string>;
}> { }> {

View File

@ -267,25 +267,23 @@ async function pull(): Promise<void> {
}); });
let downloadingReady = 0; let downloadingReady = 0;
const promises = localesToPull.map( const promises = localesToPull.map(async (languageId): Promise<void> => {
async (languageId): Promise<void> => { const {
const { data: { url },
data: { url }, } = await crowdin.translationsApi.buildProjectFileTranslation(PROJECT_ID, fileId, {
} = await crowdin.translationsApi.buildProjectFileTranslation(PROJECT_ID, fileId, { targetLanguageId: languageId,
targetLanguageId: languageId, });
});
const { data: fileContents } = await axios.get(url, { const { data: fileContents } = await axios.get(url, {
// Disable response parsing // Disable response parsing
transformResponse: [], transformResponse: [],
}); });
fs.writeFileSync(getLocaleFilePath(languageId), fileContents); fs.writeFileSync(getLocaleFilePath(languageId), fileContents);
downloadingProgressBar.update(++downloadingReady / localesToPull.length, { downloadingProgressBar.update(++downloadingReady / localesToPull.length, {
cCurrent: downloadingReady, cCurrent: downloadingReady,
}); });
}, });
);
await Promise.all(promises); await Promise.all(promises);

View File

@ -12,13 +12,15 @@ module.exports = ({ webpackLoaderContext: loader }) => ({
'postcss-import': { 'postcss-import': {
addModulesDirectories: ['./src'], addModulesDirectories: ['./src'],
resolve: ((defaultResolve) => (url, basedir, importOptions) => resolve: (
defaultResolve( (defaultResolve) => (url, basedir, importOptions) =>
// mainly to remove '~' from request defaultResolve(
loaderUtils.urlToRequest(url), // mainly to remove '~' from request
basedir, loaderUtils.urlToRequest(url),
importOptions, basedir,
))(require('postcss-import/lib/resolve-id')), importOptions,
)
)(require('postcss-import/lib/resolve-id')),
load: ((defaultLoad) => (filename, importOptions) => { load: ((defaultLoad) => (filename, importOptions) => {
if (/\.font.(js|json)$/.test(filename)) { if (/\.font.(js|json)$/.test(filename)) {

View File

@ -240,8 +240,7 @@ function createState() {
id: 7, id: 7,
username: 'SleepWalker', username: 'SleepWalker',
email: 'danilenkos@auroraglobal.com', email: 'danilenkos@auroraglobal.com',
token: token: 'eyJhbGciOiJIUzI1NiJ9.eyJlbHktc2NvcGVzIjoiYWNjb3VudHNfd2ViX3VzZXIiLCJpYXQiOjE1MTgzNzM4MDksImV4cCI6MTUxODM3NzQwOSwic3ViIjoiZWx5fDciLCJqdGkiOjM1NDh9.Fv4AbJ0iDbrH3bhbgF0ViJLfYYiwH78deR4fMlMhKrQ',
'eyJhbGciOiJIUzI1NiJ9.eyJlbHktc2NvcGVzIjoiYWNjb3VudHNfd2ViX3VzZXIiLCJpYXQiOjE1MTgzNzM4MDksImV4cCI6MTUxODM3NzQwOSwic3ViIjoiZWx5fDciLCJqdGkiOjM1NDh9.Fv4AbJ0iDbrH3bhbgF0ViJLfYYiwH78deR4fMlMhKrQ',
refreshToken: refreshToken:
'3gh6ZZ3R9jGeFdp0TmlY7sd0zBxH6Zfq48M86eUAv952RcAKx32RAnjlKkgd6i-MV-RKbjtADIdoRwMUWOYQjEYtwwXPjcQJ', '3gh6ZZ3R9jGeFdp0TmlY7sd0zBxH6Zfq48M86eUAv952RcAKx32RAnjlKkgd6i-MV-RKbjtADIdoRwMUWOYQjEYtwwXPjcQJ',
}, },
@ -249,8 +248,7 @@ function createState() {
id: 102, id: 102,
username: 'test', username: 'test',
email: 'admin@udf.su', email: 'admin@udf.su',
token: token: 'eyJhbGciOiJIUzI1NiJ9.eyJlbHktc2NvcGVzIjoiYWNjb3VudHNfd2ViX3VzZXIiLCJpYXQiOjE1MTgzNzM4NjUsImV4cCI6MTUxODM3NzQ2NSwic3ViIjoiZWx5fDEwMiIsImp0aSI6MzU0OX0.eJEgvXT3leGqBe3tYNGZb0E4WEvWfrLPjcD7eNjyQYO',
'eyJhbGciOiJIUzI1NiJ9.eyJlbHktc2NvcGVzIjoiYWNjb3VudHNfd2ViX3VzZXIiLCJpYXQiOjE1MTgzNzM4NjUsImV4cCI6MTUxODM3NzQ2NSwic3ViIjoiZWx5fDEwMiIsImp0aSI6MzU0OX0.eJEgvXT3leGqBe3tYNGZb0E4WEvWfrLPjcD7eNjyQYO',
refreshToken: refreshToken:
'Al75SIx-LFOCP7kaqZBVqMVmSljJw9_bdFQGyuM64c6ShP7YsXbkCD8vPOundAwUDfRZqsIbOHUROmAHPB0VBfjLfw96yqxx', 'Al75SIx-LFOCP7kaqZBVqMVmSljJw9_bdFQGyuM64c6ShP7YsXbkCD8vPOundAwUDfRZqsIbOHUROmAHPB0VBfjLfw96yqxx',
}, },

View File

@ -6,7 +6,7 @@ describe('Applications', () => {
// remove all previously added apps // remove all previously added apps
cy.window().then(async (win) => { cy.window().then(async (win) => {
const { oauthApi } = (win as any) as { const { oauthApi } = win as any as {
oauthApi: typeof import('app/services/api/oauth').default; oauthApi: typeof import('app/services/api/oauth').default;
}; };
const apps = await oauthApi.getAppsByUser(user.id); const apps = await oauthApi.getAppsByUser(user.id);

View File

@ -32,11 +32,7 @@ declare namespace Cypress {
*/ */
rawApiResp?: false; rawApiResp?: false;
}): Promise<{ accounts: TAccount[] }>; }): Promise<{ accounts: TAccount[] }>;
login(options: { login(options: { accounts: AccountAlias[]; updateState?: boolean; rawApiResp: true }): Promise<{
accounts: AccountAlias[];
updateState?: boolean;
rawApiResp: true;
}): Promise<{
accounts: { accounts: {
success: true; success: true;
access_token: string; access_token: string;