From bc85ec0a67309ce6a185527e7f1fbf8c700bf7f2 Mon Sep 17 00:00:00 2001 From: Rodribm10 Date: Wed, 15 Apr 2026 10:46:20 -0300 Subject: [PATCH] feat(lifecycle): Pinia/Vuex stores for rules/config/deliveries Co-Authored-By: Claude Sonnet 4.6 --- .../store/captain/lifecycleConfig.js | 63 +++++++++++++++++++ .../store/captain/lifecycleDeliveries.js | 7 +++ .../dashboard/store/captain/lifecycleRules.js | 46 ++++++++++++++ app/javascript/dashboard/store/index.js | 6 ++ 4 files changed, 122 insertions(+) create mode 100644 app/javascript/dashboard/store/captain/lifecycleConfig.js create mode 100644 app/javascript/dashboard/store/captain/lifecycleDeliveries.js create mode 100644 app/javascript/dashboard/store/captain/lifecycleRules.js diff --git a/app/javascript/dashboard/store/captain/lifecycleConfig.js b/app/javascript/dashboard/store/captain/lifecycleConfig.js new file mode 100644 index 000000000..2450caf78 --- /dev/null +++ b/app/javascript/dashboard/store/captain/lifecycleConfig.js @@ -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, +}; diff --git a/app/javascript/dashboard/store/captain/lifecycleDeliveries.js b/app/javascript/dashboard/store/captain/lifecycleDeliveries.js new file mode 100644 index 000000000..d692711d3 --- /dev/null +++ b/app/javascript/dashboard/store/captain/lifecycleDeliveries.js @@ -0,0 +1,7 @@ +import CaptainLifecycleDeliveriesAPI from 'dashboard/api/captain/lifecycleDeliveries'; +import { createStore } from '../storeFactory'; + +export default createStore({ + name: 'CaptainLifecycleDelivery', + API: CaptainLifecycleDeliveriesAPI, +}); diff --git a/app/javascript/dashboard/store/captain/lifecycleRules.js b/app/javascript/dashboard/store/captain/lifecycleRules.js new file mode 100644 index 000000000..aa16c9034 --- /dev/null +++ b/app/javascript/dashboard/store/captain/lifecycleRules.js @@ -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 }); + } + }, + }), +}); diff --git a/app/javascript/dashboard/store/index.js b/app/javascript/dashboard/store/index.js index f3c9f919b..d8d9ac621 100755 --- a/app/javascript/dashboard/store/index.js +++ b/app/javascript/dashboard/store/index.js @@ -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,