mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
saving node and showing dialog
This commit is contained in:
parent
95443635b4
commit
05980ce440
4 changed files with 14 additions and 6 deletions
|
@ -1,7 +1,7 @@
|
|||
import { INode } from '../types';
|
||||
import { FLOW_ACTIONS } from './constants';
|
||||
import { IFlowState } from './reducer';
|
||||
|
||||
export const flowSetNodes = (nodes: INode[]) => ({
|
||||
export const flowSetNodes = (nodes: IFlowState['nodes']) => ({
|
||||
nodes,
|
||||
type: FLOW_ACTIONS.SET_NODES,
|
||||
});
|
||||
|
|
|
@ -3,20 +3,27 @@ import { NODE_ACTIONS } from './constants';
|
|||
import { nodeSave, nodeSetSaveErrors } from './actions';
|
||||
import { postNode } from './api';
|
||||
import { reqWrapper } from '../auth/sagas';
|
||||
import { flowSetNodes } from '../flow/actions';
|
||||
import { ERRORS } from '~/constants/errors';
|
||||
import { modalSetShown } from '../modal/actions';
|
||||
|
||||
function* onNodeSave({ node }: ReturnType<typeof nodeSave>) {
|
||||
yield put(nodeSetSaveErrors({}));
|
||||
|
||||
const {
|
||||
data,
|
||||
data: { errors },
|
||||
data: { errors, node: result },
|
||||
} = yield call(reqWrapper, postNode, { node });
|
||||
|
||||
if (errors && Object.values(errors).length > 0) {
|
||||
return yield put(nodeSetSaveErrors(errors));
|
||||
}
|
||||
|
||||
console.log({ data, errors });
|
||||
if (!result || !result.id) {
|
||||
return yield put(nodeSetSaveErrors({ error: ERRORS.EMPTY_RESPONSE }));
|
||||
}
|
||||
|
||||
yield put(flowSetNodes({ [result.id]: result }));
|
||||
yield put(modalSetShown(false));
|
||||
}
|
||||
|
||||
export default function* nodeSaga() {
|
||||
|
|
|
@ -114,4 +114,4 @@ export interface INode {
|
|||
}
|
||||
|
||||
export type IUploadProgressHandler = (progress: ProgressEvent) => void;
|
||||
export type IValidationErrors = Record<string, keyof typeof ERRORS>;
|
||||
export type IValidationErrors = Record<string, ValueOf<typeof ERRORS>>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue