mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
node api
This commit is contained in:
parent
a662256221
commit
148974ab7d
8 changed files with 56 additions and 9 deletions
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