mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
refactored component errors
This commit is contained in:
parent
7031084b09
commit
d4c2e7ee09
79 changed files with 573 additions and 462 deletions
|
@ -1,9 +1,9 @@
|
|||
import React, { FC, MouseEventHandler, ReactElement, useEffect, useRef } from "react";
|
||||
import styles from "./styles.module.scss";
|
||||
import { clearAllBodyScrollLocks, disableBodyScroll } from "body-scroll-lock";
|
||||
import { Icon } from "~/components/input/Icon";
|
||||
import { LoaderCircle } from "~/components/input/LoaderCircle";
|
||||
import { useCloseOnEscape } from "~/utils/hooks";
|
||||
import React, { FC, MouseEventHandler, ReactElement, useEffect, useRef } from 'react';
|
||||
import styles from './styles.module.scss';
|
||||
import { clearAllBodyScrollLocks, disableBodyScroll } from 'body-scroll-lock';
|
||||
import { Icon } from '~/components/input/Icon';
|
||||
import { LoaderCircle } from '~/components/input/LoaderCircle';
|
||||
import { useCloseOnEscape } from '~/utils/hooks';
|
||||
|
||||
interface IProps {
|
||||
children: React.ReactChild;
|
||||
|
@ -14,7 +14,7 @@ interface IProps {
|
|||
width?: number;
|
||||
error?: string;
|
||||
is_loading?: boolean;
|
||||
overlay?: ReactElement;
|
||||
overlay?: JSX.Element;
|
||||
|
||||
onOverlayClick?: MouseEventHandler<HTMLDivElement>;
|
||||
onRefCapture?: (ref: any) => void;
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
import React, { createElement, FC, FormEvent, useCallback, useEffect, useState } from 'react';
|
||||
import React, {
|
||||
createElement,
|
||||
FC,
|
||||
FormEvent,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { IDialogProps } from '~/redux/modal/constants';
|
||||
import { useCloseOnEscape } from '~/utils/hooks';
|
||||
|
@ -16,6 +24,7 @@ import { EMPTY_NODE, NODE_EDITORS } from '~/redux/node/constants';
|
|||
import { BetterScrollDialog } from '../BetterScrollDialog';
|
||||
import { CoverBackdrop } from '~/components/containers/CoverBackdrop';
|
||||
import { IEditorComponentProps } from '~/redux/node/types';
|
||||
import { has, values } from 'ramda';
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const { editor, errors } = selectNode(state);
|
||||
|
@ -32,7 +41,7 @@ const mapDispatchToProps = {
|
|||
type IProps = IDialogProps &
|
||||
ReturnType<typeof mapStateToProps> &
|
||||
typeof mapDispatchToProps & {
|
||||
type: keyof typeof NODE_EDITORS;
|
||||
type: string;
|
||||
};
|
||||
|
||||
const EditorDialogUnconnected: FC<IProps> = ({
|
||||
|
@ -44,7 +53,7 @@ const EditorDialogUnconnected: FC<IProps> = ({
|
|||
type,
|
||||
}) => {
|
||||
const [data, setData] = useState(EMPTY_NODE);
|
||||
const [temp, setTemp] = useState([]);
|
||||
const [temp, setTemp] = useState<string[]>([]);
|
||||
|
||||
useEffect(() => setData(editor), [editor]);
|
||||
|
||||
|
@ -93,9 +102,18 @@ const EditorDialogUnconnected: FC<IProps> = ({
|
|||
|
||||
useCloseOnEscape(onRequestClose);
|
||||
|
||||
const error = errors && Object.values(errors)[0];
|
||||
const error = values(errors)[0];
|
||||
const component = useMemo(() => {
|
||||
if (!has(type, NODE_EDITORS)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!Object.prototype.hasOwnProperty.call(NODE_EDITORS, type)) return null;
|
||||
return NODE_EDITORS[type];
|
||||
}, [type]);
|
||||
|
||||
if (!component) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={onSubmit} className={styles.form}>
|
||||
|
@ -107,7 +125,7 @@ const EditorDialogUnconnected: FC<IProps> = ({
|
|||
onClose={onRequestClose}
|
||||
>
|
||||
<div className={styles.editor}>
|
||||
{createElement(NODE_EDITORS[type], {
|
||||
{createElement(component, {
|
||||
data,
|
||||
setData,
|
||||
temp,
|
||||
|
|
|
@ -80,7 +80,7 @@ const LoginDialogUnconnected: FC<IProps> = ({
|
|||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (error) userSetLoginError(null);
|
||||
if (error) userSetLoginError('');
|
||||
}, [username, password]);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
@ -3,9 +3,10 @@ import { Button } from '~/components/input/Button';
|
|||
import { Grid } from '~/components/containers/Grid';
|
||||
import { Group } from '~/components/containers/Group';
|
||||
import styles from './styles.module.scss';
|
||||
import { ISocialProvider } from '~/redux/auth/types';
|
||||
|
||||
interface IProps {
|
||||
openOauthWindow: (provider: string) => MouseEventHandler;
|
||||
openOauthWindow: (provider: ISocialProvider) => MouseEventHandler;
|
||||
}
|
||||
|
||||
const LoginDialogButtons: FC<IProps> = ({ openOauthWindow }) => (
|
||||
|
|
|
@ -24,7 +24,7 @@ const ModalUnconnected: FC<IProps> = ({
|
|||
}) => {
|
||||
const onRequestClose = useCallback(() => {
|
||||
modalSetShown(false);
|
||||
modalSetDialog(null);
|
||||
modalSetDialog('');
|
||||
}, [modalSetShown, modalSetDialog]);
|
||||
|
||||
if (!dialog || !DIALOG_CONTENT[dialog] || !is_shown) return null;
|
||||
|
@ -43,10 +43,7 @@ const ModalUnconnected: FC<IProps> = ({
|
|||
);
|
||||
};
|
||||
|
||||
const Modal = connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(ModalUnconnected);
|
||||
const Modal = connect(mapStateToProps, mapDispatchToProps)(ModalUnconnected);
|
||||
|
||||
export { ModalUnconnected, Modal };
|
||||
|
||||
|
|
|
@ -78,7 +78,9 @@ const PhotoSwipeUnconnected: FC<Props> = ({ photoswipe, modalSetShown }) => {
|
|||
|
||||
useEffect(() => {
|
||||
window.location.hash = 'preview';
|
||||
return () => (window.location.hash = '');
|
||||
return () => {
|
||||
window.location.hash = '';
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React, { FC, useState, useMemo, useCallback, useEffect } from 'react';
|
||||
import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { IDialogProps } from '~/redux/types';
|
||||
import { connect } from 'react-redux';
|
||||
import { BetterScrollDialog } from '../BetterScrollDialog';
|
||||
|
@ -49,7 +49,7 @@ const RestorePasswordDialogUnconnected: FC<IProps> = ({
|
|||
|
||||
useEffect(() => {
|
||||
if (error || is_succesfull) {
|
||||
authSetRestore({ error: null, is_succesfull: false });
|
||||
authSetRestore({ error: '', is_succesfull: false });
|
||||
}
|
||||
}, [password, password_again]);
|
||||
|
||||
|
@ -69,7 +69,7 @@ const RestorePasswordDialogUnconnected: FC<IProps> = ({
|
|||
<Icon icon="check" size={64} />
|
||||
|
||||
<div>Пароль обновлен</div>
|
||||
<div>Добро пожаловать домой, ~{user.username}!</div>
|
||||
<div>Добро пожаловать домой, ~{user?.username}!</div>
|
||||
|
||||
<div />
|
||||
|
||||
|
@ -77,14 +77,16 @@ const RestorePasswordDialogUnconnected: FC<IProps> = ({
|
|||
Ура!
|
||||
</Button>
|
||||
</Group>
|
||||
) : null,
|
||||
) : (
|
||||
undefined
|
||||
),
|
||||
[is_succesfull]
|
||||
);
|
||||
|
||||
const not_ready = useMemo(() => (is_loading && !user ? <div className={styles.shade} /> : null), [
|
||||
is_loading,
|
||||
user,
|
||||
]);
|
||||
const not_ready = useMemo(
|
||||
() => (is_loading && !user ? <div className={styles.shade} /> : undefined),
|
||||
[is_loading, user]
|
||||
);
|
||||
|
||||
const invalid_code = useMemo(
|
||||
() =>
|
||||
|
@ -100,7 +102,9 @@ const RestorePasswordDialogUnconnected: FC<IProps> = ({
|
|||
Очень жаль
|
||||
</Button>
|
||||
</Group>
|
||||
) : null,
|
||||
) : (
|
||||
undefined
|
||||
),
|
||||
[is_loading, user, error]
|
||||
);
|
||||
|
||||
|
@ -135,7 +139,7 @@ const RestorePasswordDialogUnconnected: FC<IProps> = ({
|
|||
type="password"
|
||||
value={password_again}
|
||||
handler={setPasswordAgain}
|
||||
error={password_again && doesnt_match && ERROR_LITERAL[ERRORS.DOESNT_MATCH]}
|
||||
error={password_again && doesnt_match ? ERROR_LITERAL[ERRORS.DOESNT_MATCH] : ''}
|
||||
/>
|
||||
|
||||
<Group className={styles.text}>
|
||||
|
|
|
@ -43,7 +43,7 @@ const RestoreRequestDialogUnconnected: FC<IProps> = ({
|
|||
|
||||
useEffect(() => {
|
||||
if (error || is_succesfull) {
|
||||
authSetRestore({ error: null, is_succesfull: false });
|
||||
authSetRestore({ error: '', is_succesfull: false });
|
||||
}
|
||||
}, [field]);
|
||||
|
||||
|
@ -72,7 +72,9 @@ const RestoreRequestDialogUnconnected: FC<IProps> = ({
|
|||
Отлично!
|
||||
</Button>
|
||||
</Group>
|
||||
) : null,
|
||||
) : (
|
||||
undefined
|
||||
),
|
||||
[is_succesfull]
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue