Skip to content

Commit 5ed94d0

Browse files
committed
Added a public kudos tab.
1 parent 29e3d94 commit 5ed94d0

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

web-ui/src/pages/KudosPage.jsx

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
selectCurrentUser,
1313
selectHasCreateKudosPermission,
1414
} from "../context/selectors";
15-
import { getReceivedKudos, getSentKudos } from "../api/kudos";
15+
import { getReceivedKudos, getSentKudos, getAllKudos } from "../api/kudos";
1616
import { UPDATE_TOAST } from "../context/actions";
1717
import KudosCard from "../components/kudos_card/KudosCard";
1818

@@ -48,6 +48,7 @@ const validTabName = (name) => {
4848
switch (name) {
4949
case "received":
5050
case "sent":
51+
case "public":
5152
break;
5253
default:
5354
name && console.warn(`Invalid tab: ${name}`);
@@ -76,6 +77,8 @@ const KudosPage = () => {
7677
const [receivedKudosLoading, setReceivedKudosLoading] = useState(true);
7778
const [sentKudos, setSentKudos] = useState([]);
7879
const [sentKudosLoading, setSentKudosLoading] = useState(true);
80+
const [publicKudos, setPublicKudos] = useState([]);
81+
const [publicKudosLoading, setPublicKudosLoading] = useState(true);
7982
const [dateRange, setDateRange] = useState(DateRange.THREE_MONTHS);
8083

8184
const isInRange = (requestDate) => {
@@ -119,6 +122,15 @@ const KudosPage = () => {
119122
}
120123
}, [csrf, dispatch, currentUser.id, dateRange]);
121124

125+
const loadPublicKudos = useCallback(async () => {
126+
setPublicKudosLoading(true);
127+
const res = await getAllKudos(csrf);
128+
if (res?.payload?.data && !res.error) {
129+
setPublicKudosLoading(false);
130+
return res.payload.data.filter((k) => isInRange(k.dateCreated));
131+
}
132+
}, [csrf, dispatch, currentUser.id, dateRange]);
133+
122134
const loadAndSetReceivedKudos = () => {
123135
loadReceivedKudos().then((data) => {
124136
if (data) {
@@ -138,10 +150,19 @@ const KudosPage = () => {
138150
});
139151
};
140152

153+
const loadAndSetPublicKudos = () => {
154+
loadPublicKudos().then((data) => {
155+
if (data) {
156+
setPublicKudos(data);
157+
}
158+
});
159+
};
160+
141161
useEffect(() => {
142162
if (csrf && currentUser && currentUser.id) {
143163
loadAndSetReceivedKudos();
144164
loadAndSetSentKudos();
165+
loadAndSetPublicKudos();
145166
}
146167
// eslint-disable-next-line react-hooks/exhaustive-deps
147168
}, [csrf, currentUser, kudosTab, dateRange]);
@@ -202,6 +223,12 @@ const KudosPage = () => {
202223
icon={<UnarchiveIcon />}
203224
iconPosition="start"
204225
/>
226+
<Tab
227+
label="Public"
228+
value="public"
229+
icon={<StarIcon />}
230+
iconPosition="start"
231+
/>
205232
</TabList>
206233
</div>
207234
<TabPanel value="received" style={{ padding: "1rem 0" }}>
@@ -226,7 +253,7 @@ const KudosPage = () => {
226253
) : (
227254
<div className="no-pending-kudos-message">
228255
<Typography variant="body2">
229-
There are currently no pending kudos
256+
There are currently no received kudos
230257
</Typography>
231258
</div>
232259
)}
@@ -251,6 +278,29 @@ const KudosPage = () => {
251278
</div>
252279
)}
253280
</TabPanel>
281+
<TabPanel value="public" style={{ padding: "1rem 0" }}>
282+
{publicKudosLoading ? (
283+
Array.from({ length: 5 }).map((_, index) => (
284+
<SkeletonLoader key={index} type="kudos" />
285+
))
286+
) : publicKudos.length > 0
287+
? (
288+
<div className="received-kudos-list">
289+
{publicKudos.map((k) => (
290+
<KudosCard
291+
key={k.id}
292+
kudos={k}
293+
/>
294+
))}
295+
</div>
296+
) : (
297+
<div className="no-pending-kudos-message">
298+
<Typography variant="body2">
299+
There are currently no public kudos
300+
</Typography>
301+
</div>
302+
)}
303+
</TabPanel>
254304
</TabContext>
255305
</Root>
256306
);

0 commit comments

Comments
 (0)