Skip to content

Commit

Permalink
Merge pull request #525 from EscolaLMS/feature/REK-89
Browse files Browse the repository at this point in the history
Feature/rek 89
  • Loading branch information
victazzz authored Dec 9, 2024
2 parents a2e4245 + ca85b5d commit 88f9fec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/components/Profile/ProfileConsultations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const ProfileConsultations = ({ type }: ProfileConsultationsProps) => {
}, [type, userConsultations.list?.data]);

const refreshConsultation = useCallback(
async (id: number) => {
async (id: number, termId: number) => {
try {
const request = await fetch(
`${API_URL}/api/consultations/me?ids[]=${id}`,
Expand All @@ -59,13 +59,17 @@ const ProfileConsultations = ({ type }: ProfileConsultationsProps) => {
const response = await request.json();

if (response.success && response.data.length > 0) {
const responseIndex = response.data.findIndex(
(consultation: API.AppointmentTerm) =>
consultation?.consultation_term_id === termId
);
setConsultationsData((prev) => {
const index = prev.findIndex(
(consultation) => consultation.id === id
(consultation) => consultation.consultation_term_id === termId
);

if (index !== -1) {
prev[index] = response.data[0];
prev[index] = response.data[responseIndex];
}

return [...prev];
Expand All @@ -81,7 +85,8 @@ const ProfileConsultations = ({ type }: ProfileConsultationsProps) => {
const handleRefreshIfTimePassed = useCallback(() => {
consultationsData.forEach((consultation) => {
if (!consultation.is_started && !consultation.is_ended) {
refreshConsultation(consultation.id);
// @ts-ignore
refreshConsultation(consultation.id, consultation.consultation_term_id);
}
});
}, [consultationsData, refreshConsultation]);
Expand All @@ -95,7 +100,8 @@ const ProfileConsultations = ({ type }: ProfileConsultationsProps) => {
setConsultationsData(filterConstulations);
const interval = setInterval(() => {
handleRefreshIfTimePassed();
}, 5000);
}, 30000);

return () => {
setConsultationsData([]);
clearInterval(interval);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Profile/ProfileTutorConsultations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const ProfileTutorConsultations = ({
setConsultationsData(filterConstulations);
const interval = setInterval(() => {
handleRefreshIfTimePassed();
}, 5000);
}, 30000);
return () => {
setConsultationsData([]);
clearInterval(interval);
Expand Down

0 comments on commit 88f9fec

Please sign in to comment.