mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
node api
This commit is contained in:
parent
a662256221
commit
148974ab7d
8 changed files with 56 additions and 9 deletions
4
src/constants/errors.ts
Normal file
4
src/constants/errors.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export const ERRORS = {
|
||||
NOT_AN_EMAIL: 'Not_An_Email',
|
||||
TOO_SHIRT: 'Is_Too_Shirt',
|
||||
};
|
|
@ -19,6 +19,7 @@ import { EditorPanel } from '~/components/editors/EditorPanel';
|
|||
import { moveArrItem } from '~/utils/fn';
|
||||
import { IFile, IFileWithUUID } from '~/redux/types';
|
||||
import * as UPLOAD_ACTIONS from '~/redux/uploads/actions';
|
||||
import * as NODE_ACTIONS from '~/redux/node/actions';
|
||||
import { selectUploads } from '~/redux/uploads/selectors';
|
||||
import { UPLOAD_TARGETS, UPLOAD_TYPES, UPLOAD_SUBJECTS } from '~/redux/uploads/constants';
|
||||
|
||||
|
@ -31,6 +32,7 @@ const mapStateToProps = (state) => {
|
|||
|
||||
const mapDispatchToProps = {
|
||||
uploadUploadFiles: UPLOAD_ACTIONS.uploadUploadFiles,
|
||||
nodeSave: NODE_ACTIONS.nodeSave,
|
||||
};
|
||||
|
||||
type IProps = IDialogProps & ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {};
|
||||
|
@ -38,9 +40,11 @@ type IProps = IDialogProps & ReturnType<typeof mapStateToProps> & typeof mapDisp
|
|||
const EditorDialogUnconnected: FC<IProps> = ({
|
||||
onRequestClose,
|
||||
editor,
|
||||
uploadUploadFiles,
|
||||
files,
|
||||
statuses,
|
||||
|
||||
uploadUploadFiles,
|
||||
nodeSave,
|
||||
}) => {
|
||||
const [data, setData] = useState(editor);
|
||||
const eventPreventer = useCallback(event => event.preventDefault(), []);
|
||||
|
@ -139,8 +143,9 @@ const EditorDialogUnconnected: FC<IProps> = ({
|
|||
|
||||
const onSubmit = useCallback((event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
nodeSave(data);
|
||||
console.log({ data });
|
||||
}, [data]);
|
||||
}, [data, nodeSave]);
|
||||
|
||||
const buttons = (
|
||||
<Padder style={{ position: 'relative' }}>
|
||||
|
|
12
src/redux/node/actions.ts
Normal file
12
src/redux/node/actions.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { INode, IValidationErrors } from '../types';
|
||||
import { NODE_ACTIONS } from './constants';
|
||||
|
||||
export const nodeSave = (node: INode) => ({
|
||||
node,
|
||||
type: NODE_ACTIONS.SAVE,
|
||||
});
|
||||
|
||||
export const nodeSetSaveErrors = (errors: IValidationErrors) => ({
|
||||
errors,
|
||||
type: NODE_ACTIONS.SET_SAVE_ERRORS,
|
||||
});
|
|
@ -1,15 +1,15 @@
|
|||
import { api, configWithToken, resultMiddleware, errorMiddleware } from '~/utils/api';
|
||||
import { INode } from '../types';
|
||||
import { INode, IResultWithStatus } from '../types';
|
||||
import { API } from '~/constants/api';
|
||||
|
||||
export const postNode = ({
|
||||
access,
|
||||
data,
|
||||
node,
|
||||
}: {
|
||||
access: string,
|
||||
data: INode,
|
||||
}) => (
|
||||
api.post(API.NODE.SAVE, { data }, configWithToken(access))
|
||||
node: INode,
|
||||
}): Promise<IResultWithStatus<INode>> => (
|
||||
api.post(API.NODE.SAVE, { node }, configWithToken(access))
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware)
|
||||
);
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import { IBlock, INode } from '../types';
|
||||
|
||||
export const NODE_ACTIONS = {
|
||||
SAVE: 'NODE.SAVE',
|
||||
SET_SAVE_ERRORS: 'NODE.SET_SAVE_ERRORS',
|
||||
};
|
||||
|
||||
export const EMPTY_BLOCK: IBlock = {
|
||||
type: null,
|
||||
files: [],
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
export const NODE_HANDLERS = {
|
||||
import assocPath from 'ramda/es/assocPath';
|
||||
import { NODE_ACTIONS } from './constants';
|
||||
import { nodeSetSaveErrors } from './actions';
|
||||
import { INodeState } from './reducer';
|
||||
|
||||
const setSaveErrors = (state: INodeState, { errors }: ReturnType<typeof nodeSetSaveErrors>) => assocPath(['errors'], errors, state);
|
||||
|
||||
export const NODE_HANDLERS = {
|
||||
[NODE_ACTIONS.SAVE]: setSaveErrors,
|
||||
};
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
export default function* nodeSaga() {
|
||||
import { takeLatest, call } from 'redux-saga/effects';
|
||||
import { NODE_ACTIONS } from './constants';
|
||||
import { nodeSave } from './actions';
|
||||
import { postNode } from './api';
|
||||
import { reqWrapper } from '../auth/sagas';
|
||||
|
||||
function* onNodeSave({ node }: ReturnType<typeof nodeSave>) {
|
||||
const { data, errors } = yield call(reqWrapper, postNode, { node });
|
||||
|
||||
console.log({ data, errors });
|
||||
}
|
||||
|
||||
export default function* nodeSaga() {
|
||||
yield takeLatest(NODE_ACTIONS.SAVE, onNodeSave);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { DetailedHTMLProps, InputHTMLAttributes } from 'react';
|
||||
import { DIALOGS } from '~/redux/modal/constants';
|
||||
import { ERRORS } from '~/constants/errors';
|
||||
|
||||
export interface ITag {
|
||||
title: string;
|
||||
|
@ -113,3 +114,4 @@ export interface INode {
|
|||
}
|
||||
|
||||
export type IUploadProgressHandler = (current: number, total: number) => void;
|
||||
export type IValidationErrors = Record<string, keyof typeof ERRORS>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue