feat(lifecycle): Pinia/Vuex stores for rules/config/deliveries
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b69053ae62
commit
bc85ec0a67
63
app/javascript/dashboard/store/captain/lifecycleConfig.js
Normal file
63
app/javascript/dashboard/store/captain/lifecycleConfig.js
Normal 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,
|
||||||
|
};
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
import CaptainLifecycleDeliveriesAPI from 'dashboard/api/captain/lifecycleDeliveries';
|
||||||
|
import { createStore } from '../storeFactory';
|
||||||
|
|
||||||
|
export default createStore({
|
||||||
|
name: 'CaptainLifecycleDelivery',
|
||||||
|
API: CaptainLifecycleDeliveriesAPI,
|
||||||
|
});
|
||||||
46
app/javascript/dashboard/store/captain/lifecycleRules.js
Normal file
46
app/javascript/dashboard/store/captain/lifecycleRules.js
Normal 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 });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
});
|
||||||
@ -60,6 +60,9 @@ import captainScenarios from './captain/scenarios';
|
|||||||
import captainTools from './captain/tools';
|
import captainTools from './captain/tools';
|
||||||
import captainCustomTools from './captain/customTools';
|
import captainCustomTools from './captain/customTools';
|
||||||
import captainReservations from './captain/reservations';
|
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 captainUnits from './modules/captainUnits';
|
||||||
import captainGalleryItems from './modules/captainGalleryItems';
|
import captainGalleryItems from './modules/captainGalleryItems';
|
||||||
import captainReports from './modules/captainReports';
|
import captainReports from './modules/captainReports';
|
||||||
@ -129,6 +132,9 @@ export default createStore({
|
|||||||
captainTools,
|
captainTools,
|
||||||
captainCustomTools,
|
captainCustomTools,
|
||||||
captainReservations,
|
captainReservations,
|
||||||
|
captainLifecycleRules,
|
||||||
|
captainLifecycleConfig,
|
||||||
|
captainLifecycleDeliveries,
|
||||||
captainUnits,
|
captainUnits,
|
||||||
captainGalleryItems,
|
captainGalleryItems,
|
||||||
captainReports,
|
captainReports,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user