feat: universal search.

This commit is contained in:
a.bouhuolia
2021-08-21 18:59:49 +02:00
parent a7b0f1a8d2
commit 79c1b2ab67
82 changed files with 2497 additions and 317 deletions

View File

@@ -20,3 +20,36 @@ export function generalSearch(name, result) {
result,
};
}
export function universalSearchSetResourceType(resourceType) {
return {
type: t.UNIVERSAL_SEARCH_SET_RESOURCE_TYPE,
payload: {
resourceType,
},
};
}
export function universalSearchResetResourceType() {
return {
type: t.UNIVERSAL_SEARCH_RESET_RESOURCE_TYPE,
};
}
export function universalSearchSetSelectedItem(resourceType, resourceId) {
return {
type: t.UNIVERSAL_SEARCH_SET_ITEM_SELECT,
payload: {
resourceType,
resourceId
}
};
}
export function universalSearchResetSelectedItem() {
return {
type: t.UNIVERSAL_SEARCH_RESET_ITEM_SELECT,
payload: {}
};
}

View File

@@ -1,8 +1,12 @@
import t from 'store/types';
import { createReducer } from '@reduxjs/toolkit';
const DEFAULT_RESOURCE_TYPE = 'customer';
const initialState = {
isOpen: false,
defaultResourceType: DEFAULT_RESOURCE_TYPE,
selectedItem: {},
};
export default createReducer(initialState, {
@@ -13,4 +17,23 @@ export default createReducer(initialState, {
[t.CLOSE_SEARCH]: (state, action) => {
state.isOpen = false;
},
[t.UNIVERSAL_SEARCH_SET_RESOURCE_TYPE]: (state, action) => {
state.defaultResourceType = action.payload.resourceType;
},
[t.UNIVERSAL_SEARCH_RESET_RESOURCE_TYPE]: (state, action) => {
state.defaultResourceType = DEFAULT_RESOURCE_TYPE;
},
[t.UNIVERSAL_SEARCH_SET_ITEM_SELECT]: (state, action) => {
state.selectedItem = {
resourceId: action.payload.resourceId,
resourceType: action.payload.resourceType,
};
},
[t.UNIVERSAL_SEARCH_RESET_ITEM_SELECT]: (state, action) => {
state.selectedItem = {};
},
});

View File

@@ -2,4 +2,8 @@ export default {
SEARCH_TYPE: 'SEARCH_TYPE',
OPEN_SEARCH: 'OPEN_SEARCH',
CLOSE_SEARCH: 'CLOSE_SEARCH',
UNIVERSAL_SEARCH_SET_RESOURCE_TYPE: 'UNIVERSAL_SEARCH_SET_RESOURCE_TYPE',
UNIVERSAL_SEARCH_RESET_RESOURCE_TYPE: 'UNIVERSAL_SEARCH_RESET_RESOURCE_TYPE',
UNIVERSAL_SEARCH_SET_ITEM_SELECT: 'UNIVERSAL_SEARCH_SET_ITEM_SELECT',
UNIVERSAL_SEARCH_RESET_ITEM_SELECT: 'UNIVERSAL_SEARCH_RESET_ITEM_SELECT'
};