mirror of
https://github.com/plankanban/planka.git
synced 2025-07-19 05:09:43 +02:00
174 lines
3.6 KiB
JavaScript
174 lines
3.6 KiB
JavaScript
|
import { call, put, select } from 'redux-saga/effects';
|
||
|
|
||
|
import { goToBoard, goToProject } from './router';
|
||
|
import request from '../request';
|
||
|
import selectors from '../../../selectors';
|
||
|
import actions from '../../../actions';
|
||
|
import api from '../../../api';
|
||
|
import { createLocalId } from '../../../utils/local-id';
|
||
|
|
||
|
export function* createBoard(projectId, data) {
|
||
|
const nextData = {
|
||
|
...data,
|
||
|
position: yield select(selectors.selectNextBoardPosition, projectId),
|
||
|
};
|
||
|
|
||
|
const localId = yield call(createLocalId);
|
||
|
|
||
|
yield put(
|
||
|
actions.createBoard({
|
||
|
...nextData,
|
||
|
projectId,
|
||
|
id: localId,
|
||
|
}),
|
||
|
);
|
||
|
|
||
|
let board;
|
||
|
let boardMemberships;
|
||
|
|
||
|
try {
|
||
|
({
|
||
|
item: board,
|
||
|
included: { boardMemberships },
|
||
|
} = yield call(request, api.createBoard, projectId, nextData));
|
||
|
} catch (error) {
|
||
|
yield put(actions.createBoard.failure(localId, error));
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
yield put(actions.createBoard.success(localId, board, boardMemberships));
|
||
|
yield call(goToBoard, board.id);
|
||
|
}
|
||
|
|
||
|
export function* createBoardInCurrentProject(data) {
|
||
|
const { projectId } = yield select(selectors.selectPath);
|
||
|
|
||
|
yield call(createBoard, projectId, data);
|
||
|
}
|
||
|
|
||
|
export function* handleBoardCreate(board) {
|
||
|
yield put(actions.handleBoardCreate(board));
|
||
|
}
|
||
|
|
||
|
export function* fetchBoard(id) {
|
||
|
yield put(actions.fetchBoard(id));
|
||
|
|
||
|
let board;
|
||
|
let users;
|
||
|
let projects;
|
||
|
let boardMemberships;
|
||
|
let labels;
|
||
|
let lists;
|
||
|
let cards;
|
||
|
let cardMemberships;
|
||
|
let cardLabels;
|
||
|
let tasks;
|
||
|
let attachments;
|
||
|
|
||
|
try {
|
||
|
({
|
||
|
item: board,
|
||
|
included: {
|
||
|
users,
|
||
|
projects,
|
||
|
boardMemberships,
|
||
|
labels,
|
||
|
lists,
|
||
|
cards,
|
||
|
cardMemberships,
|
||
|
cardLabels,
|
||
|
tasks,
|
||
|
attachments,
|
||
|
},
|
||
|
} = yield call(request, api.getBoard, id));
|
||
|
} catch (error) {
|
||
|
yield put(actions.fetchBoard.failure(id, error));
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
yield put(
|
||
|
actions.fetchBoard.success(
|
||
|
board,
|
||
|
users,
|
||
|
projects,
|
||
|
boardMemberships,
|
||
|
labels,
|
||
|
lists,
|
||
|
cards,
|
||
|
cardMemberships,
|
||
|
cardLabels,
|
||
|
tasks,
|
||
|
attachments,
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
export function* updateBoard(id, data) {
|
||
|
yield put(actions.updateBoard(id, data));
|
||
|
|
||
|
let board;
|
||
|
try {
|
||
|
({ item: board } = yield call(request, api.updateBoard, id, data));
|
||
|
} catch (error) {
|
||
|
yield put(actions.updateBoard.failure(id, error));
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
yield put(actions.updateBoard.success(board));
|
||
|
}
|
||
|
|
||
|
export function* handleBoardUpdate(board) {
|
||
|
yield put(actions.handleBoardUpdate(board));
|
||
|
}
|
||
|
|
||
|
export function* moveBoard(id, index) {
|
||
|
const { projectId } = yield select(selectors.selectBoardById, id);
|
||
|
const position = yield select(selectors.selectNextBoardPosition, projectId, index, id);
|
||
|
|
||
|
yield call(updateBoard, id, {
|
||
|
position,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
export function* deleteBoard(id) {
|
||
|
const { boardId, projectId } = yield select(selectors.selectPath);
|
||
|
|
||
|
if (id === boardId) {
|
||
|
yield call(goToProject, projectId);
|
||
|
}
|
||
|
|
||
|
yield put(actions.deleteBoard(id));
|
||
|
|
||
|
let board;
|
||
|
try {
|
||
|
({ item: board } = yield call(request, api.deleteBoard, id));
|
||
|
} catch (error) {
|
||
|
yield put(actions.deleteBoard.failure(id, error));
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
yield put(actions.deleteBoard.success(board));
|
||
|
}
|
||
|
|
||
|
export function* handleBoardDelete(board) {
|
||
|
const { boardId, projectId } = yield select(selectors.selectPath);
|
||
|
|
||
|
if (board.id === boardId) {
|
||
|
yield call(goToProject, projectId);
|
||
|
}
|
||
|
|
||
|
yield put(actions.handleBoardDelete(board));
|
||
|
}
|
||
|
|
||
|
export default {
|
||
|
createBoard,
|
||
|
createBoardInCurrentProject,
|
||
|
handleBoardCreate,
|
||
|
fetchBoard,
|
||
|
updateBoard,
|
||
|
handleBoardUpdate,
|
||
|
moveBoard,
|
||
|
deleteBoard,
|
||
|
handleBoardDelete,
|
||
|
};
|