mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
merged
This commit is contained in:
commit
1278c3230a
11 changed files with 80 additions and 6 deletions
|
@ -5,4 +5,7 @@ export const API = {
|
||||||
ME: '/auth/me', //
|
ME: '/auth/me', //
|
||||||
UPLOAD: (target, type) => `/upload/${target}/${type}`,
|
UPLOAD: (target, type) => `/upload/${target}/${type}`,
|
||||||
},
|
},
|
||||||
|
NODE: {
|
||||||
|
SAVE: '/node/',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
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 { moveArrItem } from '~/utils/fn';
|
||||||
import { IFile, IFileWithUUID } from '~/redux/types';
|
import { IFile, IFileWithUUID } from '~/redux/types';
|
||||||
import * as UPLOAD_ACTIONS from '~/redux/uploads/actions';
|
import * as UPLOAD_ACTIONS from '~/redux/uploads/actions';
|
||||||
|
import * as NODE_ACTIONS from '~/redux/node/actions';
|
||||||
import { selectUploads } from '~/redux/uploads/selectors';
|
import { selectUploads } from '~/redux/uploads/selectors';
|
||||||
import { UPLOAD_TARGETS, UPLOAD_TYPES, UPLOAD_SUBJECTS } from '~/redux/uploads/constants';
|
import { UPLOAD_TARGETS, UPLOAD_TYPES, UPLOAD_SUBJECTS } from '~/redux/uploads/constants';
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ const mapStateToProps = (state) => {
|
||||||
|
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
uploadUploadFiles: UPLOAD_ACTIONS.uploadUploadFiles,
|
uploadUploadFiles: UPLOAD_ACTIONS.uploadUploadFiles,
|
||||||
|
nodeSave: NODE_ACTIONS.nodeSave,
|
||||||
};
|
};
|
||||||
|
|
||||||
type IProps = IDialogProps & ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {};
|
type IProps = IDialogProps & ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {};
|
||||||
|
@ -38,9 +40,11 @@ type IProps = IDialogProps & ReturnType<typeof mapStateToProps> & typeof mapDisp
|
||||||
const EditorDialogUnconnected: FC<IProps> = ({
|
const EditorDialogUnconnected: FC<IProps> = ({
|
||||||
onRequestClose,
|
onRequestClose,
|
||||||
editor,
|
editor,
|
||||||
uploadUploadFiles,
|
|
||||||
files,
|
files,
|
||||||
statuses,
|
statuses,
|
||||||
|
|
||||||
|
uploadUploadFiles,
|
||||||
|
nodeSave,
|
||||||
}) => {
|
}) => {
|
||||||
const [data, setData] = useState(editor);
|
const [data, setData] = useState(editor);
|
||||||
const eventPreventer = useCallback(event => event.preventDefault(), []);
|
const eventPreventer = useCallback(event => event.preventDefault(), []);
|
||||||
|
@ -139,8 +143,9 @@ const EditorDialogUnconnected: FC<IProps> = ({
|
||||||
|
|
||||||
const onSubmit = useCallback((event: FormEvent) => {
|
const onSubmit = useCallback((event: FormEvent) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
nodeSave(data);
|
||||||
console.log({ data });
|
console.log({ data });
|
||||||
}, [data]);
|
}, [data, nodeSave]);
|
||||||
|
|
||||||
const buttons = (
|
const buttons = (
|
||||||
<Padder style={{ position: 'relative' }}>
|
<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,
|
||||||
|
});
|
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';
|
import { IBlock, INode } from '../types';
|
||||||
|
|
||||||
|
export const NODE_ACTIONS = {
|
||||||
|
SAVE: 'NODE.SAVE',
|
||||||
|
SET_SAVE_ERRORS: 'NODE.SET_SAVE_ERRORS',
|
||||||
|
};
|
||||||
|
|
||||||
export const EMPTY_BLOCK: IBlock = {
|
export const EMPTY_BLOCK: IBlock = {
|
||||||
type: null,
|
type: null,
|
||||||
files: [],
|
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 { DetailedHTMLProps, InputHTMLAttributes } from 'react';
|
||||||
import { DIALOGS } from '~/redux/modal/constants';
|
import { DIALOGS } from '~/redux/modal/constants';
|
||||||
|
import { ERRORS } from '~/constants/errors';
|
||||||
|
|
||||||
export interface ITag {
|
export interface ITag {
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -112,4 +113,9 @@ export interface INode {
|
||||||
updatedAt?: string;
|
updatedAt?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
export type IUploadProgressHandler = (progressEvent: any) => void;
|
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 {
|
import {
|
||||||
IResultWithStatus, IFile, IUploadProgressHandler, IFileWithUUID,
|
IResultWithStatus, IFile, IUploadProgressHandler, IFileWithUUID,
|
||||||
} from '~/redux/types';
|
} from '~/redux/types';
|
||||||
import { api, configWithToken } from '~/utils/api';
|
import {
|
||||||
|
api, configWithToken, resultMiddleware, errorMiddleware,
|
||||||
|
} from '~/utils/api';
|
||||||
|
|
||||||
import { API } from '~/constants/api';
|
import { API } from '~/constants/api';
|
||||||
|
|
||||||
export const postUploadFile = ({
|
export const postUploadFile = ({
|
||||||
|
@ -21,5 +24,7 @@ export const postUploadFile = ({
|
||||||
API.USER.UPLOAD(target, type),
|
API.USER.UPLOAD(target, type),
|
||||||
data,
|
data,
|
||||||
configWithToken(access, { onUploadProgress: onProgress })
|
configWithToken(access, { onUploadProgress: onProgress })
|
||||||
|
.then(resultMiddleware)
|
||||||
|
.catch(errorMiddleware)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,6 @@
|
||||||
"~/*": ["src/*"]
|
"~/*": ["src/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["./src/index.tsx", "./custom.d.ts"],
|
"include": ["./src/**/*", "./custom.d.ts"],
|
||||||
"exclude": ["./__tests__/**/*"]
|
"exclude": ["./__tests__/**/*"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue