New Backend API to fetch address hierarchy for a selected node :
//success response
{
"data": {
"pincode": "DAM",
"city": "Z1",
"state": "DAMMAM"
}
}Changes in filter for address node search:
Instead of showing only Name of options in dropdown it will now be shown as Name (Code).
This will require another update in find query in common/models/customer-portal-parts/address-node-api-helper.js → getAddressNodeDataCurrent filter is applicable only on code or name, changes to add both code and name search
common/models/customer-portal-parts/address-node-api-helper.js → getAddressNodeData
Current filter logic:
conditions.code = {ilike: queryString};
if (shouldSearchByName) {
conditions.name = {ilike: queryString};
delete conditions.code;
}Updated filter logic:
if (shouldSearchByBothNameAndCode) {
condition.and.push({
or: [
{ name: { ilike: queryString } },
{ code: { ilike: queryString } }
]
});
} else {
conditions.and.push({ code: { ilike: queryString } });
}Frontend changes:
Changes are to be done at 3 places
Add Consignment modal (src/components/pages/details/AddDetails.tsx )
Counter Booking → Add Address ( src/components/pages/OpsDashboard/Manage/counterBooking/AddAddress2.tsx )
Customer-Portal → src/components/address/create-address.tsx
List to be populated in dropdown will be fetched after entering atleast 3 characters in the input field for corresponding node( pincode, city, state, country).
Debouncing will be implemented at all places wherever we are fetching list to be populated in the dropdown. (500ms)
In case allowOverrideHierarchy is false , we will let user only enter values from dropdown only.
In case allowOverrideHierarchy is true: user can either select from dropdown or enter other values too.
Only those fields will be disabled for which data is fetched, only when allow override hierarchy is false
Customer Portal changes
Changes in src/components/address/create-address.tsx
General Function to be called whenever any option from rendered dropdown is selected, it make call to api api/CustomerPortal/fetchGeneralAddressCode
// this logic will be used to get whether isAddressHierarchyPresent is true or false
if (Array.isArray(response.data.hierarchy) && response.data.hierarchy.length) {
setIsAddressHierarchyPresent(true);
}In case isAddressHierarchyPresent is false then we will render only Simple Input text field.
If isAddressHierarchyPresent is true:
It fetches data from AddressNode table on basis of address hierarchy setup, and returns data for current and higher nodes to populate.
It also handle the logic to either disbale the higher level nodes based on whether their value is fetched and allow_override_hierarchy is false.
It also update (auto populate) the value of higher nodes.
Drop down only on those fields which are in hierarchy
Function to be called on typing text to be searched in address fields( pincode, city, state country)
Debouncing logic is also applied :
Following rendering logic is used for all nodes (pincode, state, city, country)
It renders only dropdown for case when allow_override_hierarchy is false (user can only select options from dropdown only).
When allow_override_hierarchy is true: user can type and search will be done in db, if data found user can select any option from dropdown and on basis of it higher level nodes is auto-populated, and can also enter anything out of option in dropdown for current node and higher nodes too.
On clearing a node’s value, all higher node's value will also be cleared.
Additional Details:
Changes in src/network/pickup.api.ts
Changes in src/network/api.constants.ts
CRMDashboard changes:
Similar logic as of Customer-Portal is used for rendering like on basis of isAddressHierarchyPresent and allowOverrideHierarchy.
Above logic is updated in
src/components/pages/OpsDashboard/Manage/counterBooking/AddAddress2.tsx
src/components/pages/details/AddDetails.tsx