feat: Add Pinia support and relocate store factory (#12854)

Co-authored-by: Vinay Keerthi <11478411+stonecharioteer@users.noreply.github.com>
Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
Co-authored-by: Pranav <pranav@chatwoot.com>
This commit is contained in:
Sivin Varghese
2025-11-28 16:31:59 +05:30
committed by GitHub
parent 1ef945de7b
commit f23d95e004
24 changed files with 1341 additions and 603 deletions

View File

@@ -0,0 +1,31 @@
import CompanyAPI from 'dashboard/api/companies';
import { createStore } from 'dashboard/store/storeFactory';
import { throwErrorMessage } from 'dashboard/store/utils/api';
import camelcaseKeys from 'camelcase-keys';
export const useCompaniesStore = createStore({
name: 'companies',
type: 'pinia',
API: CompanyAPI,
getters: {
getCompaniesList: state => {
return camelcaseKeys(state.records, { deep: true });
},
},
actions: () => ({
async search({ search, page, sort }) {
this.setUIFlag({ fetchingList: true });
try {
const {
data: { payload, meta },
} = await CompanyAPI.search(search, page, sort);
this.records = payload;
this.setMeta(meta);
} catch (error) {
throwErrorMessage(error);
} finally {
this.setUIFlag({ fetchingList: false });
}
},
}),
});