Skip to content

Commit

Permalink
ran prettier on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
teetangh committed Dec 12, 2024
1 parent acaa3e4 commit 0df98a5
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 177 deletions.
2 changes: 1 addition & 1 deletion app/api/slots/availability/[consultantId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ function mapCustomSlotToTiming(
): TSlotTiming {
const slotStart = toZonedTime(slot.slotStartTimeInUTC, userTimeZone);
const slotEnd = toZonedTime(slot.slotEndTimeInUTC, userTimeZone);

// Get the day of week for the slot's start time
const dayOfWeek = getDayOfWeek(slotStart);

Expand Down
18 changes: 12 additions & 6 deletions app/explore/experts/[consultantId]/components/AboutSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@ interface AboutSectionProps {
consultantDetails: TConsultantProfile;
}

export function AboutSection({ userDetails, consultantDetails }: AboutSectionProps) {
export function AboutSection({
userDetails,
consultantDetails,
}: AboutSectionProps) {
return (
<div className="space-y-6">
<div>
<h3 className="text-xl font-semibold mb-2">About</h3>
<p className="text-gray-600">
{userDetails.name} is a seasoned {consultantDetails.specialization} with{" "}
{consultantDetails.experience} of experience in the{" "}
{userDetails.name} is a seasoned {consultantDetails.specialization}{" "}
with {consultantDetails.experience} of experience in the{" "}
{consultantDetails.domain.name} sector.
</p>
</div>

<div>
<h3 className="text-xl font-semibold mb-2">Education & Background</h3>
<p className="text-gray-600">
{userDetails.name} has experience across multiple industries,
with a particular focus on{" "}
{userDetails.name} has experience across multiple industries, with a
particular focus on{" "}
{consultantDetails?.subDomains
?.map((domain: { name: string }) => domain.name)
.join(", ")}
Expand All @@ -34,7 +37,10 @@ export function AboutSection({ userDetails, consultantDetails }: AboutSectionPro
<h3 className="text-xl font-semibold mb-2">Skills & Specialties</h3>
<p className="text-gray-600">
{userDetails.name} focuses on{" "}
{consultantDetails.tags?.map((tag: { name: string }) => tag.name).join(", ")}.
{consultantDetails.tags
?.map((tag: { name: string }) => tag.name)
.join(", ")}
.
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { TConsultantProfile } from "@/types/consultant";
import { TSlotTiming } from "@/types/slots";
import { WeeklyAvailability } from "./WeeklyAvailability";
import { CustomAvailability } from "./CustomAvailability";
import {
normalizeWeeklySlot,
normalizeCustomSlot,
import {
normalizeWeeklySlot,
normalizeCustomSlot,
formatTime,
dayMap
dayMap,
} from "../utils";

interface ConsultantAvailabilityProps {
Expand All @@ -20,7 +20,7 @@ export function ConsultantAvailability({
consultantDetails,
selectedSlot,
setSelectedSlot,
timezone
timezone,
}: ConsultantAvailabilityProps) {
return (
<div>
Expand All @@ -30,11 +30,13 @@ export function ConsultantAvailability({
? "Weekly schedule. Select a time slot to schedule a meeting."
: "Custom schedule for the next 7 days. Select a time slot to schedule a meeting."}
</p>

{consultantDetails.scheduleType === "WEEKLY" ? (
<WeeklyAvailability
slots={consultantDetails.slotsOfAvailabilityWeekly.map(normalizeWeeklySlot)}
onSlotSelect={slot => {
slots={consultantDetails.slotsOfAvailabilityWeekly.map(
normalizeWeeklySlot,
)}
onSlotSelect={(slot) => {
const normalizedSlot = normalizeWeeklySlot(slot);
setSelectedSlot({
slotId: normalizedSlot.id,
Expand All @@ -44,27 +46,44 @@ export function ConsultantAvailability({
slotEndTimeInUTC: normalizedSlot.slotEndTimeInUTC,
slotOfAvailabilityId: normalizedSlot.id,
slotOfAppointmentId: "",
localStartTime: formatTime(normalizedSlot.slotStartTimeInUTC, timezone),
localEndTime: formatTime(normalizedSlot.slotEndTimeInUTC, timezone),
localStartTime: formatTime(
normalizedSlot.slotStartTimeInUTC,
timezone,
),
localEndTime: formatTime(
normalizedSlot.slotEndTimeInUTC,
timezone,
),
});
}}
selectedSlotId={selectedSlot?.slotId}
/>
) : (
<CustomAvailability
slots={consultantDetails.slotsOfAvailabilityCustom.map(normalizeCustomSlot)}
onSlotSelect={slot => {
slots={consultantDetails.slotsOfAvailabilityCustom.map(
normalizeCustomSlot,
)}
onSlotSelect={(slot) => {
const normalizedSlot = normalizeCustomSlot(slot);
setSelectedSlot({
slotId: normalizedSlot.id,
dateInISO: new Date(normalizedSlot.slotStartTimeInUTC).toISOString(),
dayOfWeek: dayMap[new Date(normalizedSlot.slotStartTimeInUTC).getDay()],
dateInISO: new Date(
normalizedSlot.slotStartTimeInUTC,
).toISOString(),
dayOfWeek:
dayMap[new Date(normalizedSlot.slotStartTimeInUTC).getDay()],
slotStartTimeInUTC: normalizedSlot.slotStartTimeInUTC,
slotEndTimeInUTC: normalizedSlot.slotEndTimeInUTC,
slotOfAvailabilityId: normalizedSlot.id,
slotOfAppointmentId: "",
localStartTime: formatTime(normalizedSlot.slotStartTimeInUTC, timezone),
localEndTime: formatTime(normalizedSlot.slotEndTimeInUTC, timezone),
localStartTime: formatTime(
normalizedSlot.slotStartTimeInUTC,
timezone,
),
localEndTime: formatTime(
normalizedSlot.slotEndTimeInUTC,
timezone,
),
});
}}
selectedSlotId={selectedSlot?.slotId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ export function ConsultationPricing({
renderCalendar,
slotTimings,
selectedSlot,
setSelectedSlot
setSelectedSlot,
}: ConsultationPricingProps) {
const formatPricingOptions = (
plans: (ConsultationPlan | SubscriptionPlan)[],
type: "consultation" | "subscription"
type: "consultation" | "subscription",
): PricingOption[] => {
return plans.map((plan) => {
if (type === "consultation" && "durationInHours" in plan) {
Expand Down Expand Up @@ -75,11 +75,11 @@ export function ConsultationPricing({

const consultationOptions = formatPricingOptions(
consultantDetails.consultationPlans,
"consultation"
"consultation",
);
const subscriptionOptions = formatPricingOptions(
consultantDetails.subscriptionPlans,
"subscription"
"subscription",
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ interface ProfileHeaderProps {
consultantDetails: TConsultantProfile;
}

export function ProfileHeader({ userDetails, consultantDetails }: ProfileHeaderProps) {
export function ProfileHeader({
userDetails,
consultantDetails,
}: ProfileHeaderProps) {
return (
<div className="space-y-8">
<div className="flex items-center space-x-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DayOfWeek } from "@prisma/client";
import {
convertUTCToLocalDate,
formatTime as formatTimeUtil,
isSlotRelevantForDay
isSlotRelevantForDay,
} from "../utils";

interface WeeklySlot {
Expand Down Expand Up @@ -38,36 +38,47 @@ export const WeeklyAvailability: React.FC<WeeklyAvailabilityProps> = ({

// Get browser's timezone
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
console.log('Using timezone:', timezone);
console.log("Using timezone:", timezone);

// Group slots by day and sort by time
const slotsByDay = daysOfWeek.map((day) => {
// Get slots that are relevant for this day
const daySlots = slots.filter(slot => isSlotRelevantForDay(slot, day, timezone));
const daySlots = slots.filter((slot) =>
isSlotRelevantForDay(slot, day, timezone),
);

// Process each slot to handle timezone and overnight slots
const processedSlots = daySlots.map(slot => {
const processedSlots = daySlots.map((slot) => {
// Use a reference date for consistent conversion
const referenceDate = new Date();
referenceDate.setHours(0, 0, 0, 0);

// Convert UTC times to local
const startDateTime = convertUTCToLocalDate(slot.slotStartTimeInUTC, referenceDate, timezone);
let endDateTime = convertUTCToLocalDate(slot.slotEndTimeInUTC, referenceDate, timezone);
const startDateTime = convertUTCToLocalDate(
slot.slotStartTimeInUTC,
referenceDate,
timezone,
);
let endDateTime = convertUTCToLocalDate(
slot.slotEndTimeInUTC,
referenceDate,
timezone,
);

// If this slot crosses midnight
if (slot.dayOfWeekforStartTimeInUTC !== slot.dayOfWeekforEndTimeInUTC ||
endDateTime <= startDateTime ||
(endDateTime.getHours() === 0 && endDateTime.getMinutes() === 0)) {

if (
slot.dayOfWeekforStartTimeInUTC !== slot.dayOfWeekforEndTimeInUTC ||
endDateTime <= startDateTime ||
(endDateTime.getHours() === 0 && endDateTime.getMinutes() === 0)
) {
endDateTime = new Date(endDateTime);
endDateTime.setDate(endDateTime.getDate() + 1);
}

return {
...slot,
localStartTime: formatTimeUtil(startDateTime, timezone),
localEndTime: formatTimeUtil(endDateTime, timezone)
localEndTime: formatTimeUtil(endDateTime, timezone),
};
});

Expand Down
6 changes: 3 additions & 3 deletions app/explore/experts/[consultantId]/hooks/useTimezone.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from 'react';
import { useState, useEffect } from "react";

export function useTimezone() {
const [timezone, setTimezone] = useState<string | null>(null);
Expand All @@ -8,10 +8,10 @@ export function useTimezone() {
try {
// Get timezone on client side
const browserTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
console.log('Browser timezone detected:', browserTimezone);
console.log("Browser timezone detected:", browserTimezone);
setTimezone(browserTimezone);
} catch (error) {
console.error('Error detecting timezone:', error);
console.error("Error detecting timezone:", error);
} finally {
setIsLoading(false);
}
Expand Down
Loading

0 comments on commit 0df98a5

Please sign in to comment.