@@ -1,3 +1,10 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
import omit from 'lodash/omit';
|
||||
import truncate from 'lodash/truncate';
|
||||
import { call, put, select } from 'redux-saga/effects';
|
||||
|
||||
import request from '../request';
|
||||
@@ -5,21 +12,33 @@ import selectors from '../../../selectors';
|
||||
import actions from '../../../actions';
|
||||
import api from '../../../api';
|
||||
import { createLocalId } from '../../../utils/local-id';
|
||||
import { AttachmentTypes } from '../../../constants/Enums';
|
||||
|
||||
export function* createAttachment(cardId, data) {
|
||||
const localId = yield call(createLocalId);
|
||||
const currentUserId = yield select(selectors.selectCurrentUserId);
|
||||
|
||||
const nextData = {
|
||||
...data,
|
||||
name: truncate(data.name, {
|
||||
length: 128,
|
||||
}),
|
||||
};
|
||||
|
||||
yield put(
|
||||
actions.createAttachment({
|
||||
...omit(nextData, ['file', 'url']),
|
||||
cardId,
|
||||
id: localId,
|
||||
name: data.file.name,
|
||||
creatorUserId: currentUserId,
|
||||
}),
|
||||
);
|
||||
|
||||
let attachment;
|
||||
try {
|
||||
({ item: attachment } = yield call(request, api.createAttachment, cardId, data, localId));
|
||||
({ item: attachment } = yield nextData.type === AttachmentTypes.FILE
|
||||
? call(request, api.createAttachmentWithFile, cardId, nextData, localId)
|
||||
: call(request, api.createAttachment, cardId, nextData));
|
||||
} catch (error) {
|
||||
yield put(actions.createAttachment.failure(localId, error));
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user