Skip to content

Commit

Permalink
Merge branch 'staging' of github.com:UNICEFECAR/USupport-provider-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilen-7DIGIT committed Sep 24, 2024
2 parents d707910 + 2c38e7d commit e8e1333
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 14 deletions.
20 changes: 13 additions & 7 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ logger.setLevel("debug");
import "./App.scss";
import "./HackTimer.js";

const IS_DEV = process.env.NODE_ENV === "development";

// Create a react-query client
const queryClient = new QueryClient({
defaultOptions: {
Expand All @@ -36,13 +38,17 @@ function App() {
});

useEffect(() => {
window.addEventListener("beforeunload", (e) => {
if (!(performance.getEntriesByType("navigation")[0].type === "reload")) {
// If the page is being refreshed, do nothing
e.preventDefault();
userSvc.logout();
}
});
if (!IS_DEV) {
window.addEventListener("beforeunload", (e) => {
if (
!(performance.getEntriesByType("navigation")[0].type === "reload")
) {
// If the page is being refreshed, do nothing
e.preventDefault();
userSvc.logout();
}
});
}
}, []);

const getDefaultTheme = () => {
Expand Down
12 changes: 11 additions & 1 deletion src/backdrops/JoinConsultation/JoinConsultation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { useTranslation } from "react-i18next";
import { toast } from "react-toastify";

import { Backdrop, ButtonSelector } from "@USupport-components-library/src";
import { messageSvc, videoSvc } from "@USupport-components-library/services";
import {
messageSvc,
videoSvc,
providerSvc,
} from "@USupport-components-library/services";

import "./join-consultation.scss";

Expand Down Expand Up @@ -35,10 +39,16 @@ export const JoinConsultation = ({ isOpen, onClose, consultation }) => {
consultation.consultationId
);

const joinConsultationPromise = providerSvc.joinConsultation({
consultationId: consultation.consultationId,
userType: "provider",
});

try {
const result = await Promise.all([
systemMessagePromise,
getConsultationTokenPromise,
joinConsultationPromise,
]);
const token = result[1].data.token;

Expand Down
62 changes: 56 additions & 6 deletions src/backdrops/SelectConsultation/SelectConsultation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
Loading,
} from "@USupport-components-library/src";
import { providerSvc } from "@USupport-components-library/services";
import { getTimestampFromUTC } from "@USupport-components-library/utils";
import {
getTimestampFromUTC,
parseUTCDate,
} from "@USupport-components-library/utils";

import { useGetProviderData } from "#hooks";

Expand Down Expand Up @@ -53,7 +56,35 @@ export const SelectConsultation = ({
getTimestampFromUTC(startDate),
getTimestampFromUTC(currentDay)
);
return data;

const slots = data.map((x) => {
if (x.time) {
return {
time: parseUTCDate(x.time),
organization_id: x.organization_id,
};
}
return x;
});

const organizationSlotTimes = slots.reduce((acc, slot) => {
if (slot.organization_id) {
acc.push(slot.time.getTime());
}
return acc;
}, []);

// Ensure that there is no overlap between organization slots and regular slots
// If there are duplicates, remove the regular slot
if (organizationSlotTimes.length > 0) {
return slots.filter((slot) => {
if (slot.time) return slot;
const slotTime = new Date(slot).getTime();
return !organizationSlotTimes.includes(slotTime);
});
}

return slots;
};
const availableSlotsQuery = useQuery(
["available-slots", startDate, currentDay, providerId],
Expand All @@ -72,16 +103,18 @@ export const SelectConsultation = ({

const renderFreeSlots = () => {
const todaySlots = availableSlots?.filter((slot) => {
const slotDate = new Date(slot).getDate();
const slotDate = new Date(slot.time || slot).getDate();
const currentDayDate = new Date(currentDay).getDate();
return slotDate === currentDayDate;
});
if (!todaySlots || todaySlots?.length === 0)
return <p>{t("no_slots_available")}</p>;
const options = todaySlots?.map(
(slot) => {
const slotLocal = new Date(slot);
const value = new Date(slot).getTime();
const slotLocal = new Date(slot.time || slot);

const value = new Date(slot.time || slot).getTime();

const getDoubleDigitHour = (hour) =>
hour === 24 ? "00" : hour < 10 ? `0${hour}` : hour;

Expand All @@ -108,7 +141,24 @@ export const SelectConsultation = ({
};

const handleSave = () => {
handleBlockSlot(selectedSlot);
const allMatchingSlots = availableSlots.filter((slot) => {
const isTimeMatching = new Date(slot.time).getTime() === selectedSlot;
return isTimeMatching;
});

let slotObject;
if (allMatchingSlots.length >= 1) {
const hasOrganizationSlot = allMatchingSlots.find(
(slot) => !!slot.organization_id
);
if (hasOrganizationSlot) {
slotObject = hasOrganizationSlot;
}
}

const time = slotObject || selectedSlot;

handleBlockSlot(time);
};

return (
Expand Down
1 change: 1 addition & 0 deletions src/blocks/ActivityHistory/ActivityHistory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export const ActivityHistory = ({
renderIn="provider"
onClick={() => handleConsultationClick(consultation)}
couponPrice={consultation.couponPrice}
organizationName={consultation.organizationName}
sponsorImage={consultation.sponsorImage}
t={t}
/>
Expand Down
1 change: 1 addition & 0 deletions src/blocks/Dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const Dashboard = ({ openJoinConsultation, openCancelConsultation }) => {
handleViewProfile={handleViewProfile}
couponPrice={consultation.couponPrice}
sponsorImage={consultation.sponsorImage}
withOrganization={!!consultation.organizationId}
t={t}
/>
</GridItem>
Expand Down
1 change: 1 addition & 0 deletions src/blocks/Scheduler/Scheduler.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ export const Scheduler = ({ openJoinConsultation, openCancelConsultation }) => {
sponsorImage: consultation.sponsor_image,
sponsorName: consultation.sponsor_name,
campaignId: consultation.campaign_id,
organizationId: consultation.organization_id,
};
};

Expand Down
1 change: 1 addition & 0 deletions src/hooks/useGetAllPastConsultations.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function useGetAllPastConsultations() {
campaignId: consultation.campaign_id,
couponPrice: consultation.coupon_price,
sponsorImage: consultation.sponsor_image,
organizationName: consultation.organization_name,
}));
};

Expand Down
1 change: 1 addition & 0 deletions src/hooks/useGetConsultationsForSingleDay.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const useGetConsultationsForSingleDay = (date, enabled = true) => {
couponPrice: consultation.coupon_price,
sponsorImage: consultation.sponsor_image,
sponsorName: consultation.sponsor_name,
organizationId: consultation.organization_id,
}));
};

Expand Down
3 changes: 3 additions & 0 deletions src/pages/Clients/Clients.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { toast } from "react-toastify";
import { useLocation } from "react-router-dom";
import { useQueryClient } from "@tanstack/react-query";

import { InputSearch } from "@USupport-components-library/src";
import { userSvc } from "@USupport-components-library/services";
Expand All @@ -25,6 +26,7 @@ import "./clients.scss";
* @returns {JSX.Element}
*/
export const Clients = () => {
const queryClient = useQueryClient();
const { width } = useWindowDimensions();
const { t } = useTranslation("clients-page");
const providerId = userSvc.getUserID();
Expand Down Expand Up @@ -83,6 +85,7 @@ export const Clients = () => {
const closeCancelConsultation = () => setIsCancelConsultationOpen(false);

const onSuggestConsultationSuccess = () => {
queryClient.invalidateQueries({ queryKey: ["all-clients"] });
toast(t("consultation_suggest_success"));
setIsBlockSlotSubmitting(false);
window.dispatchEvent(new Event("new-notification"));
Expand Down

0 comments on commit e8e1333

Please sign in to comment.