2023-03-07 22:37:56 +00:00
|
|
|
import { z } from "zod";
|
|
|
|
|
2022-08-26 00:48:50 +00:00
|
|
|
import { getEventLocationType, locationKeyToString } from "@calcom/app-store/locations";
|
2022-08-29 16:01:45 +00:00
|
|
|
import { classNames } from "@calcom/lib";
|
2023-01-04 15:31:50 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-01-23 23:08:01 +00:00
|
|
|
import { Tooltip } from "@calcom/ui";
|
2023-04-12 15:26:31 +00:00
|
|
|
import { Link } from "@calcom/ui/components/icon";
|
2022-08-26 00:48:50 +00:00
|
|
|
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { Props } from "./pages/AvailabilityPage";
|
2022-08-26 00:48:50 +00:00
|
|
|
|
2023-03-28 20:03:54 +00:00
|
|
|
const excludeNullValues = (value: unknown) => !!value;
|
|
|
|
|
2022-08-26 00:48:50 +00:00
|
|
|
export function AvailableEventLocations({ locations }: { locations: Props["eventType"]["locations"] }) {
|
2023-01-04 15:31:50 +00:00
|
|
|
const { t } = useLocale();
|
|
|
|
|
2023-03-28 20:03:54 +00:00
|
|
|
const renderLocations = locations.map((location, index) => {
|
|
|
|
const eventLocationType = getEventLocationType(location.type);
|
|
|
|
if (!eventLocationType) {
|
|
|
|
// It's possible that the location app got uninstalled
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (eventLocationType.variable === "hostDefault") {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const translateAbleKeys = [
|
|
|
|
"attendee_in_person",
|
|
|
|
"in_person",
|
|
|
|
"attendee_phone_number",
|
|
|
|
"link_meeting",
|
|
|
|
"organizer_phone_number",
|
|
|
|
];
|
|
|
|
|
|
|
|
const locationKey = z.string().default("").parse(locationKeyToString(location));
|
|
|
|
const translatedLocation = location.type.startsWith("integrations:")
|
|
|
|
? eventLocationType.label
|
|
|
|
: translateAbleKeys.includes(locationKey)
|
|
|
|
? t(locationKey)
|
|
|
|
: locationKey;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div key={`${location.type}-${index}`} className="flex flex-row items-center text-sm font-medium">
|
|
|
|
{eventLocationType.iconUrl === "/link.svg" ? (
|
2023-04-19 10:14:59 +00:00
|
|
|
<Link className="text-default ml-[2px] h-4 w-4 ltr:mr-[10px] rtl:ml-[10px] " />
|
2023-03-28 20:03:54 +00:00
|
|
|
) : (
|
|
|
|
<img
|
|
|
|
src={eventLocationType.iconUrl}
|
|
|
|
className={classNames(
|
|
|
|
"ml-[2px] h-4 w-4 opacity-70 ltr:mr-[10px] rtl:ml-[10px] dark:opacity-100 ",
|
2023-05-09 15:27:09 +00:00
|
|
|
!eventLocationType.iconUrl?.startsWith("/app-store") ? "dark:invert-[.65]" : ""
|
2022-11-22 12:04:06 +00:00
|
|
|
)}
|
2023-03-28 20:03:54 +00:00
|
|
|
alt={`${eventLocationType.label} icon`}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<Tooltip content={translatedLocation}>
|
|
|
|
<p className="line-clamp-1">{translatedLocation}</p>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
const filteredLocations = renderLocations.filter(excludeNullValues) as JSX.Element[];
|
|
|
|
return filteredLocations.length ? (
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="text-default mr-6 flex w-full flex-col space-y-4 break-words text-sm">
|
2023-03-28 20:03:54 +00:00
|
|
|
{filteredLocations}
|
2022-08-26 00:48:50 +00:00
|
|
|
</div>
|
2023-03-07 22:37:56 +00:00
|
|
|
) : null;
|
2022-08-26 00:48:50 +00:00
|
|
|
}
|