feat(lifecycle): Pinia/Vuex stores for rules/config/deliveries

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Rodribm10 2026-04-15 10:46:20 -03:00
parent b69053ae62
commit bc85ec0a67
4 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,63 @@
import CaptainLifecycleConfigAPI from 'dashboard/api/captain/lifecycleConfig';
import { throwErrorMessage } from 'dashboard/store/utils/api';
export const types = {
SET_CONFIG: 'SET_LIFECYCLE_CONFIG',
SET_UI_FLAG: 'SET_LIFECYCLE_CONFIG_UI_FLAG',
};
const state = {
config: {},
uiFlags: {
fetching: false,
updating: false,
},
};
const getters = {
getConfig: $state => $state.config,
getUIFlags: $state => $state.uiFlags,
};
const actions = {
fetch: async ({ commit }) => {
commit(types.SET_UI_FLAG, { fetching: true });
try {
const response = await CaptainLifecycleConfigAPI.show();
commit(types.SET_CONFIG, response.data);
} catch (error) {
throwErrorMessage(error);
} finally {
commit(types.SET_UI_FLAG, { fetching: false });
}
},
update: async ({ commit }, data) => {
commit(types.SET_UI_FLAG, { updating: true });
try {
const response = await CaptainLifecycleConfigAPI.update(data);
commit(types.SET_CONFIG, response.data);
return response.data;
} catch (error) {
return throwErrorMessage(error);
} finally {
commit(types.SET_UI_FLAG, { updating: false });
}
},
};
const mutations = {
[types.SET_CONFIG]($state, config) {
$state.config = config;
},
[types.SET_UI_FLAG]($state, flags) {
$state.uiFlags = { ...$state.uiFlags, ...flags };
},
};
export default {
namespaced: true,
state,
getters,
actions,
mutations,
};

View File

@ -0,0 +1,7 @@
import CaptainLifecycleDeliveriesAPI from 'dashboard/api/captain/lifecycleDeliveries';
import { createStore } from '../storeFactory';
export default createStore({
name: 'CaptainLifecycleDelivery',
API: CaptainLifecycleDeliveriesAPI,
});

View File

@ -0,0 +1,46 @@
import CaptainLifecycleRulesAPI from 'dashboard/api/captain/lifecycleRules';
import { createStore } from '../storeFactory';
import { throwErrorMessage } from 'dashboard/store/utils/api';
export default createStore({
name: 'CaptainLifecycleRule',
API: CaptainLifecycleRulesAPI,
actions: mutations => ({
create: async ({ commit }, data) => {
commit(mutations.SET_UI_FLAG, { creatingItem: true });
try {
const response = await CaptainLifecycleRulesAPI.create(data);
commit(mutations.ADD, response.data);
return response.data;
} catch (error) {
return throwErrorMessage(error);
} finally {
commit(mutations.SET_UI_FLAG, { creatingItem: false });
}
},
update: async ({ commit }, { id, ...data }) => {
commit(mutations.SET_UI_FLAG, { updatingItem: true });
try {
const response = await CaptainLifecycleRulesAPI.update(id, data);
commit(mutations.EDIT, response.data);
return response.data;
} catch (error) {
return throwErrorMessage(error);
} finally {
commit(mutations.SET_UI_FLAG, { updatingItem: false });
}
},
delete: async ({ commit }, id) => {
commit(mutations.SET_UI_FLAG, { deletingItem: true });
try {
await CaptainLifecycleRulesAPI.delete(id);
commit(mutations.DELETE, id);
return id;
} catch (error) {
return throwErrorMessage(error);
} finally {
commit(mutations.SET_UI_FLAG, { deletingItem: false });
}
},
}),
});

View File

@ -60,6 +60,9 @@ import captainScenarios from './captain/scenarios';
import captainTools from './captain/tools';
import captainCustomTools from './captain/customTools';
import captainReservations from './captain/reservations';
import captainLifecycleRules from './captain/lifecycleRules';
import captainLifecycleConfig from './captain/lifecycleConfig';
import captainLifecycleDeliveries from './captain/lifecycleDeliveries';
import captainUnits from './modules/captainUnits';
import captainGalleryItems from './modules/captainGalleryItems';
import captainReports from './modules/captainReports';
@ -129,6 +132,9 @@ export default createStore({
captainTools,
captainCustomTools,
captainReservations,
captainLifecycleRules,
captainLifecycleConfig,
captainLifecycleDeliveries,
captainUnits,
captainGalleryItems,
captainReports,