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';
|
2019-10-10 02:51:54 +05:00
|
|
|
import { boardByIdSelector, nextBoardPositionSelector, pathSelector } from '../../../selectors';
|
2019-08-31 04:07:25 +05:00
|
|
|
import { createBoard, deleteBoard, updateBoard } from '../../../actions';
|
2019-10-10 02:51:54 +05:00
|
|
|
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),
|
|
|
|
};
|
|
|
|
|
2019-10-10 02:51:54 +05:00
|
|
|
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);
|
|
|
|
}
|