1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00
planka/client/src/sagas/app/services/board.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-08-31 04:07:25 +05:00
import { call, put, select } from 'redux-saga/effects';
import { goToBoardService, goToProjectService } from './router';
import { createBoardRequest, deleteBoardRequest, updateBoardRequest } from '../requests';
import { boardByIdSelector, nextBoardPositionSelector, pathSelector } from '../../../selectors';
2019-08-31 04:07:25 +05:00
import { createBoard, deleteBoard, updateBoard } from '../../../actions';
import { createLocalId } from '../../../utils/local-id';
2019-08-31 04:07:25 +05:00
export function* createBoardService(projectId, data) {
const nextData = {
...data,
position: yield select(nextBoardPositionSelector, projectId),
};
const localId = yield call(createLocalId);
2019-08-31 04:07:25 +05:00
yield put(
createBoard({
...nextData,
projectId,
id: localId,
}),
);
const {
success,
payload: { board },
} = yield call(createBoardRequest, projectId, localId, nextData);
if (success) {
yield call(goToBoardService, board.id);
}
}
export function* createBoardInCurrentProjectService(data) {
const { projectId } = yield select(pathSelector);
yield call(createBoardService, projectId, data);
}
export function* updateBoardService(id, data) {
yield put(updateBoard(id, data));
yield call(updateBoardRequest, id, data);
}
export function* moveBoardService(id, index) {
const { projectId } = yield select(boardByIdSelector, id);
const position = yield select(nextBoardPositionSelector, projectId, index, id);
yield call(updateBoardService, id, {
position,
});
}
export function* deleteBoardService(id) {
const { boardId, projectId } = yield select(pathSelector);
if (id === boardId) {
yield call(goToProjectService, projectId);
}
yield put(deleteBoard(id));
yield call(deleteBoardRequest, id);
}