Skip to content

Commit

Permalink
refactor: manage company in data fetching in helpdesk (#852)
Browse files Browse the repository at this point in the history
* RM#88457
  • Loading branch information
vhu-axelor authored Jan 8, 2025
1 parent 08b00ee commit 6b9d3e6
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
5 changes: 5 additions & 0 deletions changelogs/unreleased/88457.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Data fetching: add active company management",
"type": "refactor",
"packages": "helpdesk"
}
12 changes: 10 additions & 2 deletions packages/apps/helpdesk/src/api/customer-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ const createCustomerContactCriteria = searchValue => {
return [getSearchCriterias('helpdesk_customerContact', searchValue)];
};

export async function searchCustomer({searchValue, page = 0}) {
export async function searchCustomer({searchValue, companyId, page = 0}) {
return createStandardSearch({
model: 'com.axelor.apps.base.db.Partner',
companyId,
isCompanyM2M: true,
criteria: createCustomerCriteria(searchValue),
fieldKey: 'helpdesk_customer',
sortKey: 'helpdesk_customer',
Expand All @@ -48,9 +50,15 @@ export async function searchCustomer({searchValue, page = 0}) {
});
}

export async function searchCustomerContact({searchValue, page = 0}) {
export async function searchCustomerContact({
searchValue,
companyId,
page = 0,
}) {
return createStandardSearch({
model: 'com.axelor.apps.base.db.Partner',
companyId,
isCompanyM2M: true,
criteria: createCustomerContactCriteria(searchValue),
fieldKey: 'helpdesk_customerContact',
sortKey: 'helpdesk_customerContact',
Expand Down
3 changes: 2 additions & 1 deletion packages/apps/helpdesk/src/api/project-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ const createProjectCriteria = searchValue => {
return [getSearchCriterias('helpdesk_project', searchValue)];
};

export async function searchProject({searchValue, page = 0}) {
export async function searchProject({searchValue, companyId, page = 0}) {
return createStandardSearch({
model: 'com.axelor.apps.project.db.Project',
companyId,
criteria: createProjectCriteria(searchValue),
fieldKey: 'helpdesk_project',
sortKey: 'helpdesk_project',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,19 @@ const ContactPartnerSearchBar = ({
isListEndCustomerContact,
customerContactList,
} = useSelector(state => state.helpdesk_customer);
const {user} = useSelector(state => state.user);

const searchContactAPI = useCallback(
({page = 0, searchValue}) => {
dispatch(searchCustomerContact({page, searchValue}));
dispatch(
searchCustomerContact({
page,
searchValue,
companyId: user.activeCompany?.id,
}),
);
},
[dispatch],
[dispatch, user.activeCompany?.id],
);

const ObjectToDisplay = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ const CustomerSearchBar = ({
const {customerList, loading, moreLoading, isListEnd} = useSelector(
state => state.helpdesk_customer,
);
const {user} = useSelector(state => state.user);

const searchCustomerAPI = useCallback(
({page = 0, searchValue}) => {
dispatch(searchCustomer({page, searchValue}));
dispatch(
searchCustomer({page, searchValue, companyId: user.activeCompany?.id}),
);
},
[dispatch],
[dispatch, user.activeCompany?.id],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ const ProjectSearchBar = ({
const {projectList, loadingProject, moreLoading, isListEnd} = useSelector(
state => state.helpdesk_project,
);
const {user} = useSelector(state => state.user);

const searchProjectAPI = useCallback(
({page = 0, searchValue}) => {
dispatch(searchProject({page, searchValue}));
dispatch(
searchProject({page, searchValue, companyId: user.activeCompany?.id}),
);
},
[dispatch],
[dispatch, user.activeCompany?.id],
);

return (
Expand Down

0 comments on commit 6b9d3e6

Please sign in to comment.