mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
merged
This commit is contained in:
commit
1278c3230a
11 changed files with 80 additions and 6 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,
|
||||
});
|
15
src/redux/node/api.ts
Normal file
15
src/redux/node/api.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { api, configWithToken, resultMiddleware, errorMiddleware } from '~/utils/api';
|
||||
import { INode, IResultWithStatus } from '../types';
|
||||
import { API } from '~/constants/api';
|
||||
|
||||
export const postNode = ({
|
||||
access,
|
||||
node,
|
||||
}: {
|
||||
access: string,
|
||||
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;
|
||||
|
@ -112,4 +113,9 @@ export interface INode {
|
|||
updatedAt?: string;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
export type IUploadProgressHandler = (progressEvent: any) => void;
|
||||
=======
|
||||
export type IUploadProgressHandler = (current: number, total: number) => void;
|
||||
export type IValidationErrors = Record<string, keyof typeof ERRORS>;
|
||||
>>>>>>> 148974ab7db3e8500e236e312dd546d39e5c322b
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import {
|
||||
IResultWithStatus, IFile, IUploadProgressHandler, IFileWithUUID,
|
||||
} from '~/redux/types';
|
||||
import { api, configWithToken } from '~/utils/api';
|
||||
import {
|
||||
api, configWithToken, resultMiddleware, errorMiddleware,
|
||||
} from '~/utils/api';
|
||||
|
||||
import { API } from '~/constants/api';
|
||||
|
||||
export const postUploadFile = ({
|
||||
|
@ -21,5 +24,7 @@ export const postUploadFile = ({
|
|||
API.USER.UPLOAD(target, type),
|
||||
data,
|
||||
configWithToken(access, { onUploadProgress: onProgress })
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware)
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue