Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 95e2750

Browse files
author
edison-nguyen
committed
changes for #15
1 parent 55478b9 commit 95e2750

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

client/src/lib/company-attributes.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ import config from "../config";
33
import * as OrgService from "../services/user-org";
44
import Axios from "axios";
55

6+
let primaryAttributeIds = [
7+
config.STANDARD_USER_ATTRIBUTES.location,
8+
config.STANDARD_USER_ATTRIBUTES.isAvailable,
9+
config.STANDARD_USER_ATTRIBUTES.title,
10+
config.STANDARD_USER_ATTRIBUTES.company,
11+
];
12+
613
/**
714
* Get the attributes associated with the company (organization)
815
* @param {Object} apiClient The api client (you can get this from src/services/api and then call api() to get the apiClient)
916
*/
10-
export async function getCompanyAttributes(apiClient, cancelToken) {
17+
export async function getAttributes(apiClient, cancelToken) {
1118
let response;
1219
let attributeGroups;
1320
let attributes = [];
@@ -63,5 +70,22 @@ export async function getCompanyAttributes(apiClient, cancelToken) {
6370
}
6471
}
6572

66-
return attributes;
73+
// Finally, split 2 attribute types
74+
const companyAttrs = attributes.filter((attribute) => {
75+
if (primaryAttributeIds.includes(attribute.name)) {
76+
return false;
77+
}
78+
79+
return true;
80+
});
81+
82+
const generalAttrs = attributes.filter((attribute) => {
83+
if (primaryAttributeIds.includes(attribute.name)) {
84+
return true;
85+
}
86+
87+
return false;
88+
});
89+
90+
return [companyAttrs, generalAttrs];
6791
}

client/src/lib/search.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ function useProvideSearch() {
6666
setPopupShown(true);
6767
};
6868

69+
const setFilter = (id, filter) => {
70+
return (filters[id] = filter);
71+
};
72+
6973
const getAttributeId = (filter) => {
7074
return filters[filter].id;
7175
};
@@ -136,6 +140,7 @@ function useProvideSearch() {
136140
popupShown,
137141
showPopup,
138142
filters,
143+
setFilter,
139144
setFilters,
140145
getAttributeId,
141146
isFilterActive,

client/src/pages/Search/Global.jsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Pagination from "../../components/Pagination";
99

1010
import * as helper from "./helper";
1111
import { useAuth0 } from "../../react-auth0-spa";
12-
import { getCompanyAttributes } from "../../lib/company-attributes";
12+
import { getAttributes } from "../../lib/company-attributes";
1313
import { useSearch, FILTERS } from "../../lib/search";
1414
import { makeColorIterator, avatarColors } from "../../lib/colors";
1515
import config from "../../config";
@@ -104,7 +104,7 @@ export default function SearchGlobal({ keyword }) {
104104
let isSubscribed = true;
105105

106106
(async () => {
107-
const companyAttrs = await getCompanyAttributes(
107+
const [companyAttrs, generalAttrs] = await getAttributes(
108108
apiClient,
109109
cancelTokenSource.token
110110
);
@@ -116,15 +116,23 @@ export default function SearchGlobal({ keyword }) {
116116
group: "Company attributes",
117117
active: false,
118118
};
119-
if (companyAttr.name === config.STANDARD_USER_ATTRIBUTES.location) {
120-
filtersWithCompanyAttrs[FILTERS.LOCATIONS].id = companyAttr.id;
121-
}
122119
});
123120

124121
if (isSubscribed) {
125122
searchContext.setFilters(filtersWithCompanyAttrs);
126123
}
127124
}
125+
if (generalAttrs) {
126+
generalAttrs.forEach((generalAttr) => {
127+
if (generalAttr.name === config.STANDARD_USER_ATTRIBUTES.location) {
128+
filtersWithCompanyAttrs[FILTERS.LOCATIONS].id = generalAttr.id;
129+
searchContext.setFilter(
130+
FILTERS.LOCATIONS,
131+
filtersWithCompanyAttrs[FILTERS.LOCATIONS]
132+
);
133+
}
134+
});
135+
}
128136
})();
129137

130138
return () => {

0 commit comments

Comments
 (0)