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,4 +1,5 @@
|
||||||
export const ERRORS = {
|
export const ERRORS = {
|
||||||
NOT_AN_EMAIL: 'Not_An_Email',
|
NOT_AN_EMAIL: 'Not_An_Email',
|
||||||
TOO_SHIRT: 'Is_Too_Shirt',
|
TOO_SHIRT: 'Is_Too_Shirt',
|
||||||
|
EMPTY_RESPONSE: 'Empty_Response',
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { INode } from '../types';
|
|
||||||
import { FLOW_ACTIONS } from './constants';
|
import { FLOW_ACTIONS } from './constants';
|
||||||
|
import { IFlowState } from './reducer';
|
||||||
|
|
||||||
export const flowSetNodes = (nodes: INode[]) => ({
|
export const flowSetNodes = (nodes: IFlowState['nodes']) => ({
|
||||||
nodes,
|
nodes,
|
||||||
type: FLOW_ACTIONS.SET_NODES,
|
type: FLOW_ACTIONS.SET_NODES,
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,20 +3,27 @@ import { NODE_ACTIONS } from './constants';
|
||||||
import { nodeSave, nodeSetSaveErrors } from './actions';
|
import { nodeSave, nodeSetSaveErrors } from './actions';
|
||||||
import { postNode } from './api';
|
import { postNode } from './api';
|
||||||
import { reqWrapper } from '../auth/sagas';
|
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>) {
|
function* onNodeSave({ node }: ReturnType<typeof nodeSave>) {
|
||||||
yield put(nodeSetSaveErrors({}));
|
yield put(nodeSetSaveErrors({}));
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data,
|
data: { errors, node: result },
|
||||||
data: { errors },
|
|
||||||
} = yield call(reqWrapper, postNode, { node });
|
} = yield call(reqWrapper, postNode, { node });
|
||||||
|
|
||||||
if (errors && Object.values(errors).length > 0) {
|
if (errors && Object.values(errors).length > 0) {
|
||||||
return yield put(nodeSetSaveErrors(errors));
|
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() {
|
export default function* nodeSaga() {
|
||||||
|
|
|
@ -114,4 +114,4 @@ export interface INode {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IUploadProgressHandler = (progress: ProgressEvent) => void;
|
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