|
|
@@ -56,38 +56,38 @@ export type Mutations<S = State> = {
|
|
|
): void;
|
|
|
|
|
|
[MutationTypes.addCreneau](state: S, payload: Creneau): void;
|
|
|
- [MutationTypes.removeCreneau](state: S, payload: Creneau): void;
|
|
|
+ [MutationTypes.removeCreneau](state: S, uuid: string): void;
|
|
|
[MutationTypes.editCreneau]<K extends keyof Creneau>(
|
|
|
state: S,
|
|
|
payload: { id: string; field: K; value: Creneau[K] }
|
|
|
- ): boolean;
|
|
|
+ ): void;
|
|
|
|
|
|
[MutationTypes.addCreneauGroup](state: S, payload: Ressource): void;
|
|
|
[MutationTypes.addCreneauGroupAt](state: S, payload: { r: Ressource; pos: number }): void;
|
|
|
- [MutationTypes.removeCreneauGroup](state: S, payload: Ressource): void;
|
|
|
+ [MutationTypes.removeCreneauGroup](state: S, uuid: string): void;
|
|
|
[MutationTypes.editCreneauGroup]<K extends keyof Ressource>(
|
|
|
state: S,
|
|
|
payload: { id: string; field: K; value: Ressource[K] }
|
|
|
- ): boolean;
|
|
|
- [MutationTypes.reorderCreneauGroup](state: S, payload: Array<Ressource>): boolean;
|
|
|
+ ): void;
|
|
|
+ [MutationTypes.reorderCreneauGroup](state: S, payload: Array<string>): void;
|
|
|
|
|
|
[MutationTypes.addBenevole2Creneau](state: S, payload: CreneauPairing): void;
|
|
|
[MutationTypes.removeBenevole2Creneau](state: S, payload: CreneauPairing): void;
|
|
|
[MutationTypes.clearBenevole2Creneau](state: S): void;
|
|
|
|
|
|
[MutationTypes.addBenevole](state: S, payload: Benevole): void;
|
|
|
- [MutationTypes.removeBenevole](state: S, payload: Benevole): void;
|
|
|
+ [MutationTypes.removeBenevole](state: S, uuid: number): void;
|
|
|
[MutationTypes.editBenevole]<K extends keyof Benevole>(
|
|
|
state: S,
|
|
|
payload: { id: number; field: K; value: Benevole[K] }
|
|
|
- ): boolean;
|
|
|
+ ): void;
|
|
|
|
|
|
[MutationTypes.addConstraint](state: S, payload: Competence): void;
|
|
|
- [MutationTypes.removeConstraint](state: S, payload: Competence): void;
|
|
|
+ [MutationTypes.removeConstraint](state: S, uuid: number): void;
|
|
|
[MutationTypes.editConstraint]<K extends keyof Competence>(
|
|
|
state: S,
|
|
|
payload: { id: number; field: K; value: Competence[K] }
|
|
|
- ): boolean;
|
|
|
+ ): void;
|
|
|
|
|
|
[MutationTypes.newVersion](state: S, payload: EvenementVersion): void;
|
|
|
[MutationTypes.refreshVersion](state: S, payload: Array<EvenementVersion>): void;
|
|
|
@@ -113,24 +113,23 @@ export const mutations: MutationTree<State> & Mutations = {
|
|
|
|
|
|
// Creneau Management
|
|
|
[MutationTypes.addCreneau](state, creneau) {
|
|
|
- state.creneauList = [creneau, ...state.creneauList];
|
|
|
+ if (state.creneauList.findIndex((c) => c.id == creneau.id) < 0)
|
|
|
+ state.creneauList = [creneau, ...state.creneauList];
|
|
|
},
|
|
|
- [MutationTypes.removeCreneau](state, creneau) {
|
|
|
- state.creneauList = state.creneauList.filter((c) => c.id !== creneau.id);
|
|
|
+ [MutationTypes.removeCreneau](state, uuid) {
|
|
|
+ state.creneauList = state.creneauList.filter((c) => c.id !== uuid);
|
|
|
},
|
|
|
[MutationTypes.editCreneau](state, payload) {
|
|
|
const el = state.creneauList.find((o) => o.id == payload.id);
|
|
|
if (el) {
|
|
|
el[payload.field] = payload.value;
|
|
|
- return true;
|
|
|
}
|
|
|
- return false;
|
|
|
},
|
|
|
|
|
|
[MutationTypes.addBenevole2Creneau](state, pair: CreneauPairing) {
|
|
|
const benevole = state.benevoleList.find((o) => o.id == pair.benevoleId);
|
|
|
const creneau = state.creneauList.find((o) => o.id == pair.creneauId);
|
|
|
- if (creneau && benevole) {
|
|
|
+ if (creneau && benevole && !benevole.creneauIdList.includes(pair.creneauId)) {
|
|
|
benevole.creneauIdList = [...benevole.creneauIdList, pair.creneauId];
|
|
|
creneau.benevoleIdList = [...creneau.benevoleIdList, pair.benevoleId];
|
|
|
}
|
|
|
@@ -149,11 +148,14 @@ export const mutations: MutationTree<State> & Mutations = {
|
|
|
},
|
|
|
// Creneau Group Management
|
|
|
[MutationTypes.reorderCreneauGroup](state, payload) {
|
|
|
- state.creneauGroupList = payload;
|
|
|
+ state.creneauGroupList = state.creneauGroupList
|
|
|
+ .slice()
|
|
|
+ .sort((a, b) => payload.indexOf(a.id) - payload.indexOf(b.id));
|
|
|
return true;
|
|
|
},
|
|
|
[MutationTypes.addCreneauGroup](state, payload) {
|
|
|
- state.creneauGroupList = [...state.creneauGroupList, payload];
|
|
|
+ if (state.creneauGroupList.findIndex((c) => c.id == payload.id) < 0)
|
|
|
+ state.creneauGroupList = [...state.creneauGroupList, payload];
|
|
|
},
|
|
|
[MutationTypes.addCreneauGroupAt](state, payload) {
|
|
|
if (payload.pos < 1) {
|
|
|
@@ -164,57 +166,52 @@ export const mutations: MutationTree<State> & Mutations = {
|
|
|
state.creneauGroupList.splice(payload.pos, 0, payload.r);
|
|
|
}
|
|
|
},
|
|
|
- [MutationTypes.removeCreneauGroup](state, payload) {
|
|
|
- state.creneauGroupList = state.creneauGroupList.filter((c) => c.id !== payload.id);
|
|
|
+ [MutationTypes.removeCreneauGroup](state, uuid) {
|
|
|
+ state.creneauGroupList = state.creneauGroupList.filter((c) => c.id !== uuid);
|
|
|
},
|
|
|
[MutationTypes.editCreneauGroup](state, payload) {
|
|
|
const el = state.creneauGroupList.find((o) => o.id == payload.id);
|
|
|
if (el) {
|
|
|
el[payload.field] = payload.value;
|
|
|
- return true;
|
|
|
}
|
|
|
- return false;
|
|
|
},
|
|
|
// Benevole Management
|
|
|
[MutationTypes.addBenevole](state, payload) {
|
|
|
- state.benevoleList = [payload, ...state.benevoleList];
|
|
|
+ if (state.benevoleList.findIndex((c) => c.id == payload.id) < 0)
|
|
|
+ state.benevoleList = [payload, ...state.benevoleList];
|
|
|
},
|
|
|
- [MutationTypes.removeBenevole](state, payload) {
|
|
|
+ [MutationTypes.removeBenevole](state, uuid) {
|
|
|
state.creneauList.forEach(
|
|
|
- (creneau) =>
|
|
|
- (creneau.benevoleIdList = creneau.benevoleIdList.filter((id) => id !== payload.id))
|
|
|
+ (creneau) => (creneau.benevoleIdList = creneau.benevoleIdList.filter((id) => id !== uuid))
|
|
|
);
|
|
|
- state.benevoleList = state.benevoleList.filter((c) => c.id !== payload.id);
|
|
|
+ state.benevoleList = state.benevoleList.filter((c) => c.id !== uuid);
|
|
|
},
|
|
|
[MutationTypes.editBenevole](state, payload) {
|
|
|
const el = state.benevoleList.find((o) => o.id == payload.id);
|
|
|
if (el) {
|
|
|
el[payload.field] = payload.value;
|
|
|
- return true;
|
|
|
}
|
|
|
- return false;
|
|
|
},
|
|
|
// Constraint Management
|
|
|
[MutationTypes.addConstraint](state, payload) {
|
|
|
- state.competenceList = [payload, ...state.competenceList];
|
|
|
+ if (state.competenceList.findIndex((c) => c.id == payload.id) < 0)
|
|
|
+ state.competenceList = [payload, ...state.competenceList];
|
|
|
},
|
|
|
- [MutationTypes.removeConstraint](state, payload) {
|
|
|
- const filterFunction = (id: number) => id !== payload.id;
|
|
|
+ [MutationTypes.removeConstraint](state, uuid) {
|
|
|
+ const filterFunction = (id: number) => id !== uuid;
|
|
|
state.benevoleList.forEach(
|
|
|
(benevole) => (benevole.competenceIdList = benevole.competenceIdList.filter(filterFunction))
|
|
|
);
|
|
|
state.creneauList.forEach(
|
|
|
(creneau) => (creneau.competencesIdList = creneau.competencesIdList.filter(filterFunction))
|
|
|
);
|
|
|
- state.competenceList = state.competenceList.filter((c) => c.id !== payload.id);
|
|
|
+ state.competenceList = state.competenceList.filter((c) => c.id !== uuid);
|
|
|
},
|
|
|
[MutationTypes.editConstraint](state, payload) {
|
|
|
const el = state.competenceList.find((o) => o.id == payload.id);
|
|
|
if (el) {
|
|
|
el[payload.field] = payload.value;
|
|
|
- return true;
|
|
|
}
|
|
|
- return false;
|
|
|
},
|
|
|
|
|
|
[MutationTypes.newVersion](state, payload) {
|