mirror of
https://github.com/plankanban/planka.git
synced 2025-08-03 04:25:27 +02:00
Initial commit
This commit is contained in:
commit
36fe34e8e1
583 changed files with 91539 additions and 0 deletions
88
client/src/models/Action.js
Executable file
88
client/src/models/Action.js
Executable file
|
@ -0,0 +1,88 @@
|
|||
import { Model, attr, fk } from 'redux-orm';
|
||||
|
||||
import ActionTypes from '../constants/ActionTypes';
|
||||
|
||||
export default class extends Model {
|
||||
static modelName = 'Action';
|
||||
|
||||
static fields = {
|
||||
id: attr(),
|
||||
type: attr(),
|
||||
data: attr(),
|
||||
createdAt: attr({
|
||||
getDefault: () => new Date(),
|
||||
}),
|
||||
isInCard: attr({
|
||||
getDefault: () => true,
|
||||
}),
|
||||
cardId: fk({
|
||||
to: 'Card',
|
||||
as: 'card',
|
||||
relatedName: 'actions',
|
||||
}),
|
||||
userId: fk({
|
||||
to: 'User',
|
||||
as: 'user',
|
||||
relatedName: 'actions',
|
||||
}),
|
||||
};
|
||||
|
||||
static reducer({ type, payload }, Action) {
|
||||
switch (type) {
|
||||
case ActionTypes.ACTIONS_FETCH_SUCCEEDED:
|
||||
payload.actions.forEach((action) => {
|
||||
Action.upsert(action);
|
||||
});
|
||||
|
||||
break;
|
||||
case ActionTypes.ACTION_CREATE_RECEIVED:
|
||||
case ActionTypes.COMMENT_ACTION_CREATE:
|
||||
Action.upsert(payload.action);
|
||||
|
||||
break;
|
||||
case ActionTypes.ACTION_UPDATE_RECEIVED:
|
||||
Action.withId(payload.action.id).update(payload.action);
|
||||
|
||||
break;
|
||||
case ActionTypes.ACTION_DELETE_RECEIVED:
|
||||
Action.withId(payload.action.id).delete();
|
||||
|
||||
break;
|
||||
case ActionTypes.COMMENT_ACTION_UPDATE:
|
||||
Action.withId(payload.id).update({
|
||||
data: payload.data,
|
||||
});
|
||||
|
||||
break;
|
||||
case ActionTypes.COMMENT_ACTION_DELETE:
|
||||
Action.withId(payload.id).delete();
|
||||
|
||||
break;
|
||||
case ActionTypes.COMMENT_ACTION_CREATE_SUCCEEDED:
|
||||
Action.withId(payload.localId).delete();
|
||||
Action.upsert(payload.action);
|
||||
|
||||
break;
|
||||
case ActionTypes.NOTIFICATIONS_FETCH_SUCCEEDED:
|
||||
payload.actions.forEach((action) => {
|
||||
Action.upsert({
|
||||
...action,
|
||||
isInCard: false,
|
||||
});
|
||||
});
|
||||
|
||||
break;
|
||||
case ActionTypes.NOTIFICATION_CREATE_RECEIVED: {
|
||||
const actionModel = Action.withId(payload.action.id);
|
||||
|
||||
Action.upsert({
|
||||
...payload.action,
|
||||
isInCard: actionModel ? actionModel.isInCard : false,
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue