1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

#58 fixed dialog routers

This commit is contained in:
Fedor Katurov 2021-03-29 17:45:54 +07:00
parent 3e8c2d4b6e
commit 124719c243
15 changed files with 93 additions and 39 deletions

View file

@ -7,11 +7,6 @@ export const nodeSet = (node: Partial<INodeState>) => ({
type: NODE_ACTIONS.SET,
});
export const nodeSave = (node: INode) => ({
node,
type: NODE_ACTIONS.SAVE,
});
export const nodeSetSaveErrors = (errors: IValidationErrors) => ({
errors,
type: NODE_ACTIONS.SET_SAVE_ERRORS,
@ -55,6 +50,15 @@ export const nodePostLocalComment = (
type: NODE_ACTIONS.POST_COMMENT,
});
export const nodeSubmitLocal = (
node: INode,
callback: (e?: string, errors?: Record<string, string>) => void
) => ({
node,
callback,
type: NODE_ACTIONS.SUBMIT_LOCAL,
});
export const nodeSetSendingComment = (is_sending_comment: boolean) => ({
is_sending_comment,
type: NODE_ACTIONS.SET_SENDING_COMMENT,

View file

@ -40,6 +40,9 @@ export type ApiGetNodeCommentsResponse = { comments: IComment[]; comment_count:
export const apiPostNode = ({ node }: ApiPostNodeRequest) =>
api.post<ApiPostNodeResult>(API.NODE.SAVE, node).then(cleanResult);
export const apiPostNodeLocal = ({ node }: ApiPostNodeRequest) =>
api.post<ApiPostNodeResult>(API.NODE.SAVE, node).then(cleanResult);
export const getNodeDiff = ({
start,
end,

View file

@ -18,12 +18,11 @@ import { NodeImageSwiperBlock } from '~/components/node/NodeImageSwiperBlock';
import { LabNodeTitle } from '~/components/lab/LabNodeTitle';
import { LabText } from '~/components/lab/LabText';
import { LabImage } from '~/components/lab/LabImage';
import { LabBottomPanel } from '~/components/lab/LabBottomPanel';
import { LabPad } from '~/components/lab/LabPad';
const prefix = 'NODE.';
export const NODE_ACTIONS = {
SAVE: `${prefix}SAVE`,
SUBMIT_LOCAL: `${prefix}SUBMIT_LOCAL`,
LOAD_NODE: `${prefix}LOAD_NODE`,
GOTO_NODE: `${prefix}GOTO_NODE`,
SET: `${prefix}SET`,

View file

@ -17,7 +17,6 @@ import {
nodeLock,
nodeLockComment,
nodePostLocalComment,
nodeSave,
nodeSet,
nodeSetCommentData,
nodeSetComments,
@ -26,8 +25,8 @@ import {
nodeSetLoading,
nodeSetLoadingComments,
nodeSetRelated,
nodeSetSaveErrors,
nodeSetTags,
nodeSubmitLocal,
nodeUpdateTags,
} from './actions';
import {
@ -43,7 +42,6 @@ import {
apiPostNodeTags,
} from './api';
import { flowSetNodes, flowSetUpdated } from '../flow/actions';
import { ERRORS } from '~/constants/errors';
import { modalSetShown, modalShowDialog } from '../modal/actions';
import { selectFlow, selectFlowNodes } from '../flow/selectors';
import { URLS } from '~/constants/urls';
@ -73,14 +71,12 @@ export function* updateNodeEverywhere(node) {
);
}
function* onNodeSave({ node }: ReturnType<typeof nodeSave>) {
function* onNodeSubmitLocal({ node, callback }: ReturnType<typeof nodeSubmitLocal>) {
try {
yield put(nodeSetSaveErrors({}));
const { errors, node: result }: Unwrap<typeof apiPostNode> = yield call(apiPostNode, { node });
if (errors && Object.values(errors).length > 0) {
yield put(nodeSetSaveErrors(errors));
callback('', errors);
return;
}
@ -97,9 +93,10 @@ function* onNodeSave({ node }: ReturnType<typeof nodeSave>) {
yield put(nodeSetCurrent(result));
}
return yield put(modalSetShown(false));
callback();
return;
} catch (error) {
yield put(nodeSetSaveErrors({ error: error.message || ERRORS.CANT_SAVE_NODE }));
callback(error.message);
}
}
@ -361,7 +358,7 @@ function* onLockCommentSaga({ id, is_locked }: ReturnType<typeof nodeLockComment
}
export default function* nodeSaga() {
yield takeLatest(NODE_ACTIONS.SAVE, onNodeSave);
yield takeLatest(NODE_ACTIONS.SUBMIT_LOCAL, onNodeSubmitLocal);
yield takeLatest(NODE_ACTIONS.GOTO_NODE, onNodeGoto);
yield takeLatest(NODE_ACTIONS.LOAD_NODE, onNodeLoad);
yield takeLatest(NODE_ACTIONS.POST_COMMENT, onPostComment);