Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

1.2 KB
Raw Blame
import "server-only";

import { cache } from "react";
import { loadUser } from "@/features/user/loaders";
import { getAvailableConferencingProviders } from "./constants";
import {
  getConferencingConnections,
  getConnectedConferencingProviders,
} from "./data";

export const loadAvailableConferencingProviders = cache(async () => {
  await loadUser();
  return getAvailableConferencingProviders();
});

export const loadConferencingConnections = cache(async () => {
  const user = await loadUser();
  return getConferencingConnections(user.id);
});

// What the poll form needs: the providers this instance offers and the ones
// the organizer has already linked. Guests have nothing to link; a pasted
// link needs no provider, so the options always exist.
export const loadConferencingOptions = cache(
  async ({ userId }: { userId: string | null }) => {
    const available = getAvailableConferencingProviders();
    // A provider the user linked before the instance stopped offering it is
    // not offered either.
    const connected = userId
      ? (await getConnectedConferencingProviders(userId)).filter((provider) =>
          available.includes(provider),
        )
      : [];
    return { available, connected };
  },
);