Skip to content

Commit c3b3da0

Browse files
committed
We still need to load today's pulse to ensure only a single submission per day, just don't fill in the response data.
1 parent dbcc427 commit c3b3da0

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

web-ui/src/pages/PulsePage.jsx

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { format } from 'date-fns';
33
import React, { useContext, useEffect, useState } from 'react';
44
import { useHistory } from 'react-router-dom';
55
import { Button, Checkbox, Typography } from '@mui/material';
6-
import { initiate } from '../api/generic.js';
6+
import { downloadData, initiate } from '../api/generic.js';
77
import Pulse from '../components/pulse/Pulse.jsx';
88
import { AppContext } from '../context/AppContext';
99
import { selectCsrfToken, selectCurrentUser } from '../context/selectors';
@@ -42,18 +42,44 @@ const PulsePage = () => {
4242
const [year, month, day] = pulse.submissionDate;
4343
setSubmittedToday(
4444
year === now.getFullYear() &&
45-
month === now.getMonth() + 1 &&
46-
day === now.getDate()
45+
month === now.getMonth() + 1 &&
46+
day === now.getDate()
4747
);
48-
49-
setInternalComment(pulse.internalFeelings ?? '');
50-
setExternalComment(pulse.externalFeelings ?? '');
51-
setInternalScore(pulse.internalScore == undefined ?
52-
center : pulse.internalScore - 1);
53-
setExternalScore(pulse.externalScore == undefined ?
54-
center : pulse.externalScore - 1);
5548
}, [pulse]);
5649

50+
const loadTodayPulse = async () => {
51+
if (!csrf || !currentUser?.id) return;
52+
53+
const query = {
54+
dateFrom: today,
55+
dateTo: today,
56+
teamMemberId: currentUser.id
57+
};
58+
59+
const res = await downloadData(pulseURL, csrf, query);
60+
if (res.error) return;
61+
62+
// Sort pulse responses by date, latest to earliest
63+
const pulses = res.payload.data?.sort((a, b) => {
64+
const l = a.submissionDate;
65+
const r = b.submissionDate;
66+
if (r[0] == l[0]) {
67+
if (r[1] == l[1]) {
68+
return r[2] - l[2];
69+
} else {
70+
return r[1] - l[1];
71+
}
72+
} else {
73+
return r[0] - l[0];
74+
}
75+
});
76+
setPulse(pulses.at(0));
77+
};
78+
79+
useEffect(() => {
80+
loadTodayPulse();
81+
}, [csrf, currentUser]);
82+
5783
const submit = async () => {
5884
const myId = currentUser?.id;
5985
const data = {

0 commit comments

Comments
 (0)